2020-02-02 18:14:10 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
# 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-04-08 18:38:36 +02:00
|
|
|
MORTY_LISTEN="${MORTY_LISTEN:-127.0.0.1:3000}"
|
2020-04-09 14:28:34 +02:00
|
|
|
PUBLIC_URL_PATH_MORTY="${PUBLIC_URL_PATH_MORTY:-/morty/}"
|
2021-06-13 11:55:32 +02:00
|
|
|
PUBLIC_URL_MORTY="${PUBLIC_URL_MORTY:-$(echo "$PUBLIC_URL" | sed -e's,^\(.*://[^/]*\).*,\1,g')${PUBLIC_URL_PATH_MORTY}}"
|
2020-04-08 18:38:36 +02:00
|
|
|
|
2020-02-02 18:14:10 +01:00
|
|
|
SERVICE_NAME="morty"
|
|
|
|
SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
|
|
|
|
SERVICE_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${SERVICE_NAME}.service"
|
|
|
|
|
|
|
|
# Apache Settings
|
|
|
|
|
|
|
|
APACHE_MORTY_SITE="morty.conf"
|
2020-04-11 13:19:11 +02:00
|
|
|
NGINX_MORTY_SITE="morty.conf"
|
2020-02-02 18:14:10 +01:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
usage() {
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# shellcheck disable=SC1117
|
|
|
|
cat <<EOF
|
|
|
|
usage::
|
2022-06-16 16:30:18 +02:00
|
|
|
$(basename "$0") remove all
|
|
|
|
$(basename "$0") apache remove
|
|
|
|
$(basename "$0") nginx remove
|
2020-02-02 18:14:10 +01:00
|
|
|
|
2022-06-16 16:30:18 +02:00
|
|
|
remove all : drop all components of the morty service
|
|
|
|
apache remove : drop apache site ${APACHE_MORTY_SITE}
|
|
|
|
nginx remove : drop nginx site ${NGINX_MORTY_SITE}
|
2022-07-30 16:13:47 +02:00
|
|
|
|
|
|
|
environment:
|
|
|
|
PUBLIC_URL_MORTY : ${PUBLIC_URL_MORTY}
|
2020-02-04 10:39:42 +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-02-04 10:39:42 +01:00
|
|
|
}
|
|
|
|
|
2020-02-02 18:14:10 +01:00
|
|
|
main() {
|
|
|
|
local _usage="ERROR: unknown or missing $1 command $2"
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
-h|--help) usage; exit 0;;
|
|
|
|
remove)
|
|
|
|
sudo_or_exit
|
|
|
|
case $2 in
|
|
|
|
all) remove_all;;
|
|
|
|
*) usage "$_usage"; exit 42;;
|
|
|
|
esac ;;
|
|
|
|
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-02 18:14:10 +01:00
|
|
|
*) usage "ERROR: unknown or missing command $1"; exit 42;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2021-10-29 17:40:37 +02:00
|
|
|
|
2020-02-02 18:14:10 +01:00
|
|
|
remove_all() {
|
|
|
|
rst_title "De-Install $SERVICE_NAME (service)"
|
|
|
|
|
|
|
|
rst_para "\
|
|
|
|
It goes without saying that this script can only be used to remove
|
|
|
|
installations that were installed with this script."
|
|
|
|
|
|
|
|
if systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"; then
|
|
|
|
drop_service_account "${SERVICE_USER}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
remove_apache_site() {
|
|
|
|
|
|
|
|
rst_title "Remove Apache site $APACHE_MORTY_SITE"
|
|
|
|
|
|
|
|
rst_para "\
|
|
|
|
This removes apache site ${APACHE_MORTY_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-02-02 18:14:10 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
apache_remove_site "$APACHE_MORTY_SITE"
|
|
|
|
}
|
2020-02-26 19:07:55 +01:00
|
|
|
|
2020-04-11 13:19:11 +02:00
|
|
|
remove_nginx_site() {
|
|
|
|
|
|
|
|
rst_title "Remove nginx site $NGINX_MORTY_SITE"
|
|
|
|
|
|
|
|
rst_para "\
|
|
|
|
This removes nginx site ${NGINX_MORTY_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 "$NGINX_MORTY_SITE"
|
2020-04-03 20:26:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-02 18:14:10 +01:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
main "$@"
|
|
|
|
# ----------------------------------------------------------------------------
|