improvements to configure
This commit is contained in:
@@ -14,12 +14,45 @@ is_installed() {
|
||||
|
||||
# Tailscale has no status field naming its login server, so tailscale.conf
|
||||
# records which Core it was set up for
|
||||
is_configured() {
|
||||
[ -n "$CORE_DOMAIN" ] && [ "$TAILSCALE_DOMAIN" = "$CORE_DOMAIN" ] \
|
||||
joined() {
|
||||
[ -n "$TAILSCALE_DOMAIN" ] \
|
||||
&& tailscale status --json 2> /dev/null | jq -e '.BackendState == "Running"' > /dev/null
|
||||
}
|
||||
|
||||
# Done when on the main Core's network
|
||||
is_configured() {
|
||||
[ -n "$CORE_DOMAIN" ] && [ "$TAILSCALE_DOMAIN" = "$CORE_DOMAIN" ] && joined
|
||||
}
|
||||
|
||||
# Log out rather than only go down, so this computer's key is expired on
|
||||
# headscale and it's off the network until it joins again
|
||||
leave_network() {
|
||||
sudo tailscale logout || return 1
|
||||
rm -f "$TAILSCALE_CONF"
|
||||
echo "This computer has left your Core's Tailscale network. To join again: configure tailscale"
|
||||
}
|
||||
|
||||
run_configure() {
|
||||
local choice
|
||||
if joined &> /dev/null; then
|
||||
echo "This computer is on $TAILSCALE_DOMAIN's Tailscale network (headscale.$TAILSCALE_DOMAIN)."
|
||||
echo
|
||||
if [ "$TAILSCALE_DOMAIN" = "$CORE_DOMAIN" ]; then
|
||||
echo " 1) Join it again"
|
||||
else
|
||||
echo " 1) Join your main Core's network instead (headscale.$CORE_DOMAIN)"
|
||||
fi
|
||||
echo " 2) Leave the network"
|
||||
echo " q) Leave it as it is"
|
||||
echo
|
||||
read -rp "Choose: " choice
|
||||
case "$choice" in
|
||||
1) ;;
|
||||
2) leave_network; return ;;
|
||||
*) return 0 ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -z "$CORE_DOMAIN" ]; then
|
||||
echo "This joins your Core's Tailscale network, so set up your Core first: configure core"
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user