se.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bash
  2. # require line in /etc/sudoers:
  3. # _www ALL = NOPASSWD: /Library/Server/Web/Data/Sites/SE-production-git/sbin/se.sh
  4. # cat /etc/sudoers |grep "_www ALL = NOPASSWD: /Library/Server/Web/Data/Sites/SE-production-git/sbin/se.sh" || echo "_www ALL = NOPASSWD: /Library/Server/Web/Data/Sites/SE-production-git/sbin/se.sh" >> /etc/sudoers;
  5. set -e
  6. # set -e stops the execution of a script if a command or pipeline has an error
  7. function usage {
  8. echo "usage se.sh [--sudo] module_name"
  9. exit 1
  10. }
  11. [ -z "$1" ] && usage
  12. [ "$1" = "--sudo" ] && {
  13. [ -z "$2" ] && echo "Missing module name"
  14. [ -z "$2" ] && usage
  15. sudo ./se.sh "$2"
  16. exit 0
  17. }
  18. module_name="$1"
  19. echo "DBG: module_name: ${module_name}"
  20. [ ! -f "module/${module_name}.sh" ] && {
  21. echo "Module not exists" >&2
  22. usage
  23. }
  24. echo "DBG: starting module: [${module_name}]"
  25. /bin/bash module/${module_name}.sh "${@:2}"
  26. module_exit=$?
  27. echo "DBG: module exited with code [${module_exit}] - module: [${module_name}]"
  28. exit $module_exit
  29. # exit $? exit with same exit code what script