morty.sh 3.2 KB

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