execute_dir 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. if [ -z "${CONFIGURATION_DIR:-}" ]
  3. then
  4. CONFIGURATION_DIR=/etc/lfirewall
  5. . ${CONFIGURATION_DIR}/setup
  6. fi
  7. options=$(getopt -l "firewall-action,verbose" -o "fv" -- "$@")
  8. if [ $? != 0 ] ; then
  9. echo "Error while checking options ($0)">&2
  10. exit 1
  11. fi
  12. eval set -- "$options"
  13. set -eu
  14. firewall_action=no
  15. verbose=0
  16. while :
  17. do
  18. if [ ${verbose} = "1" ] ; then
  19. echo "$@"
  20. fi
  21. case "$1" in
  22. -f|--firewall-action)
  23. firewall_action=yes
  24. ;;
  25. -v|--verbose)
  26. verbose=$(( verbose + 1 ))
  27. if [ ${verbose} -gt 1 ] ; then
  28. set -x
  29. fi
  30. if [ ${verbose} -gt 2 ] ; then
  31. set -v
  32. fi
  33. ;;
  34. --)
  35. shift
  36. break
  37. ;;
  38. esac
  39. shift
  40. done
  41. do_action=${1:-}
  42. script_dir=${2:-}
  43. if [ -z "${do_action}" ] ; then
  44. echo "ERROR: missing action" > &2
  45. exit 2
  46. fi
  47. if [ -z "${script_dir}" ] ; then
  48. echo "ERROR: missing script directory" > &2
  49. exit 2
  50. fi
  51. if [ ${do_action} = "do_delete" && ${firewall_action} = "yes" ]
  52. then
  53. # We do nothing in that specific case
  54. # (post-up-down)
  55. # just leave the script
  56. # because we let post-down directive
  57. # from /etc/network/interfaces
  58. # do the job
  59. exit
  60. fi
  61. cd ${script_dir}
  62. for script_file in $(ls)
  63. do
  64. if [ -x ${scritp_file} ]
  65. then
  66. # If file is executable
  67. ./${scritp_file} ${do_action}
  68. fi
  69. done
  70. cd -