Guest User

Untitled

a guest
Nov 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. contains_word() {
  2. word=${1:?"target word required"}
  3. shift
  4. for elem in "${@}"; do
  5. if [ "${word}" = "${elem}" ]; then
  6. unset elem
  7. unset word
  8. return 0
  9. fi
  10. done
  11. unset elem
  12. unset word
  13. return 1
  14. }
  15.  
  16. prog_name() {
  17. name=${1:?"Program name required"}
  18. name=$(basename -- ${name})
  19. if [ "-" = "$(printf %.1s "${name}")" ]; then
  20. name=${name#?}
  21. fi
  22. echo "${name}"
  23. unset name
  24. }
  25.  
  26. # If ssh-agent is not available to the login shell, exec a new ssh-agent
  27. # with a new login shell as its subshell. Whitelist known good shell
  28. # names, because Xsession also runs .profile and dies if it's run as a
  29. # subshell of ssh-agent. (Xsession has its own mechanism for getting an
  30. # ssh-agent running.)
  31. if [ -n "$(which ssh-agent)" ]; then
  32. ssh-add -l >/dev/null 2>&1
  33. if [ ${?} -eq 2 ]; then
  34. if contains_word $(prog_name ${0}) bash dash ksh sh; then
  35. exec ssh-agent $(prog_name ${0}) -l
  36. fi
  37. fi
  38. fi
Add Comment
Please, Sign In to add comment