morty.sh 3.3 KB

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