-
Notifications
You must be signed in to change notification settings - Fork 0
/
arkanum
executable file
·427 lines (382 loc) · 12.8 KB
/
arkanum
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/bin/bash
set -e
# region usage
function showHelp() {
cat << HELP
🧙 arkanum ✨🌌☄️💥 is used to install optional tools for developing in a
code-server container environment.
Syntax: arkanum <flags> COMMAND OPTION ARGUMENT
COMMAND
config The config command is used to modify arkanum itself.
git The git command is a wrapper for git helpers.
install The install command is used to add different tools
help Shows this help text.
OPTION
config:
disable-motd Disables hint in new bash terminal.
install-extensions Installs predefined recommended extensions.
reset-codesettings Sets VS Code user setting with basic (Fira Code).
git:
setup Takes two arguments to setup the git client:
1) Username
2) Email address
install:
docker-cli Installs the latest docker-cli.
dotnet Installs latest LTS dotnet core sdk + runtime.
gitea Installs gitea tools like changelog and tea.
golang Installs golang 1.21.5.
bun Installs latest bun version.
nodejs Installs latest NodeJs LTS version using Volta.
volta Installs Volta as NodeJS version manager.
powershell Installs latest PowerShell LTS version.
lazygit Installs latest Lazygit binary.
session:
save Adds items from the install command to the session config.
restore Restores the saved session.
reset Resets the session config.
show Show currently defined session content.
Example 1: arkanum git setup "my-name" "my-email"
Example 2: arkanum install golang
Example 3: arkanum config disable-motd
Example 4: arkanum session save lazygit powershell gitea
HELP
}
# endregion usage
function disableMotd() {
if [[ -e "$HOME/enable_motd" ]]; then
say "Disabling 'arkanum' motd..." "disableMotd"
rm -f "$HOME/enable_motd"
else
sayW "Arkanum Motd already disabled" "disableMotd"
fi
}
function say() {
if [[ -n "$2" ]]; then
echo -e "🧙 \e[32markanum\e[0m \e[34m[⚒️ $2]\e[0m: $1"
else
echo -e "🧙 \e[32markanum\e[0m: $1"
fi
}
function sayE() {
if [[ -n "$2" ]]; then
echo -e "🧙 \e[31markanum\e[0m \e[34m[⚒️ $2]\e[0m: $1" 1>&2
else
echo -e "🧙 \e[31markanum\e[0m: $1" 1>&2
fi
}
function sayW() {
if [[ -n "$2" ]]; then
echo -e "🧙 \e[33markanum\e[0m \e[34m[⚒️ $2]\e[0m: $1" 1>&2
else
echo -e "🧙 \e[33markanum\e[0m: $1" 1>&2
fi
}
function instDockerCLI() {
say "Installing docker-cli..." "docker-cli"
say "Getting requires packages..." "docker-cli"
sudo -E apt-get update > /dev/null
sudo -E apt-get install ca-certificates curl gnupg
say "Setting up docker repository..." "docker-cli"
sudo -E install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo -E gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo -E chmod a+r /etc/apt/keyrings/docker.gpg
# shellcheck disable=SC2046,SC2027
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
say "Installing docker-ce-cli package" "docker-cli"
sudo -E apt-get update > /dev/null
sudo -E apt-get install --no-install-recommends -y \
docker-ce-cli
say "docker-cli done." "docker-cli"
}
function instDotNet() {
say "Installing dotnet requirements..." "dotnet"
sudo -E apt-get update > /dev/null
sudo -E apt-get install --no-install-recommends -y \
libicu74
say "Downloading latest install script..." "dotnet"
curl -#fSL https://dot.net/v1/dotnet-install.sh -o /tmp/dotnet-install.sh
chmod +x /tmp/dotnet-install.sh
say "Installing latest .NET Core LTS release..." "dotnet"
/tmp/dotnet-install.sh --channel LTS
# shellcheck disable=SC2016
echo 'export PATH=$PATH:/config/.dotnet' | sudo tee -a /etc/bash.bashrc > /dev/null
say "Cleaning up..." "dotnet"
sudo -E apt-get clean
sudo rm -rf \
/tmp/* \
/var/lib/apt/lists/* \
/var/tmp/*
say "dotnet done. " "dotnet"
}
function instGoLang() {
if [[ -z "$1" ]]; then
GOVERSION="1.23.2"
else
GOVERSION="$1"
fi
say "Downloading golang ($GOVERSION)..." "GoLang"
curl -#fSL "https://go.dev/dl/go$GOVERSION.linux-amd64.tar.gz" -o /tmp/golang.tar.gz
say "Installing golang ($GOVERSION)...." "GoLang"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf /tmp/golang.tar.gz
# shellcheck disable=SC2016
echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee -a /etc/bash.bashrc > /dev/null
say "Cleaning up..." "GoLang"
rm -f /tmp/golang.tar.gz
say "done." "GoLang"
say "Please reload bash profile to finalize." "GoLang"
}
function instBun() {
say "Installing Bun requirements..." "Bun"
sudo -E apt-get update > /dev/null
sudo -E apt-get install --no-install-recommends -y \
unzip
sudo -E apt-get clean
say "Installing Bun binaries..." "Bun"
curl -#fSL https://bun.sh/install | bash
say "Adding bun binary to profile..." "Bun"
echo 'export BUN_INSTALL=$HOME/.bun' | sudo tee -a /etc/bash.bashrc > /dev/null
echo 'export PATH=$BUN_INSTALL/bin:$PATH' | sudo tee -a /etc/bash.bashrc > /dev/null
say "done." "Bun"
say "Please reload bash profile to finalize." "Bun"
}
function instNodeJs() {
say "Installing NodeJS LTS via Volta..." "NodeJS"
volta install node@lts
say "done." "NodeJS"
}
function instVolta() {
say "Installing Volta as NodeJS version manager..." "Volta"
curl -#fSl https://get.volta.sh | bash
# shellcheck disable=SC1090
source ~/.profile
say "done." "Volta"
}
function instPwsh() {
say "Installing PowerShell requirements..." "PowerShell"
sudo -E apt-get update > /dev/null
sudo -E apt-get install --no-install-recommends -y \
apt-transport-https \
software-properties-common
say "Adding powershell package sources..." "PowerShell"
# Download the Microsoft repository GPG keys
curl -#fSL "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb" -o /tmp/packages-microsoft-prod.deb
# Register the Microsoft repository GPG keys
sudo dpkg -i /tmp/packages-microsoft-prod.deb
# Update the list of packages after we added packages.microsoft.com
sudo -E apt-get update
say "Installing PowerShell..." "PowerShell"
# Install PowerShell
sudo -E apt-get install --no-install-recommends -y \
powershell-lts
say "done." "PowerShell"
}
function instGiteaTools() {
TEA_VERSION="0.9.0"
CHANGELOG_VERSION="main"
say "Installing Gitea tools..." "Gitea"
say "Downloading 'changelog' ($CHANGELOG_VERSION)..." "Gitea"
sudo -E curl -#fSL "https://dl.gitea.io/changelog-tool/$CHANGELOG_VERSION/changelog-$CHANGELOG_VERSION-linux-amd64" -o /usr/bin/changelog
sudo chmod +x /usr/bin/changelog
say "'changelog' command installed." "Gitea"
say "Downloading 'tea' ($TEA_VERSION)..." "Gitea"
sudo -E curl -#fSL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-amd64 -o /usr/bin/tea
sudo chmod +x /usr/bin/tea
say "'tea' command installed." "Gitea"
say "done." "Gitea"
}
function installLazyGit() {
say "Installing latest lazygit version..." "Lazygit"
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')
sudo -E curl -#fSL "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" -o /tmp/lazygit.tar.gz
#mkdir -p /tmp/lazygit
cd /tmp
tar xf /tmp/lazygit.tar.gz lazygit
say "Installing Lazygit binary" "Lazygit"
sudo install /tmp/lazygit /usr/local/bin
say "Removing lazygit cache files..." "Lazygit"
sudo rm -f /tmp/lazygit.tar.gz
rm -rf /tmp/lazygit
}
function instCodeExtension() {
say "Installing default extensions...." "Extension"
# Gitlens
say "Installing 'gitlens'..." "Extension"
install-extension eamodio.gitlens --force
# OneDarkPro
say "Installing 'One Dark Pro' theme..." "Extension"
install-extension zhuangtongfa.material-theme --force
# vscode-icons
say "Installing 'vscode-icons' theme..." "Extension"
install-extension vscode-icons-team.vscode-icons --force
say "done." "Extension"
}
function setCodeSettings() {
CODEFILE="$HOME/data/User/settings.json"
#region code-settings
# VSCode user settings file
say "Setting VScode base settings.($CODEFILE)" "VSCode"
cat <<EOF | tee "$CODEFILE"
{
"window.menuBarVisibility": "compact",
"workbench.colorTheme": "One Dark Pro Darker",
"workbench.iconTheme": "vscode-icons",
"editor.fontFamily": "'FiraCode', 'FiraCode Nerd Font', 'FiraCode NF', Consolas, 'Courier New', monospace",
"terminal.integrated.fontFamily": "'FiraCode Mono', 'FiraCode Nerd Font Mono', 'FiraCode NFM', Consolas, monospace",
"editor.fontLigatures": true,
"editor.formatOnSave": true,
"extensions.autoUpdate": false,
"git.confirmSync": false,
"telemetry.telemetryLevel": "off"
}
EOF
#endregion code-settings
say "done." "VSCode"
}
function setGitConfig() {
#echo "function arg counter is; $#"
#echo "function args:$@"
if [[ "$#" != "4" ]]; then
sayE "Invalid arguments given. Please provide '<user>' and '<email>'!" "Git"
exit 1
fi
if [[ -z "$3" ]]; then
sayE "Invalid or empty username given!" "Git"
exit 1
fi
if [[ -z "$4" ]]; then
sayE "Invalid or empty email given!" "Git"
exit 1
fi
say "Setting global git config..." "Git"
git config --global user.name "$3"
git config --global user.email "$4"
say "Returning global config:" "Git"
git config --list --global
}
function saveSession() {
SESSION_FILE="$HOME/arkanum-session"
if [[ $# -ge 3 ]]; then
for item in "${@:3}"; do
say "Adding '$item' to your session config" "saveSession"
echo "$item" | tee -a "$SESSION_FILE" > /dev/null
done
else
sayE "Unknown parameter count given" "saveSession"
exit 1
fi
}
function restoreSession() {
SESSION_FILE="$HOME/arkanum-session"
if [[ -e "$SESSION_FILE" ]]; then
while read item; do
say "Restoring '$item'..." "restoreSession"
arkanum install "$item"
done <"$SESSION_FILE"
say "Arkanum session restore completed. 🏁" "restoreSession"
else
sayE "There is no arkanum session!" "restoreSession"
exit 1
fi
}
function showSession() {
SESSION_FILE="$HOME/arkanum-session"
say "Trying to read your session config '$SESSION_FILE':" "showSession"
if [[ -e "$SESSION_FILE" ]]; then
cat "$SESSION_FILE"
else
sayE "There is no session defined!" "showSession"
fi
}
function resetSession() {
SESSION_FILE="$HOME/arkanum-session"
say "Deleting session file '$SESSION_FILE'..." "resetSession"
rm "$SESSION_FILE"
}
function main() {
if [[ "$#" == "0" ]]; then
showHelp
exit 0
fi
# Command filter
if [[ "$1" =~ ^help|-h|--h$ ]]; then
showHelp
exit 0
fi
# CONFIG command
if [[ "$1" == "config" ]]; then
# disable-motd option
if [[ "$2" == "disable-motd" ]]; then
disableMotd
exit 0
# install-extensions option
elif [[ "$2" == "install-extensions" ]]; then
instCodeExtension
exit 0
# reset-codesetting option
elif [[ "$2" == "reset-codesettings" ]]; then
setCodeSettings
exit 0
else
sayE "Unknown option ($2) given for command 'config'!"
fi
# GIT command
elif [[ "$1" == "git" ]]; then
# setup option
if [[ "$2" == "setup" ]]; then
setGitConfig "$@"
else
sayE "Unknown option ($2) given for command 'git'!"
fi
# INSTALL command
elif [[ "$1" == "install" ]]; then
# docker-cli option
if [[ "$2" == "docker-cli" ]]; then
instDockerCLI
elif [[ "$2" == "dotnet" ]]; then
instDotNet
elif [[ "$2" == "golang" ]]; then
instGoLang "$3"
elif [[ "$2" == "bun" ]]; then
instBun
elif [[ "$2" == "nodejs" ]]; then
instVolta
instNodeJs
elif [[ "$2" == "volta" ]]; then
instVolta
elif [[ "$2" == "powershell" ]]; then
instPwsh
elif [[ "$2" == "gitea" ]]; then
instGiteaTools
elif [[ "$2" == "lazygit" ]]; then
installLazyGit
else
sayE "Unknown option ($2) given for command 'install'!"
fi
elif [[ "$1" == "session" ]]; then
# session option
if [[ "$2" == "save" ]]; then
saveSession "$@"
exit 0
elif [[ "$2" == "restore" ]]; then
restoreSession
exit 0
elif [[ "$2" == "show" ]]; then
showSession
exit 0
elif [[ "$2" == "reset" ]]; then
resetSession
exit 0
else
sayE "Unknown option ($2) given for command 'session'!"
fi
else
sayE "Unknown parameter value given!($1)."
showHelp
exit 1
fi
}
main "$@"