Skip to content

Instantly share code, notes, and snippets.

@k0nserv
Created December 1, 2015 19:43
Show Gist options
  • Save k0nserv/1168ba9cf700325826b2 to your computer and use it in GitHub Desktop.
Save k0nserv/1168ba9cf700325826b2 to your computer and use it in GitHub Desktop.
#!/bin/bash
export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
# export IFS=" \t\n"
unset IFS
echo "App installation path: $1"
AppPath=$1"/"
# provide second parameter to disable permission setting
set +e
if [ -z "$2" ]
then
echo "set permission to Freedome.app: "$AppPath
chmod 755 "$AppPath"
chown -R root:wheel "$AppPath"
fi
echo "creating data folders"
mkdir "/Library/Application Support/F-Secure"
mkdir "/Library/Application Support/F-Secure/FSFreedome"
mkdir "/Library/Application Support/F-Secure/FSFreedome/admin"
chmod 1777 "/Library/Application Support/F-Secure/FSFreedome"
chmod 755 "/Library/Application Support/F-Secure/FSFreedome/admin"
chown root:admin "/Library/Application Support/F-Secure/FSFreedome/admin"
echo "done creating data folders"
set -e
set +e # may not be loaded
echo unloading services
launchctl unload /Library/LaunchDaemons/com.fsecure.freedome.vpn.plist
launchctl unload /Library/LaunchDaemons/com.fsecure.freedome.uninstall.plist
# unloading agent will close currently running UI
# launchctl unload /Library/LaunchAgents/com.fsecure.freedome.gui.plist
set -e # fail on error
echo clearing temp files
set +e # dont care
rm "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.vpn.plist"
rm "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.uninstall.plist"
rm "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.gui.plist"
set -e # fail on error
echo creating temp plist files
# cmd param 1 is installation path /Applications/Freedome.app or similar
FreedomePath=$1"/Contents/MacOS"
echo "Freedome path: "$FreedomePath
sed -e "s|%2|$FreedomePath|g" -e 's|%1|/Library/Application Support/F-Secure/FSFreedome|g' <"$1/Contents/Resources/com.fsecure.freedome.gui.plist.template" | tee "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.gui.plist.template" > /dev/null
sed -e "s|%2|$FreedomePath|g" -e 's|%1|/Library/Application Support/F-Secure/FSFreedome|g' <"$1/Contents/Resources/com.fsecure.freedome.vpn.plist.template" | tee "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.vpn.plist.template" > /dev/null
sed -e "s|%2|$1|g" -e 's|%1|/Library/Application Support/F-Secure/FSFreedome|g' <"$1/Contents/Resources/com.fsecure.freedome.uninstall.plist.template" | tee "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.uninstall.plist.template" > /dev/null
echo done creating temp plist files
cp "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.vpn.plist.template" /Library/LaunchDaemons/com.fsecure.freedome.vpn.plist
cp "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.uninstall.plist.template" /Library/LaunchDaemons/com.fsecure.freedome.uninstall.plist
cp "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.gui.plist.template" /Library/LaunchAgents/com.fsecure.freedome.gui.plist
echo clearing temp files
set +e # dont care
rm "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.vpn.plist.template"
rm "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.uninstall.plist.template"
rm "/Library/Application Support/F-Secure/FSFreedome/admin/com.fsecure.freedome.gui.plist.template"
set -e # fail on error
echo "Copy uninstallation script"
cp "$1/Contents/Resources/UninstallFreedome.sh" "/Library/Application Support/F-Secure/FSFreedome/admin/UninstallFreedome.sh"
echo "Done copying uninstallation script"
echo launching gui plist
chown root:wheel /Library/LaunchAgents/com.fsecure.freedome.gui.plist
chmod 644 /Library/LaunchAgents/com.fsecure.freedome.gui.plist
# we should not load gui because it will trigger it's start immediately.
# it will be loaded on next reboot
# launchctl load /Library/LaunchAgents/com.fsecure.freedome.gui.plist
echo launching vpn and uninstall daemon plists
chown root:wheel /Library/LaunchDaemons/com.fsecure.freedome.uninstall.plist
chmod 644 /Library/LaunchDaemons/com.fsecure.freedome.uninstall.plist
launchctl load /Library/LaunchDaemons/com.fsecure.freedome.uninstall.plist
chown root:wheel /Library/LaunchDaemons/com.fsecure.freedome.vpn.plist
chmod 644 /Library/LaunchDaemons/com.fsecure.freedome.vpn.plist
launchctl load /Library/LaunchDaemons/com.fsecure.freedome.vpn.plist
echo Installation done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment