You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sitegen.sh 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #! /usr/bin/env sh
  2. apache_dir=/etc/apache2/sites-available/
  3. conf_dir=/etc/sitegen/
  4. site_dir=/var/
  5. hooks_dir=/etc/sitegen/hooks.d/
  6. hooks_dir_local=~/.sitegen/hooks.d/
  7. makeDir()
  8. {
  9. mkdir -p "$1"
  10. if [ $? -ne 0 ]
  11. then
  12. exit 4
  13. fi
  14. }
  15. getPath()
  16. {
  17. readlink -m "$1"
  18. }
  19. applyHooks()
  20. {
  21. dir="$1"
  22. if [ -d ${dir} ]
  23. then
  24. for file in $(find ${dir} | sort) ;
  25. do
  26. echo "Applying ${file}"
  27. . "${file}"
  28. done
  29. else
  30. echo "No hooks found in ${dir}"
  31. fi
  32. }
  33. if [ $# -eq 0 ] || [ $# -gt 2 ] || [ "$1" = "--help" ]
  34. then
  35. echo "Usage:" $(basename $0) "hostname [config=default]" >&2
  36. exit 1
  37. fi
  38. host="$1"
  39. if [ $# -eq 2 ]
  40. then
  41. conf="$2"
  42. else
  43. conf="default"
  44. fi
  45. conf_conf=$(getPath "${conf_dir}/${conf}.conf")
  46. conf_include=$(getPath "${conf_dir}/${conf}.include")
  47. site_conf=$(getPath "${apache_dir}/${host}.conf")
  48. site_include=$(getPath "${apache_dir}/${host}.include")
  49. root_dir=$(getPath "${site_dir}/${host}")
  50. sed_host="s:%%HOST%%:${host}:g"
  51. sed_root="s:%%ROOT%%:${root_dir}:g"
  52. if [ ! -f "${conf_conf}" ] || [ ! -f "${conf_include}" ]
  53. then
  54. echo "Configuration file ${conf_conf} and/or ${conf_include} error: No such file" >&2
  55. exit 2
  56. fi
  57. if [ -f "${site_conf}" ]
  58. then
  59. echo "Host already exists: ${site_conf}" >&2
  60. exit 3
  61. fi
  62. makeDir "${root_dir}"
  63. makeDir "${apache_dir}"
  64. sed -e "${sed_host}" -e "${sed_root}" "${conf_conf}" > "${site_conf}"
  65. sed -e "${sed_host}" -e "${sed_root}" "${conf_include}" > "${site_include}"
  66. applyHooks ${hooks_dir}
  67. applyHooks ${hooks_dir_local}