summaryrefslogtreecommitdiffhomepage
path: root/dist-assets/pkg-scripts/postinstall
blob: e213c73b62c86c83913c6017bdd457a8921827b8 (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
#!/usr/bin/env bash

set -eu

LOG_DIR=/var/log/mullvad-vpn

mkdir -p $LOG_DIR
exec 2>&1 > $LOG_DIR/postinstall.log

echo "Running postinstall at $(date)"

INSTALL_DIR=$2
DAEMON_PLIST_PATH="/Library/LaunchDaemons/net.mullvad.daemon.plist"

DAEMON_PLIST=$(cat <<-EOM
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
        <dict>
                <key>Label</key>
                <string>net.mullvad.daemon</string>

                <key>ProgramArguments</key>
                <array>
                        <string>$INSTALL_DIR/Mullvad VPN.app/Contents/Resources/mullvad-daemon</string>
                        <string>-v</string>
                </array>

                <key>UserName</key>
                <string>root</string>

                <key>RunAtLoad</key>
                <true/>

                <key>KeepAlive</key>
                <true/>

                <key>StandardErrorPath</key>
                <string>$LOG_DIR/stderr.log</string>
        </dict>
</plist>
EOM
)

pkill -x "Mullvad VPN" || echo "Unable to kill GUI, not running?"
sleep 1
launchctl unload -w $DAEMON_PLIST_PATH
echo "$DAEMON_PLIST" > $DAEMON_PLIST_PATH
launchctl load -w $DAEMON_PLIST_PATH