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

set -eux

LOG_DIR=/var/log/mullvad-vpn
INSTALL_DIR=$2

mkdir -p $LOG_DIR
chmod 755 $LOG_DIR
exec 2>&1 > $LOG_DIR/preinstall.log

echo "Running preinstall at $(date)"

# We need to run this is after extracting the new files and running "mullvad" in postinstall rather
# than in preinstall.
cp "$INSTALL_DIR/Mullvad VPN.app/Contents/Resources/mullvad-setup" "$TMPDIR/" || echo "Failed to copy mullvad-setup"

# Migrate cache files from <=2020.8-beta2 paths
OLD_CACHE_DIR="/var/root/Library/Caches/mullvad-vpn"
NEW_CACHE_DIR="/Library/Caches/mullvad-vpn"

if [ -d "$OLD_CACHE_DIR" ]; then
    echo "Found old cache dir at $OLD_CACHE_DIR, moving to $NEW_CACHE_DIR"
    mkdir -p "$NEW_CACHE_DIR"
    mv "$OLD_CACHE_DIR"/* "$NEW_CACHE_DIR/" || echo "Unable to migrate cache. No cache files?"
    rm -rf "$OLD_CACHE_DIR"
fi

# Remove the existing relay and API address cache lists.
# There is a risk that they're incompatible with the format this version wants
rm "$NEW_CACHE_DIR/relays.json" || true
rm "$NEW_CACHE_DIR/api-ip-address.txt" || true

# Remove deprecated exclusion group. This line can be removed when 2023.4 is no longer supported
dscl . -delete /groups/mullvad-exclusion &>/dev/null || true

# Kill the GUI before proceeding with the upgrade.
#
# When we drop support for all app versions older than 2022.5, we can skip this
# check and always try to kill the GUI.
if "$INSTALL_DIR/Mullvad VPN.app/Contents/Resources/mullvad-setup" is-older-version 2022.5; then
    pkill -x "Mullvad VPN" || echo "Unable to kill GUI, not running?"
    sleep 1
fi