File size: 1,594 Bytes
dfb775d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# (c) 2026 BANKON — all rights reserved.
#
# Uninstall WordPress.agent from a VPS.
# Removes the service unit, install dir, and (with --purge) the env file and user.
#
# Usage:
#   sudo bash scripts/uninstall.sh           # leave env + user
#   sudo bash scripts/uninstall.sh --purge   # remove everything

set -euo pipefail

INSTALL_DIR="/opt/wordpress-agent"
ENV_DIR="/etc/wordpress-agent"
SERVICE_USER="wpagent"
SERVICE_GROUP="wpagent"
PURGE=0

for arg in "$@"; do
    case "${arg}" in
        --purge) PURGE=1 ;;
        *) echo "Unknown arg: ${arg}" >&2; exit 1 ;;
    esac
done

require_root() {
    if [[ "${EUID}" -ne 0 ]]; then
        echo "ERROR: must run as root" >&2
        exit 1
    fi
}

stop_service() {
    if systemctl list-unit-files | grep -q '^wordpress-agent.service'; then
        systemctl disable --now wordpress-agent.service || true
        rm -f /etc/systemd/system/wordpress-agent.service
        systemctl daemon-reload
    fi
}

remove_files() {
    rm -rf "${INSTALL_DIR}"
    if [[ "${PURGE}" -eq 1 ]]; then
        rm -rf "${ENV_DIR}"
        if id "${SERVICE_USER}" >/dev/null 2>&1; then
            userdel "${SERVICE_USER}" || true
        fi
        if getent group "${SERVICE_GROUP}" >/dev/null; then
            groupdel "${SERVICE_GROUP}" || true
        fi
    fi
}

main() {
    require_root
    stop_service
    remove_files
    echo "WordPress.agent uninstalled."
    if [[ "${PURGE}" -eq 0 ]]; then
        echo "Note: ${ENV_DIR} preserved. Pass --purge to remove."
    fi
}

main "$@"