diff --git a/startup.bash b/startup.bash index a90fb3d..cfd9717 100644 --- a/startup.bash +++ b/startup.bash @@ -1,13 +1,35 @@ -#!/usr/bin/env bash -x +#!/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 - +install \ + -Dm 600 \ + -o thurstylark \ + -g thurstylark \ + /run/secrets/tl-weechat-authorizedkeys \ + /home/thurstylark/.ssh/authorized_keys #### @@ -16,6 +38,9 @@ install -Dm 600 -o thurstylark -g thurstylark /run/secrets/tl-weechat-authorized # 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