diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2019-08-12 02:25:03 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2019-08-12 02:25:03 +0300 |
commit | ec6b662bc499aeb11ca0fcda26840664f2c47add (patch) | |
tree | 88472926533b0941c5caf5398970bf98e24ba4f0 /pull | |
parent | more robust ssh calls (diff) | |
download | cgitize-ec6b662bc499aeb11ca0fcda26840664f2c47add.tar.gz cgitize-ec6b662bc499aeb11ca0fcda26840664f2c47add.zip |
pull.sh: refactoring
Diffstat (limited to '')
-rwxr-xr-x | pull.sh | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -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 "$@" |