#!/bin/sh

# Check permission.
if ! [ $(id -u) = 0 ]; then
   echo "Must be running with root permission!"
   exit 1
fi

# Stop it first.
sudo launchctl unload -w /Library/LaunchDaemons/org.nxfilter.nxproxy.plist
sleep 1

# Unset proxy.
export NX_HOME=/Library/nxproxy
/usr/bin/java -cp $NX_HOME/nxproxy.jar:$NX_HOME/lib/* nxproxy.Main -up

# Delete files.
sudo rm /Library/LaunchDaemons/org.nxfilter.nxproxy.plist
sudo rm -rf /Library/nxproxy
