filtron.sh 3.1 KB

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