-
Notifications
You must be signed in to change notification settings - Fork 1
/
local-setup.sh
executable file
·243 lines (212 loc) · 5.91 KB
/
local-setup.sh
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/sh
set -eu
set -eu
stderr() {
echo >&2 "$@"
}
TILDE="$HOME"/r/github.com/cceckman/Tilde
ssh_config() {
sudo apt-get install -y ykcs11
mkdir -p ~/.ssh
chmod 0700 ~/.ssh
# Set up enrollment key:
cat <<EOF >$HOME/.ssh/id_enrollment.pub
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBEWOv6ObxM/LQTQXMJYKDrk/yzpog0CvhXWCCFu/3SddnYujiLDTDvPKM+7LmPRWTvaWDvWyaG1mvIL17aBlO8=
EOF
# And a new per-device key for Github, if needed:
if ! test -f $HOME/.ssh/id_github.pub
then
stderr "Generating an SSH keypair for github.com"
ssh-keygen -t ed25519 -C cceckman@"$(hostname)" -f $HOME/.ssh/id_github
fi
# Seed SSH config:
if ! test -f $HOME/.ssh/config
then
cat <<EOF >$HOME/.ssh/config
Host *
PasswordAuthentication no
# Only use identity files, not any identity loaded in ssh-agent
IdentitiesOnly yes
ControlPath ~/.ssh/control-%h-%p-%r
ControlMaster=auto
ControlPersist=10
EOF
fi
if ! grep "^Host github.com" $HOME/.ssh/config
then
TEMP="$(mktemp -p ~/.ssh)"
cat - $HOME/.ssh/config <<EOF >$TEMP
Host github.com
User cceckman
PasswordAuthentication no
PKCS11Provider /usr/lib/$(uname -m)-linux-gnu/libykcs11.so
IdentitiesOnly yes
IdentityFile ~/.ssh/id_github
IdentityFile ~/.ssh/id_enrollment.pub
EOF
mv "$TEMP" $HOME/.ssh/config
fi
}
upgrade_tilde() {
(
set +x
cd "$TILDE"
# Promote to SSH, then unshallow;
# SSH has better performance than HTTP, if I understand correctly.
if git remote get-url origin | grep -q 'http'
then
stderr "Upgrading Tilde to SSH"
git remote set-url origin [email protected]:cceckman/Tilde.git
fi
if test "$(git rev-parse --is-shallow-repository)" = true
then
stderr "Unshallowing Tilde"
git fetch --unshallow
fi
git submodule update --init --recursive
git remote prune origin
)
}
upgrade_links() {
(
stderr "Updating homedir links"
mkdir -p "$HOME/.config"
for dir in $(ls "$TILDE"/config)
do
ln -sf "$TILDE"/config/"$dir" "$HOME"/.config
done
ln -sf "$TILDE"/.gitignore_global "$HOME"
ln -sf "$TILDE"/.gitconfig "$HOME"
ln -sf "$TILDE"/.vim "$HOME"
ln -sf "$TILDE"/.vimrc "$HOME"
ln -sf "$TILDE"/.zsh "$HOME"
ln -sf "$TILDE"/scripts "$HOME"
ln -sf "$TILDE"/themes "$HOME"
mkdir -p "$HOME"/.vscode/extensions/
ln -sf \
"$TILDE"/.vscode/extensions/selenized \
"$HOME"/.vscode/extensions/selenized
)
}
install_go() {
VERSION="go1.22.5"
if type go 2>&1 >/dev/null
then
stderr "Found Go:"
type go
if test "$(go version | cut -d' ' -f3)" = "$VERSION"
then
stderr "$VERSION installed"
return 0
fi
fi
stderr "Installing Go $VERSION"
GOFILE="$(mktemp -d)/go.tar.gz"
curl --fail -Lo "$GOFILE" \
https://go.dev/dl/"$VERSION".linux-amd64.tar.gz
sudo rm -rf /usr/local/go && \
sudo tar -C /usr/local -xzf "$GOFILE"
}
install_toolchains() {
stderr "Installing toolchains"
(
if type cargo 2>&1 >/dev/null
then
stderr "Found Cargo:"
type cargo
else
stderr "Installing Rust via Rustup"
curl https://sh.rustup.rs -sSf | sh -s -- \
--no-modify-path \
-y \
--component rust-analyzer \
--target aarch64-unknown-linux-gnu \
--target x86_64-unknown-linux-gnu
fi
)
( install_go )
(
if type bazel 2>&1 >/dev/null
then
stderr "Found bazel:"
type bazel
else
stderr "Installing bazelisk (as bazel)"
mkdir -p ~/.local/bin
curl --fail -Lo ~/.local/bin/bazel \
https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/bazelisk-linux-amd64
chmod +x ~/.local/bin/bazel
fi
)
sudo apt-get -y install clang llvm python3 lldb
# TODO: sccache?
# https://github.com/mozilla/sccache/blob/main/docs/DistributedQuickstart.md
. "$HOME"/rcfiles/path.sh
}
install_gcloud() {
sudo apt-get -y install gpg
# gcloud stanza: https://cloud.google.com/sdk/docs/install#deb
if ! test -f /usr/share/keyrings/cloud.google.gpg
then
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \
| sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
fi
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" \
| sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list
# We have to --no-install-recommends because it wants to install
# app-engine-python, which still requires python2.7 apparently? Wild.
sudo apt-get update && sudo apt-get install -y google-cloud-cli
# This doesn't work - requires python2.7 (!!)
# Filed b/312491174 for this.
# sudo apt-get install google-cloud-cli-app-engine-go
}
install_tools() {
# Various tools I like...
cargo install git-branchless
sudo apt-get -y install \
gh file htop inotify-tools pv \
strace linux-perf htop
# install_gcloud
}
install_theme() {
# Prerequisite for retheme script
sudo apt-get -y install jq
"$HOME"/scripts/retheme selenized dark
}
install_gui() {
sudo apt-get install -y \
sway swayidle swaylock xdg-desktop-portal-wlr waybar \
foot alacritty mako-notifier bemenu \
brightnessctl ddcutil gammastep \
fonts-font-awesome \
xwayland wl-clipboard
sudo apt-get install -y \
blueman libspa-0.2-bluetooth
mkdir -p ~/.local/share/fonts/
if ! find ~/.local/share/fonts -name 'Font Awesome*' >/dev/null
then
FONTDIR="$(mktemp -d)"
(
cd $FONTDIR ; echo >&2 $FONTDIR
curl -Lo fontawesome.zip https://use.fontawesome.com/releases/v5.15.4/fontawesome-free-5.15.4-desktop.zip
unzip fontawesome.zip
cp */otfs/*.otf ~/.local/share/fonts
)
rm -rf "$FONTDIR"
fi
fc-cache
}
# TODO: Install GUI environment
main() {
ssh_config
upgrade_tilde
upgrade_links
install_toolchains
install_tools
install_theme
if ( test -d /usr/share/wayland-sessions || test -d /usr/share/xsessions )
then
install_gui
fi
}
main