Last active
August 29, 2017 14:03
-
-
Save toonetown/444211fc2830ae765693f8c28612b6e5 to your computer and use it in GitHub Desktop.
Leverages alias-local to automatically add/remove SSH hosts.
This file contains 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 | |
source /etc/profile | |
# The location of the ssh config file and alias-local | |
: ${SSHCONF:="/var/run/Shimo/configs/${CS_UNIQUE_IDENTIFIER}.sshconf"} | |
: ${ALIAS_IFACE:="lo0"} | |
: ${ALIAS_LOCAL:="$(which alias-local 2>/dev/null)"} | |
# Read the mappings in the config file - only if we have an alias-local command installed in our path | |
[ -f "${SSHCONF}" -a -x "${ALIAS_LOCAL}" ] && { | |
MAPPED=() | |
for i in $(cat "${SSHCONF}" | grep '^LocalForward ' | cut -d' ' -f2 | cut -d':' -f1 | sort -u); do | |
"${ALIAS_LOCAL}" "${i}" "${ALIAS_IFACE}" && MAPPED+=(${i}) | |
done | |
trap 'for i in "${MAPPED[@]}"; do "${ALIAS_LOCAL}" -d "${i}" "${ALIAS_IFACE}" &>/dev/null; done;' EXIT | |
} | |
# Call the original parameters as-is | |
"$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment