Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

sitegen.sh 1.4KB

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