summaryrefslogtreecommitdiff
path: root/utils/searx.sh
blob: 719cd2031307a64ba8244f3fdf29bbe6885dae35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
# shellcheck disable=SC2001

# shellcheck source=utils/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
# shellcheck source=utils/brand.env
source "${REPO_ROOT}/utils/brand.env"

# ----------------------------------------------------------------------------
# config
# ----------------------------------------------------------------------------

PUBLIC_URL="${PUBLIC_URL:-${SEARXNG_URL}}"

SERVICE_NAME="searx"
SERVICE_USER="${SERVICE_USER:-${SERVICE_NAME}}"
SEARXNG_SETTINGS_PATH="/etc/searx/settings.yml"
SEARXNG_UWSGI_APP="searx.ini"

# ----------------------------------------------------------------------------
usage() {
# ----------------------------------------------------------------------------

    # shellcheck disable=SC1117
    cat <<EOF
usage::
  $(basename "$0") remove     all

remove all:    complete uninstall of SearXNG service

environment:
  PUBLIC_URL   : ${PUBLIC_URL}
EOF

    [[ -n ${1} ]] &&  err_msg "$1"
}

main() {

    local _usage="unknown or missing $1 command $2"

    case $1 in
        remove)
            rst_title "SearXNG (remove)" part
            sudo_or_exit
            case $2 in
                all) remove_all;;
                *) usage "$_usage"; exit 42;;
            esac ;;
        *) usage "unknown or missing command $1"; exit 42;;
    esac
}

remove_all() {
    rst_title "De-Install SearXNG (service)"

    rst_para "\
It goes without saying that this script can only be used to remove
installations that were installed with this script."

    if ! ask_yn "Do you really want to deinstall SearXNG?"; then
        return
    fi
    remove_searx_uwsgi
    drop_service_account "${SERVICE_USER}"
    remove_settings
    wait_key
    if service_is_available "${PUBLIC_URL}"; then
        MSG="** Don't forget to remove your public site! (${PUBLIC_URL}) **" wait_key 10
    fi
}

remove_settings() {
    rst_title "remove SearXNG settings" section
    echo
    info_msg "delete ${SEARXNG_SETTINGS_PATH}"
    rm -f "${SEARXNG_SETTINGS_PATH}"
}

remove_searx_uwsgi() {
    rst_title "Remove SearXNG's uWSGI app (searxng.ini)" section
    echo
    uWSGI_remove_app "$SEARXNG_UWSGI_APP"
}


# ----------------------------------------------------------------------------
main "$@"
# ----------------------------------------------------------------------------