Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
199 lines (175 loc) · 5.67 KB
/
Copy pathjustfile
File metadata and controls
199 lines (175 loc) · 5.67 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
# SPDX-FileCopyrightText: © 2025 hazzuk
#
# SPDX-License-Identifier: AGPL-3.0-only
# justfile, for running project-specific commands.
# See https://just.systems/man/en for more information.
set minimum-version := '1.55.0'
set default-list := true
# List recipes
help:
@{{ just_executable() }}
# Reusable confirmation statement
[private]
[confirm("proceed? (y/N)")]
confirm:
@echo
# Debian install
# ---
# Host preseed.cfg
[group('Debian install')]
@preseed platform='server':
# check user input for platform
[ "{{platform}}" = "server" ] || [ "{{platform}}" = "desktop" ] || { echo "platform must be 'server' or 'desktop'" >&2; exit 1; }
# check user key file exists
[ -e "inventory/key.txt" ] || { echo "inventory/key.txt not found" >&2; exit 1; }
# insert public ssh key into preseed file
just insert-preseed-key "$(cat inventory/key.txt)" {{platform}}
# run webserver
-just host-preseed {{platform}}
-# revert change to preseed file
-just insert-preseed-key "<key>" {{platform}}
# Write the authorized SSH key to the Debian preseed file
[private]
insert-preseed-key value platform:
@sed -i "s|echo '.*'|echo '{{value}}'|" debian/{{platform}}/d-i/trixie/preseed.cfg
# Run a Python HTTP server to host the preseed file
[private]
host-preseed platform:
@echo "press 'Ctrl + C' to exit"
-python3 -m http.server 8000 --bind 0.0.0.0 --directory ./debian/{{platform}}
# System setup
# ---
# Setup a system
[group('System setup')]
@install hostname='': check-password
ansible-playbook run.yml --tags install --limit "{{hostname}}"
# Up/down Docker stacks
[group('System setup')]
[arg("stack", long, short="s")]
compose action hostname='' stack='all': check-password
#!/bin/bash
# check user input for action
if [ "{{action}}" = "up" ]; then
skip_tags="down"
elif [ "{{action}}" = "down" ]; then
skip_tags="up"
else
echo "action must be 'up' or 'down'" >&2; exit 1;
fi
# manage symlinks
just custom-symlink
# run user action
ANSIBLE_DISPLAY_SKIPPED_HOSTS=false ansible-playbook run.yml \
--extra-vars "karo_compose_justfile_stack={{stack}}" \
--tags compose \
--skip-tags "$skip_tags" \
--limit "{{hostname}}"
# Ansible vault
# ---
password := "/run/user/1000/karo/ansible/vault_pass"
# Manage a vault
[group('Ansible vault')]
vault hostname:
#!/bin/bash
# check password file exists
if [ -e "{{password}}" ]; then
# check vault file exists
export vault="inventory/host_vars/{{hostname}}/vault.yml"; echo $vault
if [ -e "$vault" ]; then
# edit existing vault
ansible-vault edit "$vault"
else
# create new vault
ansible-vault create "$vault"
fi
else
echo "{{password}} not found, run 'just password'." >&2; exit 1;
fi
# Create the Ansible vault password file when missing
[private]
check-password:
@[ -e "{{password}}" ] || micro -backup false -mkparents true "{{password}}"
# Set password file
[group('Ansible vault')]
password:
@micro -backup false -mkparents true "{{password}}"
# Wireguard
# ---
# Generate key pair
[private]
wireguard:
@priv="$(wg genkey)"; \
pub="$(wg pubkey <<<"$priv")"; \
printf 'Private key: %s\n' "$priv"; \
printf 'Public key: %s\n' "$pub"
# Custom repos
# ---
# Get/remove custom repos
[group('Custom repos')]
custom action username:
#!/usr/bin/env bash
set -euo pipefail
case "{{action}}" in
get)
echo "Getting repo {{lowercase(username)}}/karo-custom"
just custom-get {{lowercase(username)}}
;;
remove)
echo "removing custom/{{lowercase(username)}}"
just custom-remove {{lowercase(username)}}
;;
*)
echo "action must be 'get' or 'remove'" >&2; exit 1;
;;
esac
repo_name := "karo-custom"
# Get remote karo-custom repo
[private]
custom-get username:
#!/usr/bin/env bash
set -euo pipefail
# clone karo-custom git repo
git clone git@github.com:{{username}}/{{repo_name}}.git custom/{{username}}
# check karo-custom repo dir not empty
if [ -z "$(find custom/{{username}}/karo-compose -mindepth 1 -maxdepth 1)" ]; then
exit 0
else
# manage symlinks
just custom-symlink
# list stack groups for username
echo "new karo-compose stack groups:"
ls -1 roles/karo-compose/templates | grep {{username}} | awk '{print "- " $0}'
fi
# Remove a karo-custom repo
[private]
@custom-remove username:
# check username dir exists
test -d "custom/{{username}}"
# confirm removal
just confirm
# remove custom dir
rm -rf "custom/{{username}}"
# manage symlinks
just custom-symlink
# Manage symbolic links for custom files
[private]
custom-symlink:
#!/usr/bin/env bash
set -euo pipefail
# clear existing symlinks
find roles/karo-compose/defaults/main/ -mindepth 1 -maxdepth 1 ! -name "main.yml" -delete
find roles/karo-compose/templates/ -mindepth 1 -maxdepth 1 ! -name ".gitkeep" -delete
# check custom dir not empty
if [ -z "$(find custom -mindepth 1 -maxdepth 1)" ]; then
exit 0
else
# symlink custom files
ln -sr custom/*/karo-compose/defaults/main/*/ roles/karo-compose/defaults/main/
ln -sr custom/*/karo-compose/templates/*/ roles/karo-compose/templates/
fi
# check inventory for custom dir
if [ -d inventory/karo-compose ]; then
# symlink custom files from inventory
ln -sr inventory/karo-compose/defaults/main/*/ roles/karo-compose/defaults/main/
ln -sr inventory/karo-compose/templates/*/ roles/karo-compose/templates/
fi