-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask
More file actions
executable file
·302 lines (256 loc) · 10.7 KB
/
task
File metadata and controls
executable file
·302 lines (256 loc) · 10.7 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
#!/usr/bin/env bash
set -e
if [[ -a ".env" ]]; then
source .env
fi
help-table() {
local cmd_width=24
local opt_width=10
local desc_width=60
local column="| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n"
printf "$column" "Command" "Option" "Description"
echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((desc_width + 2)) '' | tr ' ' '-')|"
printf "$column" 'clone-taskfile' '' 'Clone the taskfile.build repo.'
printf "$column" "install" "[name]" "Install a package."
printf "$column" "list" "[grep]" "List all available packages."
printf "$column" "set-git-origin" "" "Change git origin to ssh."
printf "$column" "setup-passwordless-sudo" "" "Get sudoers entry for passwordless sudo."
printf "$column" "setup-mint-system" "" "Clone Mint System git repos."
}
help() {
echo
if [[ -n "$1" ]]; then
help-table | grep -i "$1" | column -t -s'|'
else
echo "task <command> [options]"
echo
echo "commands:"
echo
help-table
fi
echo
}
# Updateable env vars
KEEPASS_DATABASE_FILE=${KEEPASS_DATABASE_FILE:="$HOME/cloud.mint-system.ch/Mint System/Data/Infrastruktur.kdbx"}
KEEPASS_DATABASE_KEY_FILE=${KEEPASS_DATABASE_KEY_FILE:="$HOME/cloud.mint-system.ch/Mint System/Secrets/KeePass.key"}
# Conditional env vars
if command -v pacman >/dev/null 2>&1; then
export PACKAGE_MANAGER="pacman"
elif command -v apt >/dev/null 2>&1; then
export PACKAGE_MANAGER="apt"
elif command -v dnf >/dev/null 2>&1; then
export PACKAGE_MANAGER="dnf"
else
export PACKAGE_MANAGER="unknown"
fi
# Import commands
clone-taskfile(){
if [[ ! -d "$HOME/taskfile.build" ]]; then
echo -e "\033[38;5;214mGit\033[0m: Clone taskfile repo"
git clone https://git.taskfile.build "$HOME/taskfile.build"
else
echo -e "\033[38;5;214mGit\033[0m: Pull taskfile repo"
git -C "$HOME/taskfile.build" pull
fi
}
if [[ -d "$HOME/taskfile.build/bin" ]]; then
for file in "$HOME/taskfile.build/bin/"*; do
if [[ -f "$file" ]]; then
source "$file"
fi
done
fi
# Env commands
set-git-origin(){
echo "Change git origin."
git remote set-url origin [email protected]:Mint-System/Dotfiles.git
}
# Package commands
list() {
list-table() {
local cmd_width=20
local opt_width=40
local column="| %-${cmd_width}s | %-${opt_width}s |\n"
printf "$column" "Name" "Description"
echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|"
printf "$column" "llm" "Install LLM cli."
printf "$column" "nextcloud" "Install Nextcloud Desktop."
printf "$column" "uv" "Install uv."
printf "$column" "obsidian" "Install Obsidian."
printf "$column" "opencode" "Install OpenCode cli."
printf "$column" "pnpm" "Install pnpm."
printf "$column" "tools" "Install common tools."
printf "$column" "kubectl" "Install kubectl and kubectx."
printf "$column" "kubeseal" "Install kubeseal."
printf "$column" "k9s" "Install k9s."
printf "$column" "kind" "Install kind."
printf "$column" "keepass" "Install KeepassXC and keepassxc-cli."
}
echo
if [[ -n "$1" ]]; then
list-table | grep -i "$1" | column -t -s'|'
else
list-table
fi
echo
}
install() {
if [[ -z "$1" ]]; then echo "\$1 is empty."; exit; fi
local command="install-$1"
$command
}
install-tools() {
echo "Install yq."
sudo wget https://github.com/mikefarah/yq/releases/download/v4.2.0/yq_linux_amd64 -O /usr/bin/yq &&\
sudo chmod +x /usr/bin/yq
}
install-obsidian() {
echo "Install Obsidian."
if [[ "$PACKAGE_MANAGER" == "apt" ]]; then
# wcurl "https://github.com/obsidianmd/obsidian-releases/releases/download/v$RELEASE/obsidian_${RELEASE}_amd64.deb"
wcurl "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.8.9/obsidian_1.8.9_amd64.deb"
sudo apt install -y "./obsidian_1.8.9_amd64.deb"
rm "obsidian_1.8.9_amd64.deb"
elif [[ "$PACKAGE_MANAGER" == "dnf" ]]; then
sudo flatpak install -y md.obsidian.Obsidian
elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
sudo pacman -S --noconfirm obsidian
fi
}
install-kubectl() {
echo "Install kubectl."
curl -LO "https://dl.k8s.io/release/v1.34.0/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl
echo "Install krew."
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew
}
install-keepass() {
echo "Install KeepassXC."
if [[ "$PACKAGE_MANAGER" == "apt" ]]; then
sudo add-apt-repository ppa:phoerious/keepassxc
sudo apt update && sudo apt install -y keepassxc
elif [[ "$PACKAGE_MANAGER" == "dnf" ]]; then
sudo dnf install -y keepassxc
elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
sudo pacman -S --noconfirm keepassxc
fi
}
install-k9s() {
if [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
sudo pacman -S --noconfirm k9s
fi
}
install-kubeseal() {
# Fetch the latest sealed-secrets version using GitHub API
local kubeseal_version=$(curl -s https://api.github.com/repos/bitnami-labs/sealed-secrets/tags | jq -r '.[0].name' | cut -c 2-)
# Check if the version was fetched successfully
if [[ -z "$kubeseal_version" ]]; then
echo "Failed to fetch the latest kubeseal_version"
exit 1
fi
curl -OL "https://github.com/bitnami-labs/sealed-secrets/releases/download/v${KUBESEAL_VERSION}/kubeseal-${KUBESEAL_VERSION}-linux-amd64.tar.gz"
tar -xvzf kubeseal-${KUBESEAL_VERSION}-linux-amd64.tar.gz kubeseal
sudo install -m 755 kubeseal /usr/local/bin/kubeseal
rm kubeseal-${KUBESEAL_VERSION}-linux-amd64.tar.gz
rm kubeseal
}
install-kind() {
echo "Install kind."
# https://kind.sigs.k8s.io/docs/user/quick-start/#installation
[[ $(uname -m) = x86_64 ]] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-amd64
[[ $(uname -m) = aarch64 ]] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
}
install-llm() {
echo "Install LLM."
uv tool install llm
echo "Create symlink to extra openapi models config."
create-symlink "$PWD/llm/extra-openai-models.yaml" "$(dirname $(llm logs path))/extra-openai-models.yaml"
echo "Set infomaniak api key."
llm keys set infomaniak --value "$(get-pass-from-keepass dotenv/api_key_infomaniak)"
echo "Set cortecs api key."
llm keys set cortecs --value "$(get-pass-from-keepass dotenv/api_key_cortecs)"
echo "Set default model."
llm models default qwen3
}
install-nextcloud() {
echo "Install Nextcloud Desktop."
if [[ "$PACKAGE_MANAGER" == "apt" ]]; then
sudo add-apt-repository ppa:xtradeb/apps
sudo apt update && sudo apt install -y nextcloud-desktop
elif [[ "$PACKAGE_MANAGER" == "dnf" ]]; then
sudo dnf install -y nextcloud-client
elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
sudo pacman -S --noconfirm nextcloud-client
fi
}
install-opencode() {
echo "Install OpenCode cli."
pnpm install -g opencode-ai
}
install-pnpm() {
echo "Install pnpm."
curl -fsSL https://get.pnpm.io/install.sh | sh -
log-warning "Run this command to install Node for your project:"
echo "pnpm env use --global lts"
}
install-uv() {
echo "Install uv."
curl -LsSf https://astral.sh/uv/install.sh | sh
}
# Setup commands
setup-mint-system() {
echo "Enable git credentials store."
git config --global credential.helper store
echo "Update git origin."
[[ -d "$HOME/Ansible-Build/inventories" ]] && git -C "$HOME/Ansible-Build/inventories" remote set-url origin https://mint.app.codey.ch/mint-system/ansible-inventories
[[ -d "$HOME/Ansible-Build/inventories/opsone" ]] && git -C "$HOME/Ansible-Build/inventories/opsone" remote set-url origin https://mint.app.codey.ch/mint-system/ops-one-ansible-inventory
[[ -d "$HOME/Odoo-Build/vault" ]] && git -C "$HOME/Odoo-Build/vault" remote set-url origin https://mint.app.codey.ch/mint-system/odoo-build-vault
[[ -d "$HOME/Kubernetes-Build/values" ]] && git -C "$HOME/Kubernetes-Build/values" remote set-url origin https://mint.app.codey.ch/mint-system/helm-values
echo "Clone Mint-System repos."
# [[ ! -d "$HOME/Main-Build" ]] && git clone [email protected]:Mint-System/Main.Build.git "$HOME/Main-Build"
[[ ! -d "$HOME/Jenkins-Build" ]] && git clone [email protected]:Mint-System/Jenkins-Build.git "$HOME/Jenkins-Build"
[[ ! -d "$HOME/Nextcloud-Build" ]] && git clone [email protected]:Mint-System/Nextcloud-Build.git "$HOME/Nextcloud-Build"
[[ ! -d "$HOME/Kubernetes-Build" ]] && git clone [email protected]:Mint-System/Kubernetes-Build.git "$HOME/Kubernetes-Build"
[[ ! -d "$HOME/Odoo-Build" ]] && git clone [email protected]:Mint-System/Odoo-Build.git "$HOME/Odoo-Build"
[[ ! -d "$HOME/Ansible-Build" ]] && git clone [email protected]:Mint-System/Ansible-Build.git "$HOME/Ansible-Build"
[[ ! -d "$HOME/Odoo-Wiki" ]] && git clone [email protected]:Mint-System/Odoo-Wiki.git "$HOME/Odoo-Wiki"
[[ ! -d "$HOME/Wiki" ]] && git clone [email protected]:Mint-System/Wiki.git "$HOME/Wiki"
[[ ! -d "$HOME/Website" ]] && git clone [email protected]:Mint-System/Website.git "$HOME/Website"
[[ ! -d "$HOME/VarLog" ]] && git clone [email protected]:Mint-System/VarLog.git "$HOME/VarLog"
[[ ! -d "$HOME/Odoo-Build/vault" ]] && git clone https://mint.app.codey.ch/mint-system/odoo-build-vault "$HOME/Odoo-Build/vault"
[[ ! -d "$HOME/Kubernetes-Build/values" ]] && git clone https://mint.app.codey.ch/mint-system/helm-values "$HOME/Kubernetes-Build/values"
[[ ! -d "$HOME/Ansible-Build/inventories" ]] && git clone https://mint.app.codey.ch/mint-system/ansible-inventories "$HOME/Ansible-Build/inventories"
}
if [[ "$1" == *","* ]]; then
# Split comma-separated commands
IFS=',' read -ra COMMANDS <<< "$1"
for cmd in "${COMMANDS[@]}"; do
# Trim whitespace
cmd=$(echo "$cmd" | xargs)
if declare -f "$cmd" > /dev/null; then
"$cmd"
else
echo "Unknown command: $cmd"
help
exit 1
fi
done
elif declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
case "$1" in
*)
echo "Unknown command: $1"
exit 1
;;
esac
fi