From ab2b0248c8c58099853203cd1f3f26cc69f78c9e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 26 Apr 2020 09:15:09 -0500 Subject: Update style --- mrgrctrnl | 94 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/mrgrctrnl b/mrgrctrnl index ca17f55..d51be58 100755 --- a/mrgrctrnl +++ b/mrgrctrnl @@ -5,40 +5,40 @@ # version 0.1 # LICENSE: MIT -usage() -{ +usage() { cat <<-END - mrgrctrnl: make magic ssh tunnels - usage: mrgrctrnl [-h] [-c CONF] [-d] [-k] + mrgrctrnl: make magic ssh tunnels + usage: mrgrctrnl [-h] [-c CONF] [-d] [-k] - -h show this help - -c CONF use config file CONF. - . default: \$XDG_CONFIG_HOME/mrgrctrnl/config - -d do a dry run: don't actually tunnel - -k kill all processes and exit + -h show this help + -c CONF use config file CONF. + . default: \$XDG_CONFIG_HOME/mrgrctrnl/config + -d do a dry run: don't actually tunnel + -k kill all processes and exit END exit "${1:-0}" } -die() -{ +die() { [ "$#" -eq 0 ] && exit 1 case "$1" in - 0-9*) ec="$1"; shift ;; - *) ec=1 ;; + 0-9*) + ec="$1" + shift + ;; + *) ec=1 ;; esac printf '!!%s: %s\n' "mrgrctrnl" "$*" exit "$ec" } -demolish_tunnels() -{ +demolish_tunnels() { printf '%s...' "Demolishing tunnels" while read -r pid; do [ -z "$pid" ] && continue kill "$pid" 2>/dev/null - done < "$pidf" + done <"$pidf" rm "$pidf" sleep 3 printf '%s.\n' "Done" @@ -50,48 +50,46 @@ dry_run=false while getopts hc:dk opt; do case "$opt" in - h) usage ;; - c) config="$OPTARG" ;; - d) dry_run=true ;; - k) - demolish_tunnels - pkill -x mrgrctrnl - exit - ;; - \?) usage 2 ;; - *) usage 2 ;; + h) usage ;; + c) config="$OPTARG" ;; + d) dry_run=true ;; + k) + demolish_tunnels + pkill -x mrgrctrnl + exit + ;; + \?) usage 2 ;; + *) usage 2 ;; esac done shift "$((OPTIND - 1))" [ -f "$config" ] || die "Need a config! Edit $config" -if [ -e "$pidf" ] && ! "$dry_run" -then demolish_tunnels +if [ -e "$pidf" ] && ! "$dry_run"; then + demolish_tunnels fi awk '{sub(/#.*$/,"");print}' "$config" | -while read -r machine user local remote key rest -do - if [ -z "$machine" ] || [ -z "$user" ] || - [ -z "$local" ] || [ -z "$remote" ] - then continue - fi + while read -r machine user local remote key rest; do + if [ -z "$machine" ] || [ -z "$user" ] || + [ -z "$local" ] || [ -z "$remote" ]; then + continue + fi - set -- -N "$user@$machine" -L "$local:$remote" - [ -n "$key" ] && set -- "$@" -i "$key" - #shellcheck disable=2086 - [ -n "$rest" ] && set -- "$@" $rest + set -- -N "$user@$machine" -L "$local:$remote" + [ -n "$key" ] && set -- "$@" -i "$key" + #shellcheck disable=2086 + [ -n "$rest" ] && set -- "$@" $rest - echo ssh "$@" + echo ssh "$@" - "$dry_run" || { - while : - do - ssh "$@" - echo "$!" >> "$pidf" - sleep 5 - done & - } -done + "$dry_run" || { + while :; do + ssh "$@" + echo "$!" >>"$pidf" + sleep 5 + done & + } + done wait -- cgit 1.4.1-21-gabe81