Last active
October 30, 2024 16:30
-
-
Save 1stvamp/06167ba5097cf567118e1a8ad89c7b5b to your computer and use it in GitHub Desktop.
Update SSH config to include tailscale staging/production/tooling hosts, add "Include /Users/YOURUSER/.ssh/tailscale-hosts" to the top of ~/.ssh/config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
HOSTS=$(curl -s -XGET --url "https://api.tailscale.com/api/v2/tailnet/${TAILSCALE_DOMAIN}/devices" -H "Authorization: Bearer ${TAILSCALE_SSH_CONFIG_UPDATER_TOKEN}" | jq -r '.devices.[].name' | grep -E -- "-(staging|production|tooling).${TAILSCALE_MAGICDNS_DOMAIN}$") | |
cat << EOF > "${HOME}/.ssh/tailscale-hosts" | |
Host *.${TAILSCALE_MAGICDNS_DOMAIN} | |
User ${TAILSCALE_SSH_USER} | |
EOF | |
for HOST in ${HOSTS} | |
do | |
short="${HOST/.${TAILSCALE_MAGICDNS_DOMAIN}/}" | |
shortshort=$(echo "${short}" | sed 's/-[^-]*$//') | |
description= | |
if [[ "${HOST}" == *"staging"* ]] | |
then | |
description="${shortshort} STAGING server" | |
elif [[ "${HOST}" == *"production"* ]] | |
then | |
description="${shortshort} PRODUCTION server" | |
elif [[ "${HOST}" == *"tooling"* ]] | |
then | |
description='TOOLING server' | |
description="${shortshort} TOOLING server" | |
fi | |
cat << EOF >> "${HOME}/.ssh/tailscale-hosts" | |
Host ${short} | |
Hostname ${HOST} | |
User ${TAILSCALE_SSH_USER} | |
#_Desc ${description} | |
#@desc ${description} | |
EOF | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment