Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·200 lines (174 loc) · 7.96 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·200 lines (174 loc) · 7.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
set -eo pipefail
# ==========================================================
# My setup code for a new machine (MacOS)
#
# Required steps:
# - Ensure that SSH keys are downloaded into local machine,
# and added to ssh agent.
# ===========================================================
# -- Install the Xcode Command Line Tools --
if ! xcode-select -p >/dev/null 2>&1; then
xcode-select --install
printf 'Finish the installation in the macOS dialog. Setup will continue automatically (Ctrl-C to stop).\n'
until xcode-select -p >/dev/null 2>&1 && xcrun --find clang >/dev/null 2>&1; do
sleep 5
done
fi
# -- Authenticate once --
sudo -v
# -- Setup colors --
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No color
# -- Init variables --
XDG_CONFIG_HOME="$HOME/.config"
# -- Install Homebrew --
printf "%s%b%-8s%b%s %s\n" "[ " "${BLUE}" "WORKING" "${NC}" " ]" "Installing Homebrew"
if ! command -v brew &> /dev/null; then
brew_installer=$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
/bin/bash -c "$brew_installer"
brew_shellenv=$(/opt/homebrew/bin/brew shellenv)
eval "$brew_shellenv"
fi
printf "%s%b%-8s%b%s %s\n" "[ " "${GREEN}" " DONE" "${NC}" " ]" "Installing Homebrew"
# -- Install Git --
printf "%s%b%-8s%b%s %s\n" "[ " "${BLUE}" "WORKING" "${NC}" " ]" "Installing Git"
if ! command -v git &> /dev/null; then
brew install git
fi
printf "%s%b%-8s%b%s %s\n" "[ " "${GREEN}" " DONE" "${NC}" " ]" "Installing Git"
# -- Git clone dotfiles --
printf "%s%b%-8s%b%s %s\n" "[ " "${BLUE}" "WORKING" "${NC}" " ]" "Git Clone dotfiles"
dotfiles_repo="xavierchen0/dotfiles"
if checkout_root=$(git -C "$XDG_CONFIG_HOME" rev-parse --show-toplevel 2>/dev/null) &&
[[ "$checkout_root" -ef "$XDG_CONFIG_HOME" ]]; then
origin=$(git -C "$XDG_CONFIG_HOME" config --local --get remote.origin.url) || origin=""
origin=${origin%/}
case "${origin%.git}" in
"git@github.com:$dotfiles_repo"|"ssh://git@github.com/$dotfiles_repo"|"https://github.com/$dotfiles_repo")
printf 'Reusing dotfiles checkout at %s\n' "$XDG_CONFIG_HOME" ;;
*)
printf 'Cannot use %s: expected a checkout of github.com/%s.\n' "$XDG_CONFIG_HOME" "$dotfiles_repo" >&2
exit 1 ;;
esac
else
# Git accepts a missing or empty destination and refuses to overwrite existing files.
git clone "git@github.com:${dotfiles_repo}.git" "$XDG_CONFIG_HOME"
fi
if [[ ! -f "$XDG_CONFIG_HOME/Brewfile" ]]; then
printf 'Missing Brewfile in %s. Check the dotfiles checkout before running setup.\n' "$XDG_CONFIG_HOME" >&2
exit 1
fi
printf "%s%b%-8s%b%s %s\n" "[ " "${GREEN}" " DONE" "${NC}" " ]" "Git Clone dotfiles"
# -- Install software and packages via Brew bundle --
printf "%s%b%-8s%b%s %s\n" "[ " "${BLUE}" "WORKING" "${NC}" " ]" "Installing via Brewfile"
export XDG_CONFIG_HOME
brew bundle install --file="${XDG_CONFIG_HOME}/Brewfile" --verbose --no-upgrade
brew bundle cleanup --file="${XDG_CONFIG_HOME}/Brewfile"
printf "%s%b%-8s%b%s %s\n" "[ " "${GREEN}" " DONE" "${NC}" " ]" "Installing via Brewfile"
# -- Build Sioyek from https://github.com/ahrm/sioyek/discussions/1602 --
install_sioyek() (
apps_dir="$1"
app="$apps_dir/sioyek.app"
check_existing_app() {
if [[ -L "$app" || ! -x "$app/Contents/MacOS/sioyek" ||
"$(plutil -extract CFBundleIdentifier raw "$app/Contents/Info.plist" 2>/dev/null)" != info.sioyek.sioyek ]]; then
printf 'Cannot install Sioyek. Check the existing bundle at %s.\n' "$app" >&2
return 1
fi
}
if [[ -e "$app" || -L "$app" ]]; then
check_existing_app || return 1
fi
build_dir=$(mktemp -d "${TMPDIR:-/tmp}/sioyek.XXXXXXXX")
trap 'rm -rf "$build_dir"' EXIT
git clone --branch development --depth 1 https://github.com/ahrm/sioyek "$build_dir"
cd "$build_dir"
mupdf_commit=$(git rev-parse HEAD:mupdf)
if [[ "$(plutil -extract SioyekMuPDFCommit raw "$app/Contents/Info.plist" 2>/dev/null)" == "$mupdf_commit" ]] &&
codesign --verify --deep --strict "$app"; then
printf 'Reusing %s\n' "$app"
return 0
fi
git submodule update --init --recursive --depth 1
qt_bin="$(brew --prefix qt)/bin"
qt_version=$("$qt_bin/qmake" -query QT_VERSION)
printf 'Building Sioyek with MuPDF commit %s and Qt %s.\n' "$mupdf_commit" "$qt_version"
jobs=$(getconf _NPROCESSORS_ONLN)
macos_version=$(sw_vers -productVersion)
export MACOSX_DEPLOYMENT_TARGET="${macos_version%%.*}"
make -C mupdf -j"$jobs" HAVE_GLUT=no
"$qt_bin/qmake" pdf_viewer_build_config.pro 'CONFIG+=non_portable' \
'QMAKE_CXXFLAGS+=-Wno-implicit-function-declaration' \
-after "QMAKE_MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET" "QMAKE_APPLE_DEVICE_ARCHS=$(uname -m)"
make -j"$jobs"
resources=sioyek.app/Contents/Resources
cp -R pdf_viewer/shaders "$resources/"
cp pdf_viewer/{prefs,prefs_user,keys,keys_user}.config tutorial.pdf "$resources/"
/usr/libexec/PlistBuddy -c "Add :LSEnvironment:PATH string $PATH" sioyek.app/Contents/Info.plist
plutil -insert SioyekMuPDFCommit -string "$mupdf_commit" sioyek.app/Contents/Info.plist
"$qt_bin/macdeployqt" sioyek.app -qmldir=pdf_viewer/touchui
codesign --force --deep --sign - sioyek.app
# Stage on the destination volume so macOS can replace the entire signed bundle safely.
stage_dir=$(mktemp -d "$apps_dir/.sioyek-install.XXXXXXXX")
trap 'rm -rf "$stage_dir" "$build_dir"' EXIT
mv sioyek.app "$stage_dir/"
codesign --verify --deep --strict "$stage_dir/sioyek.app"
if [[ -e "$app" || -L "$app" ]]; then
check_existing_app || return 1
/usr/bin/swift - "$app" "$stage_dir/sioyek.app" <<'SWIFT'
import Foundation
let installed = URL(fileURLWithPath: CommandLine.arguments[1])
let replacement = URL(fileURLWithPath: CommandLine.arguments[2])
_ = try FileManager.default.replaceItemAt(installed, withItemAt: replacement, options: .usingNewMetadataOnly)
SWIFT
else
mv -n "$stage_dir/sioyek.app" "$apps_dir/"
if [[ -e "$stage_dir/sioyek.app" ]]; then
printf 'Another install created %s. Rerun setup to check it.\n' "$app" >&2
return 1
fi
fi
)
printf "%s%b%-8s%b%s %s\n" "[ " "${BLUE}" "WORKING" "${NC}" " ]" "Installing Sioyek"
install_sioyek /Applications
printf "%s%b%-8s%b%s %s\n" "[ " "${GREEN}" " DONE" "${NC}" " ]" "Installing Sioyek"
# -- helper function to verify correctness of symlink --
# -- if destination missing, create the link
# -- if already links to the intended file or directory, skip
# -- if something else occupies the destination, print the conflict and stop
ensure_symlink() {
local source="$1" destination="$2"
if [[ -L "$destination" ]]; then
if [[ "$destination" -ef "$source" || "$(readlink "$destination")" == "$source" ]]; then
return 0
fi
fi
if [[ -e "$destination" || -L "$destination" ]]; then
printf 'Cannot create link at %s: destination already exists.\n' "$destination" >&2
return 1
fi
ln -sh "$source" "$destination"
}
printf "%s%b%-8s%b%s %s\n" "[ " "${BLUE}" "WORKING" "${NC}" " ]" "Creating symlinks"
ensure_symlink "${XDG_CONFIG_HOME}/zsh/.zshrc" "${HOME}/.zshrc" || exit 1
ensure_symlink "${XDG_CONFIG_HOME}/git/.gitconfig" "${HOME}/.gitconfig" || exit 1
ensure_symlink "${HOME}/Library/Mobile Documents/com~apple~CloudDocs" "${HOME}/iCloud" || exit 1
printf "%s%b%-8s%b%s %s\n" "[ " "${GREEN}" " DONE" "${NC}" " ]" "Creating symlinks"
# -- Set up QMK and link the Lily58 keymap --
printf "%s%b%-8s%b%s %s\n" "[ " "${BLUE}" "WORKING" "${NC}" " ]" "Setting up Lily58 keymap"
keymap_dir="$XDG_CONFIG_HOME/qmk/keymaps/my_lily58"
if [[ ! -f "$keymap_dir/keymap.c" ]]; then
printf 'Missing Lily58 keymap at %s/keymap.c\n' "$keymap_dir" >&2
exit 1
fi
# Follow the macOS instructions at https://docs.qmk.fm/newbs_getting_started
export PATH="${UV_TOOL_BIN_DIR:-$HOME/.local/bin}:$PATH"
if ! command -v qmk >/dev/null; then
curl -fsSL https://install.qmk.fm | sh
fi
qmk setup
qmk_home=$(qmk env QMK_HOME)
ensure_symlink "$keymap_dir" "$qmk_home/keyboards/lily58/keymaps/my_lily58"
printf "%s%b%-8s%b%s %s\n" "[ " "${GREEN}" " DONE" "${NC}" " ]" "Setting up Lily58 keymap"