git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/bin/ssh-agent-launcher
diff options
context:
space:
mode:
Diffstat (limited to 'bin/ssh-agent-launcher')
-rwxr-xr-xbin/ssh-agent-launcher48
1 files changed, 48 insertions, 0 deletions
diff --git a/bin/ssh-agent-launcher b/bin/ssh-agent-launcher
new file mode 100755
index 0000000..0d116dc
--- /dev/null
+++ b/bin/ssh-agent-launcher
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+if [ -z "$SSHENVFILE" ];then
+ printf "SSHENVFILE not set, no target for SSH environment variables.\\n" >&2
+ exit 1
+fi
+
+VERB=1
+KILLIT=0
+while getopts ":qf" SHOPT;do
+ case "$SHOPT" in
+ q) VERB=0;;
+ f) KILLIT=1;;
+ *) printf "WAT\n" >&2;exit 127;;
+ esac
+done
+shift "$(( OPTIND -1 ))"
+
+[ "$VERB" -eq 1 ]&&printf "[....] Starting SSH agent.\\033[s"
+ROEDGROED="$(pgrep -U "$(whoami)" ssh-agent|grep -v grep|awk '{print $1}')"
+
+if [ -n "$ROEDGROED" ];then
+ if [ "$KILLIT" -eq 1 ];then
+ for i in $(echo "$ROEDGROED");do kill "$i" >/dev/null 2>&1||break;done
+ case "$?" in
+ 0);;
+ *)
+ [ "$VERB" -eq 1 ]&&printf "\\033[666D[\\033[31mFAIL\\033[0m]\\033[u\\033[K\\n"
+ exit 2
+ ;;
+ esac
+ else
+ [ "$VERB" -eq 1 ]&&printf "\\033[666D[\\033[30;1mSKIP\\033[0m]\\033[u\\033[K (running, PID: %s)\\n" "$ROEDGROED"
+ exit 0
+ fi
+fi
+ssh-agent >"$SSHENVFILE" 2>&1&&chmod 0600 "$SSHENVFILE" >/dev/null 2>&1
+case "$?" in
+ 0)
+ sed -i 's/^echo[^\;]*\;//g' "$SSHENVFILE" >/dev/null 2>&1
+ [ "$VERB" -eq 1 ]&&printf "\\033[666D[\\033[32m OK \\033[0m]\\033[u\\033[K\\n"
+ exit 0
+ ;;
+ *)
+ [ "$VERB" -eq 1 ]&&printf "\\033[666D[\\033[31mFAIL\\033[0m]\\033[u\\033[K\\n"
+ exit 1
+ ;;
+esac