filtron.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: AGPL-3.0-or-later
  3. # shellcheck disable=SC2001
  4. # shellcheck source=utils/lib.sh
  5. source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
  6. # shellcheck source=utils/brand.env
  7. source "${REPO_ROOT}/utils/brand.env"
  8. # ----------------------------------------------------------------------------
  9. # config
  10. # ----------------------------------------------------------------------------
  11. PUBLIC_URL="${PUBLIC_URL:-${SEARXNG_URL}}"
  12. FILTRON_ETC="/etc/filtron"
  13. SERVICE_NAME="filtron"
  14. SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
  15. SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
  16. APACHE_FILTRON_SITE="searx.conf"
  17. NGINX_FILTRON_SITE="searx.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 filtron service
  28. apache remove : drop apache site ${APACHE_FILTRON_SITE}
  29. nginx remove : drop nginx site ${NGINX_FILTRON_SITE}
  30. environment:
  31. PUBLIC_URL : ${PUBLIC_URL}
  32. EOF
  33. [[ -n ${1} ]] && err_msg "$1"
  34. }
  35. main() {
  36. local _usage="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 "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. return 42
  67. fi
  68. drop_service_account "${SERVICE_USER}"
  69. rm -r "$FILTRON_ETC" 2>&1 | prefix_stdout
  70. if service_is_available "${PUBLIC_URL}"; then
  71. MSG="** Don't forget to remove your public site! (${PUBLIC_URL}) **" wait_key 10
  72. fi
  73. }
  74. remove_apache_site() {
  75. rst_title "Remove Apache site $APACHE_FILTRON_SITE"
  76. rst_para "\
  77. This removes apache site ${APACHE_FILTRON_SITE}."
  78. ! apache_is_installed && err_msg "Apache is not installed."
  79. if ! ask_yn "Do you really want to continue?" Yn; then
  80. return
  81. fi
  82. apache_remove_site "$APACHE_FILTRON_SITE"
  83. }
  84. remove_nginx_site() {
  85. rst_title "Remove nginx site $NGINX_FILTRON_SITE"
  86. rst_para "\
  87. This removes nginx site ${NGINX_FILTRON_SITE}."
  88. ! nginx_is_installed && err_msg "nginx is not installed."
  89. if ! ask_yn "Do you really want to continue?" Yn; then
  90. return
  91. fi
  92. nginx_remove_app "$FILTRON_FILTRON_SITE"
  93. }
  94. # ----------------------------------------------------------------------------
  95. main "$@"
  96. # ----------------------------------------------------------------------------