| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							| 
									
										
										
										
											2020-01-27 19:08:40 +01:00
										 |  |  | # SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							| 
									
										
										
										
											2021-06-29 19:01:07 +02:00
										 |  |  | # shellcheck disable=SC2001 | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # shellcheck source=utils/lib.sh | 
					
						
							|  |  |  | source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | # config | 
					
						
							|  |  |  | # ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-30 16:13:47 +02:00
										 |  |  | PUBLIC_URL="${PUBLIC_URL:-${SEARXNG_URL}}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | FILTRON_ETC="/etc/filtron" | 
					
						
							| 
									
										
										
										
											2020-01-09 16:25:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | SERVICE_NAME="filtron" | 
					
						
							| 
									
										
										
										
											2020-02-02 18:14:10 +01:00
										 |  |  | SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}" | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-16 16:30:18 +02:00
										 |  |  | APACHE_FILTRON_SITE="searx.conf" | 
					
						
							|  |  |  | NGINX_FILTRON_SITE="searx.conf" | 
					
						
							| 
									
										
										
										
											2020-01-09 16:25:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | # ---------------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2020-01-20 19:08:56 +01:00
										 |  |  | usage() { | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | # ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # shellcheck disable=SC1117 | 
					
						
							|  |  |  |     cat <<EOF | 
					
						
							| 
									
										
										
										
											2020-02-02 18:14:10 +01:00
										 |  |  | usage:: | 
					
						
							| 
									
										
										
										
											2022-07-30 16:13:47 +02:00
										 |  |  |   $(basename "$0") remove all | 
					
						
							| 
									
										
										
										
											2022-06-16 16:30:18 +02:00
										 |  |  |   $(basename "$0") apache remove | 
					
						
							|  |  |  |   $(basename "$0") nginx  remove | 
					
						
							| 
									
										
										
										
											2020-01-29 20:00:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-16 16:30:18 +02:00
										 |  |  | remove all     : drop all components of the filtron service | 
					
						
							|  |  |  | apache remove  : drop apache site ${APACHE_FILTRON_SITE} | 
					
						
							|  |  |  | nginx  remove  : drop nginx site ${NGINX_FILTRON_SITE} | 
					
						
							| 
									
										
										
										
											2022-07-30 16:13:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | environment: | 
					
						
							|  |  |  |   PUBLIC_URL   : ${PUBLIC_URL} | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | EOF | 
					
						
							| 
									
										
										
										
											2021-06-29 19:01:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-16 20:07:37 +01:00
										 |  |  |     [[ -n ${1} ]] &&  err_msg "$1" | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 19:08:56 +01:00
										 |  |  | main() { | 
					
						
							| 
									
										
										
										
											2020-02-04 17:59:58 +01:00
										 |  |  |     local _usage="unknown or missing $1 command $2" | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     case $1 in | 
					
						
							| 
									
										
										
										
											2020-01-11 12:50:40 +01:00
										 |  |  |         -h|--help) usage; exit 0;; | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  |         remove) | 
					
						
							|  |  |  |             sudo_or_exit | 
					
						
							|  |  |  |             case $2 in | 
					
						
							|  |  |  |                 all) remove_all;; | 
					
						
							|  |  |  |                 *) usage "$_usage"; exit 42;; | 
					
						
							|  |  |  |             esac ;; | 
					
						
							| 
									
										
										
										
											2020-01-29 20:00:50 +01:00
										 |  |  |         apache) | 
					
						
							|  |  |  |             sudo_or_exit | 
					
						
							|  |  |  |             case $2 in | 
					
						
							|  |  |  |                 remove) remove_apache_site ;; | 
					
						
							|  |  |  |                 *) usage "$_usage"; exit 42;; | 
					
						
							|  |  |  |             esac ;; | 
					
						
							| 
									
										
										
										
											2020-04-11 13:19:11 +02:00
										 |  |  |         nginx) | 
					
						
							|  |  |  |             sudo_or_exit | 
					
						
							|  |  |  |             case $2 in | 
					
						
							|  |  |  |                 remove) remove_nginx_site ;; | 
					
						
							|  |  |  |                 *) usage "$_usage"; exit 42;; | 
					
						
							|  |  |  |             esac ;; | 
					
						
							| 
									
										
										
										
											2020-02-04 17:59:58 +01:00
										 |  |  |         *) usage "unknown or missing command $1"; exit 42;; | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  |     esac | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | remove_all() { | 
					
						
							|  |  |  |     rst_title "De-Install $SERVICE_NAME (service)" | 
					
						
							| 
									
										
										
										
											2020-01-29 20:00:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     rst_para "\
 | 
					
						
							|  |  |  | It goes without saying that this script can only be used to remove | 
					
						
							|  |  |  | installations that were installed with this script."
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 18:14:10 +01:00
										 |  |  |     if ! systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then | 
					
						
							|  |  |  |         return 42 | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2020-02-01 16:59:27 +01:00
										 |  |  |     drop_service_account "${SERVICE_USER}" | 
					
						
							| 
									
										
										
										
											2020-01-09 16:25:05 +01:00
										 |  |  |     rm -r "$FILTRON_ETC" 2>&1 | prefix_stdout | 
					
						
							| 
									
										
										
										
											2020-01-30 19:55:51 +01:00
										 |  |  |     if service_is_available "${PUBLIC_URL}"; then | 
					
						
							|  |  |  |         MSG="** Don't forget to remove your public site! (${PUBLIC_URL}) **" wait_key 10 | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 20:00:50 +01:00
										 |  |  | remove_apache_site() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rst_title "Remove Apache site $APACHE_FILTRON_SITE" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rst_para "\
 | 
					
						
							|  |  |  | This removes apache site ${APACHE_FILTRON_SITE}."
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ! apache_is_installed && err_msg "Apache is not installed." | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 18:38:36 +02:00
										 |  |  |     if ! ask_yn "Do you really want to continue?" Yn; then | 
					
						
							| 
									
										
										
										
											2020-01-29 20:00:50 +01:00
										 |  |  |         return | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     apache_remove_site "$APACHE_FILTRON_SITE" | 
					
						
							| 
									
										
										
										
											2020-04-08 18:38:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 19:08:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-11 13:19:11 +02:00
										 |  |  | remove_nginx_site() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rst_title "Remove nginx site $NGINX_FILTRON_SITE" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rst_para "\
 | 
					
						
							|  |  |  | This removes nginx site ${NGINX_FILTRON_SITE}."
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ! nginx_is_installed && err_msg "nginx is not installed." | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ! ask_yn "Do you really want to continue?" Yn; then | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-16 16:30:18 +02:00
										 |  |  |     nginx_remove_app "$FILTRON_FILTRON_SITE" | 
					
						
							| 
									
										
										
										
											2020-04-03 20:24:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-08 19:21:07 +01:00
										 |  |  | # ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | main "$@" | 
					
						
							|  |  |  | # ---------------------------------------------------------------------------- |