Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contains_word() {
- word=${1:?"target word required"}
- shift
- for elem in "${@}"; do
- if [ "${word}" = "${elem}" ]; then
- unset elem
- unset word
- return 0
- fi
- done
- unset elem
- unset word
- return 1
- }
- prog_name() {
- name=${1:?"Program name required"}
- name=$(basename -- ${name})
- if [ "-" = "$(printf %.1s "${name}")" ]; then
- name=${name#?}
- fi
- echo "${name}"
- unset name
- }
- # If ssh-agent is not available to the login shell, exec a new ssh-agent
- # with a new login shell as its subshell. Whitelist known good shell
- # names, because Xsession also runs .profile and dies if it's run as a
- # subshell of ssh-agent. (Xsession has its own mechanism for getting an
- # ssh-agent running.)
- if [ -n "$(which ssh-agent)" ]; then
- ssh-add -l >/dev/null 2>&1
- if [ ${?} -eq 2 ]; then
- if contains_word $(prog_name ${0}) bash dash ksh sh; then
- exec ssh-agent $(prog_name ${0}) -l
- fi
- fi
- fi
Add Comment
Please, Sign In to add comment