filtron.sh 3.2 KB

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