-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·307 lines (268 loc) · 8.41 KB
/
setup
File metadata and controls
executable file
·307 lines (268 loc) · 8.41 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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/usr/bin/env bash
#
# Copyright © 2023 Aspen James <hello@aspenjames.dev>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the “Software”), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Customize behavior with environment variables:
# Variable Default Description
# ======== ======= ===========
# ASSUME_YES false Assume YES to y/n prompts
# GO_VERSION 1.22.5 Go version to install
# NODE_VERSION v20.15.1 Node version to install
# OS_CODENAME (detected) Operating system codename
#
# Disable SC2016 (info): Expressions don't expand in single quotes, use double
# quotes for that. https://www.shellcheck.net/wiki/SC2016
# shellcheck disable=SC2016
# ARCH
######
case "$(arch)" in
aarch64)
ARCH=arm64
NODE_ARCH=arm64
;;
x86_64)
ARCH=amd64
NODE_ARCH=x64
;;
esac
# HELPERS
#########
function _confirm() {
[[ -n "$ASSUME_YES" ]] && return 0
read -p "$1" -n 1 -r reply
echo
case "$reply" in
y|Y ) return 0 ;;
* ) return 1 ;;
esac
}
# _copyFile source destination [sudo]
# Copies source file to destination, offering to backup if contents differ.
function _copyFile() {
local src="$1"
local dest="$2"
local sudo="$3"
if [ -f "$dest" ]; then
if ! cmp -s "$src" "$dest"; then
if _confirm "Would you like to backup $dest before updating?"; then
if [[ "$sudo" ]]; then
_sudo mv "$dest" "${dest}.bak"
else
mv "$dest" "${dest}.bak"
fi
fi
else
return 0
fi
fi
if [[ "$sudo" ]]; then
_sudo cp "$src" "$dest"
else
cp "$src" "$dest"
fi
}
function _sudo() {
echo "Executing '$*' as sudo"
sudo "$@"
}
# Package Manager
#################
function _updatePkgRepos() {
_sudo apt update
}
function _install() {
OLDIFS="$IFS"
IFS=":" read -r -a progs <<< "$1"
local prog=${progs[0]}
local exe=${progs[1]:-$prog}
if [ ! -x "$(command -v "$exe")" ]; then
echo "Installing $prog..."
_sudo apt install -y "$prog"
fi
IFS="$OLDIFS"
}
# INSTALL
#########
_updatePkgRepos
for prog in \
bat:batcat \
build-essential:NULL \
curl \
exa \
git \
python3 \
python3-distutils:NULL \
python3-setuptools:NULL \
qemu-system:qemu-system-x86_64 \
ripgrep:rg \
shellcheck \
vim \
; do
_install "$prog"
done
# apt-vim
#########
# apt-vim dep: python
if [ ! -x "$(command -v python)" ]; then
# Symlink python to python3
_sudo update-alternatives --install /usr/bin/python python "$(which python3)" 100
fi
# apt-vim install
if [ ! -x "$(command -v apt-vim)" ]; then
echo "Installing apt-vim..."
# Clone repo
mkdir -p "$HOME/src/egalpin"
git clone "https://github.com/egalpin/apt-vim.git" "$HOME/src/egalpin/apt-vim"
# Run init script
"$HOME/src/egalpin/apt-vim/apt-vim" init
# Add vimpkg bin directory to ~/.bashrc
sed -i '/\.vimpkg\/bin/d' "$HOME/.bashrc"
PATH="$PATH:$HOME/.vimpkg/bin"
echo 'PATH="$PATH:$HOME/.vimpkg/bin"' >> "$HOME/.bashrc"
fi
# apt-vim InstantMarkdown dep: node
NODE_VERSION="${NODE_VERSION:-v20.15.1}"
if [[ ! "$(node --version)" == *"$NODE_VERSION"* ]]; then
echo "Installing node version $NODE_VERSION"
_sudo rm -rf /usr/local/lib/node*
curl -sL "https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz" \
| _sudo tar -C /usr/local/lib -xJf -
_sudo mv /usr/local/lib/node-* /usr/local/lib/nodejs
_sudo chown -R "$USER:$USER" /usr/local/lib/nodejs
sed -i '/\nodejs\/bin/d' "$HOME/.bashrc"
PATH="$PATH:/usr/local/lib/nodejs/bin"
echo 'PATH="$PATH:/usr/local/lib/nodejs/bin"' >> "$HOME/.bashrc"
npm i -g npm
fi
# apt-vim InstantMarkdown dep: instant-markdown-d
if [[ ! "$(npm ls -g)" == *"instant-markdown-d"* ]]; then
npm i -g instant-markdown-d
fi
# apt-vim pkgs
for vimpkg in \
airblade/vim-gitgutter \
fatih/vim-go \
flazz/vim-colorschemes \
hashivim/vim-terraform \
nathanaelkane/vim-indent-guides \
suan/vim-instant-markdown \
tpope/vim-fugitive \
vim-airline/vim-airline \
; do
apt-vim install -y "https://github.com/${vimpkg}.git"
done
# golang
########
GO_VERSION="${GO_VERSION:-1.22.5}"
if [[ ! "$(go version)" == *"$GO_VERSION"* ]]; then
echo "Installing golang version $GO_VERSION"
_sudo rm -rf /usr/local/go
curl -sL "https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz" \
| _sudo tar -C /usr/local -xzf -
sed -i '/\go\/bin/d' "$HOME/.bashrc"
PATH="$PATH:/usr/local/go/bin"
echo 'PATH="$PATH:/usr/local/go/bin"' >> "$HOME/.bashrc"
fi
# CONFIGURE
###########
# Kernel
########
for file in files/sysctl.d/*.conf; do
_copyFile "$file" "/etc/sysctl.d/$(basename "$file")" sudo
done
_sudo service procps force-reload
# Profile
#########
for file in files/profile.d/*.sh; do
_copyFile "$file" "/etc/profile.d/$(basename "$file")" sudo
done
# Unset default history settings
if grep -qE '(histappend|HISTCONTROL|HISTFILESIZE|HISTSIZE|HISTTIMEFORMAT)' "$HOME/.bashrc"; then
sed -i -E '/(histappend|HISTCONTROL|HISTFILESIZE|HISTSIZE|HISTTIMEFORMAT)/d' "$HOME/.bashrc"
fi
# Set gnome-terminal to use login shell
if [ -x "$(command -v gsettings)" ]; then
UUID="$(gsettings get org.gnome.Terminal.ProfilesList default | tr -d \')"
gsettings set \
org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:"${UUID}"/ \
login-shell true
fi
# Setup case insensitive tab completion
_copyFile files/inputrc "$HOME/.inputrc"
# Git
#####
_copyFile files/gitconfig "$HOME/.gitconfig"
# Vim
#####
_copyFile files/vimrc "$HOME/.vimrc"
# REGOLITH
##########
function _detect_os_codename() {
[[ -f /etc/os-release ]] && \
grep VERSION_CODENAME /etc/os-release | \
cut -f2 -d= | \
tr -d '"'
}
function _install_regolith() {
if [ -x "$(command -v regolith-session)" ]; then
# Regolith already installed
return
fi
if [ -z "$ARCH" ]; then
echo "Unable to install Regolith; incompatible arch"
return
fi
OS_CODENAME="${OS_CODENAME:-$(_detect_os_codename)}"
if [ -z "$OS_CODENAME" ]; then
echo "Unable to install Regolith; incompatible OS"
return
fi
case "$OS_CODENAME" in
bookworm)
REGOLITH_DEB="deb [arch=${ARCH} signed-by=/usr/share/keyrings/regolith-archive-keyring.gpg] https://regolith-desktop.org/release-3_0-debian-bookworm-${ARCH} bookworm main" ;;
trixie) # Debian testing
REGOLITH_DEB="deb [arch=${ARCH} signed-by=/usr/share/keyrings/regolith-archive-keyring.gpg] https://regolith-desktop.org/testing-debian-testing-${ARCH} testing main" ;;
jammy)
REGOLITH_DEB="deb [arch=${ARCH} signed-by=/usr/share/keyrings/regolith-archive-keyring.gpg] https://regolith-desktop.org/release-3_1-ubuntu-jammy-${ARCH} jammy main" ;;
mantic)
REGOLITH_DEB="deb [arch=${ARCH} signed-by=/usr/share/keyrings/regolith-archive-keyring.gpg] https://regolith-desktop.org/release-3_1-ubuntu-mantic-${ARCH} mantic main" ;;
esac
if [ -z "$REGOLITH_DEB" ]; then
echo "Unable to install Regolith; incompatible OS codename '$OS_CODENAME'"
return
fi
# Register the Regolith public key
wget -qO - https://regolith-desktop.org/regolith.key | gpg --dearmor | _sudo tee /usr/share/keyrings/regolith-archive-keyring.gpg > /dev/null
# Add the Regolith repository URL
echo "$REGOLITH_DEB" | _sudo tee /etc/apt/sources.list.d/regolith.list
# Update apt & install Regolith
_sudo apt update
_sudo apt install -y \
regolith-desktop \
regolith-session-flashback \
regolith-look-ayu \
regolith-look-ayu-dark \
regolith-look-ayu-mirage \
regolith-look-gruvbox \
regolith-look-nevil \
regolith-look-nord
}
_install_regolith