aboutsummaryrefslogtreecommitdiff
path: root/systemctl-shim
blob: 1cb8c9bb79d46b09d8a8669a4c0dba62491e9914 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# systemctl shim for Windscribe on OpenRC systems
# Intercepts systemctl calls made by Windscribe binaries

# Parse flags
USER_FLAG=""
QUIET_FLAG=""
while [[ "$1" == --* ]]; do
    case "$1" in
        --quiet) QUIET_FLAG=1 ;;
        --user) USER_FLAG=1 ;;
    esac
    shift
done

cmd="$1"
shift || true

# Helper to suppress output if --quiet
output() {
    if [ -z "$QUIET_FLAG" ]; then
        echo "$@"
    fi
}

case "$cmd" in
    start)
        case "$1" in
            windscribe-helper)
                exec rc-service windscribe-helper start
                ;;
            windscribe)
                # CLI-only user service maps to system helper
                exec rc-service windscribe-helper start
                ;;
            systemd-resolved)
                exit 1
                ;;
            NetworkManager)
                exec rc-service NetworkManager start
                ;;
            *)
                output "systemctl shim: unknown service $1"
                exit 1
                ;;
        esac
        ;;
    stop)
        case "$1" in
            windscribe-helper|windscribe)
                exec rc-service windscribe-helper stop
                ;;
            NetworkManager)
                exec rc-service NetworkManager stop
                ;;
            *)
                exit 0
                ;;
        esac
        ;;
    restart)
        case "$1" in
            windscribe-helper)
                exec rc-service windscribe-helper restart
                ;;
            NetworkManager)
                exec rc-service NetworkManager restart
                ;;
            *)
                exit 0
                ;;
        esac
        ;;
    enable)
        case "$1" in
            windscribe-helper|windscribe)
                exec rc-update add windscribe-helper default
                ;;
            NetworkManager)
                exec rc-update add NetworkManager default
                ;;
            systemd-resolved)
                exit 1
                ;;
            *)
                exit 0
                ;;
        esac
        ;;
    disable)
        case "$1" in
            windscribe-helper|windscribe)
                exec rc-update del windscribe-helper default
                ;;
            *)
                exit 0
                ;;
        esac
        ;;
    daemon-reload)
        exit 0
        ;;
    is-active)
        if [ "$1" = "--quiet" ]; then
            shift
        fi
        case "$1" in
            systemd-resolved)
                exit 1
                ;;
            windscribe-helper|windscribe)
                rc-service windscribe-helper status >/dev/null 2>&1
                exit $?
                ;;
            NetworkManager)
                rc-service NetworkManager status >/dev/null 2>&1
                exit $?
                ;;
            *)
                exit 1
                ;;
        esac
        ;;
    status)
        case "$1" in
            windscribe-helper|windscribe)
                exec rc-service windscribe-helper status
                ;;
            NetworkManager)
                exec rc-service NetworkManager status
                ;;
            *)
                exit 1
                ;;
        esac
        ;;
    *)
        # Warn to stderr but return 0 so future Windscribe versions don't crash on new commands
        echo "systemctl shim: unsupported command $cmd $*" >&2
        exit 0
        ;;
esac