53 lines
1.2 KiB
Bash
53 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
joinztnet() {
|
|
local ztaddrlist ztoutput ztaddr
|
|
ztaddrlist="$1"
|
|
|
|
# Yes, this is UUOC. No, I won't be changing it.
|
|
# shellcheck disable=2002,2162
|
|
cat "$ztaddrlist" | while read ztaddr; do
|
|
# `zerotier-cli join $address` will return the same success message if already joined
|
|
# to $address
|
|
ztoutput=$(zerotier-cli join "$ztaddr")
|
|
if [[ "$ztoutput" != "200 join OK" ]]; then
|
|
printf "Error: Unable to join ZeroTier network with ID: %s\nOutput: %s" \
|
|
"$ztaddr" \
|
|
"$ztoutput"
|
|
exit 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
####
|
|
# Runtime Config
|
|
|
|
# Copy authorized_keys secret to the user's ssh config folder
|
|
# (symlinking will not do, because sshd checks perms of the file tree above the target of the link)
|
|
install \
|
|
-Dm 600 \
|
|
-o thurstylark \
|
|
-g thurstylark \
|
|
/run/secrets/tl-weechat-authorizedkeys \
|
|
/home/thurstylark/.ssh/authorized_keys
|
|
|
|
|
|
####
|
|
# Service startup
|
|
|
|
# Start zerotier-one in daemon mode
|
|
zerotier-one -d
|
|
|
|
# Attempt to join the specified ZeroTier networks
|
|
joinztnets /run/secrets/tl-weechat-ztnetaddrs
|
|
|
|
# Start sshd
|
|
sshd
|
|
|
|
|
|
|
|
####
|
|
# Start weechat within tmux as thurstylark
|
|
|
|
runuser -u thurstylark -- tmux -f ~/.tmux.conf -L tl-weechat new-session -ds tl-weechat weechat
|