openconnect-wrapper 488 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. # This script wraps openconnect in order to obtain the password
  3. # file from cmd.
  4. # $1 password file
  5. # $2... are passed to openconnect
  6. test -z "$1" && exit 1
  7. pwfile=$1
  8. shift
  9. pidfile=/var/run/ocwrap-$$.pid
  10. cleanup()
  11. {
  12. if ! test -z "$pid";then
  13. kill $pid
  14. wait $pid
  15. fi
  16. exit 0
  17. }
  18. cleanup2()
  19. {
  20. if ! test -z "$pid";then
  21. kill -2 $pid
  22. wait $pid
  23. fi
  24. exit 0
  25. }
  26. trap cleanup2 2
  27. trap cleanup 1 3 6 15
  28. rm -f "$pidfile"
  29. /usr/sbin/openconnect $* <$pwfile &
  30. pid=$!
  31. wait $pid