Skip to content

Instantly share code, notes, and snippets.

@xv-tom-l
Created August 25, 2015 08:22
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xv-tom-l/982469a99f3a6b7b92ae to your computer and use it in GitHub Desktop.
Save xv-tom-l/982469a99f3a6b7b92ae to your computer and use it in GitHub Desktop.
Uninstall script for ExpressVPN Mac 4.x
#!/usr/bin/env bash
#----------------------------------------------------------------------
# Functions
#----------------------------------------------------------------------
# Exits the script with the given exit code after waiting
# for a keypress.
#
# @param [Integer] $1 exit code.
function key_exit() {
echo "Press any key to exit."
read
exit $1
}
# Appends a value to an array.
#
# @param [String] $1 Name of the variable to modify
# @param [String] $2 Value to append
function append() {
eval $1[\${#$1[*]}]=$2
}
#----------------------------------------------------------------------
# Script
#----------------------------------------------------------------------
# Collect the directories and files to remove
my_files=()
append my_files "/Applications/ExpressVPN.app"
# 4.x files
append my_files "$HOME/Library/Application\ Support/com.expressvpn.ExpressVPN"
# 3.x files
append my_files "$HOME/Library/Application\ Support/ExpressVPN"
# staging files
append my_files "$HOME/Library/Application\ Support/com.expressvpn.ExpressVPN-staging"
# preferences
append my_files "$HOME/Library/Preferences/com.expressvpn.ExpressVPN.plist"
append my_files "$HOME/Library/Preferences/com.expressvpn.ExpressVPNGroup.plist"
append my_files "$HOME/Library/Preferences/group.com.expressvpn.ExpressVPN.plist"
# logs
append my_files "$HOME/Library/Logs/ExpressVPN"
append my_files "/EV.script.log"
append my_files "/var/log/EV.script.log"
# kexts
append my_files "/Library/Extensions/tun.kext"
append my_files "/Library/Extensions/tap.kext"
# Print the files and directories that are to be removed and verify
# with the user that that is what he/she really wants to do.
echo "The following files and directories will be removed:"
for file in "${my_files[@]}"; do
echo " $file"
done
echo ""
echo "Do you wish to uninstall ExpressVPN (Yes/No)?"
read my_answer
if [ "$my_answer" != "Yes" ]; then
echo "Aborting install. (answer: ${my_answer})"
key_exit 2
fi
# Initiate the actual uninstall, which requires admin privileges.
echo "The uninstallation process requires administrative privileges"
echo "because some of the installed files cannot be removed by a"
echo "normal user. You may now be prompted for a password..."
echo ""
# Use AppleScript so we can use a graphical `sudo` prompt.
# This way, people can enter the username they wish to use
# for sudo, and it is more Apple-like.
tmpfile=`mktemp -t xvpn_uninstall`
echo "#!/bin/bash" > $tmpfile
echo "kextunload /Library/Extensions/tun.kext" >> $tmpfile
echo "kextunload /Library/Extensions/tap.kext" >> $tmpfile
for file in "${my_files[@]}"; do
echo "/bin/rm -rf \"$file\"" >> $tmpfile
done
echo $tmpfile
osascript -e "do shell script \"/bin/bash $tmpfile\" with administrator privileges"
# Verify that the uninstall succeeded by checking whether every file
# we meant to remove is actually removed.
for file in "${my_files[@]}"; do
if [ -e "${file}" ]; then
echo "An error must have occurred since a file that was supposed to be"
echo "removed still exists: ${file}"
echo ""
echo "Please try again."
key_exit 1
fi
done
echo "Successfully uninstalled ExpressVPN."
echo "Done."
if [ -e $tmpfile ]; then
rm -f $tmpfile
fi
key_exit 0
@datherra
Copy link

Cool stuff. Tks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment