morty.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: AGPL-3.0-or-later
  3. # shellcheck source=utils/lib.sh
  4. source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
  5. # ----------------------------------------------------------------------------
  6. # config
  7. # ----------------------------------------------------------------------------
  8. MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}"
  9. PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty/}"
  10. PUBLIC_URL_MORTY="${PUBLIC_URL_MORTY:-$(echo "$PUBLIC_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}}"
  11. SERVICE_NAME="morty"
  12. SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
  13. SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
  14. # Apache Settings
  15. APACHE_MORTY_SITE="morty.conf"
  16. NGINX_MORTY_SITE="morty.conf"
  17. # ----------------------------------------------------------------------------
  18. usage() {
  19. # ----------------------------------------------------------------------------
  20. # shellcheck disable=SC1117
  21. cat <<EOF
  22. usage::
  23. $(basename "$0") remove all
  24. $(basename "$0") apache remove
  25. $(basename "$0") nginx remove
  26. remove all : drop all components of the morty service
  27. apache remove : drop apache site ${APACHE_MORTY_SITE}
  28. nginx remove : drop nginx site ${NGINX_MORTY_SITE}
  29. EOF
  30. [[ -n ${1} ]] && err_msg "$1"
  31. }
  32. main() {
  33. local _usage="ERROR: unknown or missing $1 command $2"
  34. case $1 in
  35. -h|--help) usage; exit 0;;
  36. remove)
  37. sudo_or_exit
  38. case $2 in
  39. all) remove_all;;
  40. *) usage "$_usage"; exit 42;;
  41. esac ;;
  42. apache)
  43. sudo_or_exit
  44. case $2 in
  45. remove) remove_apache_site ;;
  46. *) usage "$_usage"; exit 42;;
  47. esac ;;
  48. nginx)
  49. sudo_or_exit
  50. case $2 in
  51. remove) remove_nginx_site ;;
  52. *) usage "$_usage"; exit 42;;
  53. esac ;;
  54. *) usage "ERROR: unknown or missing command $1"; exit 42;;
  55. esac
  56. }
  57. remove_all() {
  58. rst_title "De-Install $SERVICE_NAME (service)"
  59. rst_para "\
  60. It goes without saying that this script can only be used to remove
  61. installations that were installed with this script."
  62. if systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then
  63. drop_service_account "${SERVICE_USER}"
  64. fi
  65. }
  66. remove_apache_site() {
  67. rst_title "Remove Apache site $APACHE_MORTY_SITE"
  68. rst_para "\
  69. This removes apache site ${APACHE_MORTY_SITE}."
  70. ! apache_is_installed && err_msg "Apache is not installed."
  71. if ! ask_yn "Do you really want to continue?" Yn; then
  72. return
  73. fi
  74. apache_remove_site "$APACHE_MORTY_SITE"
  75. }
  76. remove_nginx_site() {
  77. rst_title "Remove nginx site $NGINX_MORTY_SITE"
  78. rst_para "\
  79. This removes nginx site ${NGINX_MORTY_SITE}."
  80. ! nginx_is_installed && err_msg "nginx is not installed."
  81. if ! ask_yn "Do you really want to continue?" Yn; then
  82. return
  83. fi
  84. nginx_remove_app "$NGINX_MORTY_SITE"
  85. }
  86. # ----------------------------------------------------------------------------
  87. main "$@"
  88. # ----------------------------------------------------------------------------