aboutsummaryrefslogtreecommitdiff
path: root/windscribe-openrc.install
blob: 37ade1461e41c4dfff6d9ad628812d028d27afc2 (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
pre_install() {
    # Stop any running instance before upgrade/reinstall
    rc-service windscribe-helper stop >/dev/null 2>&1 || true

    # If migrating from a systemd-based install, disable the old systemd unit
    if command -v systemctl >/dev/null 2>&1; then
        systemctl stop windscribe-helper >/dev/null 2>&1 || true
        systemctl disable windscribe-helper >/dev/null 2>&1 || true
    fi
}

post_install() {
    # Ensure windscribe user/group exist
    getent group windscribe >/dev/null 2>&1 || groupadd windscribe
    id -u windscribe >/dev/null 2>&1 || useradd -r -g windscribe -s /bin/false windscribe

    # Add helper to default runlevel and start it
    rc-update add windscribe-helper default >/dev/null 2>&1 || true
    rc-service windscribe-helper start >/dev/null 2>&1 || true

    # Symlink CLI binary into PATH
    ln -sf /opt/windscribe/windscribe-cli /usr/bin/windscribe-cli

    # Desktop database
    update-desktop-database || true

    # Set setgid on Windscribe GUI binary so it can talk to helper
    chgrp windscribe /opt/windscribe/Windscribe && chmod 2755 /opt/windscribe/Windscribe

    # Platform marker
    mkdir -p /etc/windscribe
    echo linux_zst_x64 > /etc/windscribe/platform

    # Add shim to PATH only if no real systemctl exists (don't shadow systemd)
    if ! command -v systemctl >/dev/null 2>&1 && [ ! -e /usr/local/bin/systemctl ]; then
        ln -sf /opt/windscribe/systemctl /usr/local/bin/systemctl
    fi
}

pre_upgrade() {
    rc-service windscribe-helper stop >/dev/null 2>&1 || true
    rc-update del windscribe-helper default >/dev/null 2>&1 || true
}

post_upgrade() {
    post_install
    rm -rf /etc/windscribe/stunnel.conf /etc/windscribe/config.ovpn /etc/windscribe/windscribe_servers
}

pre_remove() {
    # Kill GUI
    killall -q Windscribe || true

    # Stop and remove helper from runlevel
    rc-service windscribe-helper stop >/dev/null 2>&1 || true
    rc-update del windscribe-helper default >/dev/null 2>&1 || true

    # Reset MAC addresses
    if [ -x /opt/windscribe/helper ]; then
        /opt/windscribe/helper --reset-mac-addresses >/dev/null 2>&1 || true
    fi

    # Remove user/group
    userdel -f windscribe >/dev/null 2>&1 || true
    groupdel -f windscribe >/dev/null 2>&1 || true

    # Cleanup
    rm -rf /etc/windscribe
    rm -rf /var/log/windscribe
    rm -rf /var/lib/windscribe
    rm -f /usr/bin/windscribe-cli

    # Remove shim symlink if it points to our shim
    if [ -L /usr/local/bin/systemctl ] && [ "$(readlink /usr/local/bin/systemctl)" = "/opt/windscribe/systemctl" ]; then
        rm -f /usr/local/bin/systemctl
    fi
}