execute_lfirewall_dir 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. if [ -z ${verbose:-} ]
  16. then
  17. verbose=0
  18. fi
  19. while :
  20. do
  21. if [ ${verbose} = "1" ] ; then
  22. echo "$@"
  23. fi
  24. case "$1" in
  25. -f|--firewall-action)
  26. firewall_action=yes
  27. ;;
  28. -v|--verbose)
  29. verbose=$(( verbose + 1 ))
  30. if [ ${verbose} -gt 1 ] ; then
  31. set -x
  32. fi
  33. if [ ${verbose} -gt 2 ] ; then
  34. set -v
  35. fi
  36. ;;
  37. --)
  38. shift
  39. break
  40. ;;
  41. esac
  42. shift
  43. done
  44. do_log=do_not_log_action
  45. if [ ${verbose} -gt 0 ] ; then
  46. do_log=log_action
  47. fi
  48. export do_log
  49. export do_action=${1:-}
  50. script_dir=${2:-}
  51. shift 2 # clean any arguments
  52. if [ -z "${do_action}" ] ; then
  53. echo "ERROR: missing action" >&2
  54. exit 2
  55. fi
  56. if [ -z "${script_dir}" ] ; then
  57. echo "ERROR: missing script directory" >&2
  58. exit 2
  59. fi
  60. if [ ${do_action} = "do_delete" ] && [ ${firewall_action} = "yes" ]
  61. then
  62. # We do nothing in that specific case
  63. # (post-up-down)
  64. # just leave the script
  65. # because we let post-down directive
  66. # from /etc/network/interfaces
  67. # do the job
  68. exit
  69. fi
  70. cd ${script_dir}
  71. for script_file in `ls`
  72. do
  73. if [ -x ${script_file} ]
  74. then
  75. # If file is executable
  76. # we SOURCE it (because exporting function
  77. # can't be done in sh)
  78. set +eu # Just to avoid that a bad script crashes all others
  79. . ${script_dir}/${script_file} \
  80. || echo "ERROR in ${script_dir}/${script_file}" >&2
  81. set -eu
  82. fi
  83. done
  84. cd - > /dev/null