From ec6b662bc499aeb11ca0fcda26840664f2c47add Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 12 Aug 2019 02:25:03 +0300 Subject: pull.sh: refactoring --- pull.sh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'pull.sh') diff --git a/pull.sh b/pull.sh index 4313d66..9bde02e 100755 --- a/pull.sh +++ b/pull.sh @@ -6,6 +6,23 @@ script_dir="$( dirname -- "${BASH_SOURCE[0]}" )" script_dir="$( cd -- "$script_dir" && pwd )" readonly script_dir +dump() { + local prefix="${FUNCNAME[0]}" + [ "${#FUNCNAME[@]}" -gt 1 ] && prefix="${FUNCNAME[1]}" + + local msg + for msg; do + echo "$prefix: $msg" + done +} + +check_ssh_agent_running() { + if [ -z "${SSH_AUTH_SOCK+x}" ]; then + dump "SSH_AUTH_SOCK isn't defined (ssh-agent not running?)" >&2 + return 1 + fi +} + add_ssh_key() { local password_path="$script_dir/password.txt" local password @@ -30,9 +47,10 @@ add_ssh_key() { DISPLAY="${DISPLAY-x}" SSH_ASKPASS="$askpass_path" ssh-add "$key_path" < /dev/null } -if [ -z "${SSH_AUTH_SOCK+x}" ]; then - echo "SSH_AUTH_SOCK isn't defined (ssh-agent not running?)" >&2 - exit 1 -fi -add_ssh_key -python3 -m pull.main "$@" +main() { + check_ssh_agent_running + add_ssh_key + python3 -m pull.main "$@" +} + +main "$@" -- cgit v1.2.3