#!/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)" # Notify the running daemon that we are going to kill it and replace it with a newer version. "$INSTALL_DIR/Mullvad VPN.app/Contents/Resources/mullvad-setup" prepare-restart || \ echo "Failed to send 'prepare-restart' command to old mullvad-daemon" # 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 # Create a group for mullvad-exclusion MULLVAD_EXCLUSION_GROUP="mullvad-exclusion" if ! dscl . -list /Groups | grep $MULLVAD_EXCLUSION_GROUP; then dscl . -create /Groups/$MULLVAD_EXCLUSION_GROUP \ || echo "FAILED TO CREATE $MULLVAD_EXCLUSION_GROUP GROUP" fi if ! dscl . -read /Groups/$MULLVAD_EXCLUSION_GROUP | grep PrimaryGroupID; then MULLVAD_EXCLUSION_GID=$(( RANDOM )) dscl . -append /Groups/$MULLVAD_EXCLUSION_GROUP PrimaryGroupID $MULLVAD_EXCLUSION_GID \ && echo "Created mullvad-exclusion group with gid $MULLVAD_EXCLUSION_GID" \ || echo "FAILED TO CREATE 'mullvad-exclusion' group" fi