summaryrefslogtreecommitdiffhomepage
path: root/dist-assets/uninstall_macos.sh
blob: 0983ee43ae944d51ceb4b7b696613f5bc2d1d63c (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
#!/usr/bin/env bash

set -ue

ASSUMEYES="n"

while [[ "$#" -gt 0 ]]; do
    case $1 in
        --yes) ASSUMEYES="y";;
        *)
            echo "Unknown parameter: $1"
            exit 1
            ;;
    esac
    shift
done

[[ $ASSUMEYES == "y" ]] || read -r -p "Are you sure you want to stop and uninstall Mullvad VPN? (y/n) "
if [[ $ASSUMEYES == "y" || "$REPLY" =~ [Yy]$ ]]; then
    echo "Uninstalling Mullvad VPN ..."
else
    echo "Aborting uninstall"
    exit 0
fi

echo "Stopping GUI process ..."
sudo pkill -x "Mullvad VPN" || echo "No GUI process found"

echo "Stopping and unloading mullvad-daemon system daemon ..."
DAEMON_PLIST_PATH="/Library/LaunchDaemons/net.mullvad.daemon.plist"
sudo launchctl unload -w "$DAEMON_PLIST_PATH"
sudo rm -f "$DAEMON_PLIST_PATH"

echo "Resetting firewall"
sudo /Applications/Mullvad\ VPN.app/Contents/Resources/mullvad-setup reset-firewall || echo "Failed to reset firewall"
sudo /Applications/Mullvad\ VPN.app/Contents/Resources/mullvad-setup remove-device || echo "Failed to remove device from account"

echo "Removing zsh shell completion symlink ..."
sudo rm -f /usr/local/share/zsh/site-functions/_mullvad

echo "Removing fish shell completion symlink ..."

sudo rm -f "/opt/homebrew/share/fish/vendor_completions.d/mullvad.fish"
sudo rm -f "/usr/local/share/fish/vendor_completions.d/mullvad.fish"

echo "Removing CLI symlinks from /usr/local/bin/ ..."
sudo rm -f /usr/local/bin/mullvad /usr/local/bin/mullvad-problem-report

echo "Removing app from /Applications ..."
sudo rm -rf /Applications/Mullvad\ VPN.app
sudo pkgutil --forget net.mullvad.vpn || true

echo "Removing login item ..."
osascript -e 'tell application "System Events" to delete login item "Mullvad VPN"' 2>/dev/null || true

[[ $ASSUMEYES == "y" ]] || read -r -p "Do you want to delete the log and cache files the app has created? (y/n) "
if [[ $ASSUMEYES == "y" || "$REPLY" =~ [Yy]$ ]]; then
    sudo rm -rf /var/log/mullvad-vpn /var/root/Library/Caches/mullvad-vpn /Library/Caches/mullvad-vpn
    for user in /Users/*; do
        user_log_dir="$user/Library/Logs/Mullvad VPN"
        if [[ -d "$user_log_dir" ]]; then
            echo "Deleting GUI logs at $user_log_dir"
            sudo rm -rf "$user_log_dir"
        fi
    done
fi

[[ $ASSUMEYES == "y" ]] || read -r -p "Do you want to delete the Mullvad VPN settings? (y/n) "
if [[ $ASSUMEYES == "y" || "$REPLY" =~ [Yy]$ ]]; then
    sudo rm -rf /etc/mullvad-vpn
    for user in /Users/*; do
        user_settings_dir="$user/Library/Application Support/Mullvad VPN"
        if [[ -d "$user_settings_dir" ]]; then
            echo "Deleting GUI settings at $user_settings_dir"
            sudo rm -rf "$user_settings_dir"
        fi
    done
fi

# When run from a non-standard directory, like when detecting that the app bundle is gone,
# we must also delete the uninstall script itself
rm -f "$0" || true