ZeroTierOne/ext/installfiles/mac/install.tmpl.sh

148 lines
4.7 KiB
Bash
Raw Normal View History

#!/bin/bash
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
shopt -s expand_aliases
dryRun=0
echo "*** ZeroTier One install/update ***"
if [ "$UID" -ne 0 ]; then
echo "Not running as root so doing dry run (no modifications to system)..."
dryRun=1
fi
if [ $dryRun -gt 0 ]; then
alias ln="echo '>> dry run: ln'"
alias rm="echo '>> dry run: rm'"
2014-01-03 23:39:09 +00:00
alias mv="echo '>> dry run: mv'"
2014-01-10 06:58:31 +00:00
alias cp="echo '>> dry run: cp'"
2014-01-03 23:39:09 +00:00
alias chown="echo '>> dry run: chown'"
alias chgrp="echo '>> dry run: chgrp'"
2014-01-10 06:58:31 +00:00
alias chmod="echo '>> dry run: chmod'"
alias launchctl="echo '>> dry run: launchctl'"
alias zerotier-cli="echo '>> dry run: zerotier-cli'"
fi
2014-01-03 23:39:09 +00:00
zthome="/Library/Application Support/ZeroTier/One"
2014-01-10 22:09:08 +00:00
ztapp="/Applications/ZeroTier One.app"
if [ ! -d "$ztapp" ]; then
ztapp=`mdfind kMDItemCFBundleIdentifier == 'com.zerotier.ZeroTierOne' | grep -E '.*ZeroTier One[.]app$' | grep -v -F '/build-' | grep -v -F '/Volumes/ZeroTier' | sort | head -n 1`
2014-01-03 23:39:09 +00:00
fi
scriptPath="`dirname "$0"`/`basename "$0"`"
if [ ! -r "$scriptPath" ]; then
scriptPath="$0"
if [ ! -r "$scriptPath" ]; then
echo "Installer cannot determine its own path; $scriptPath is not readable."
exit 2
fi
fi
2014-01-04 00:53:00 +00:00
endMarkerIndex=`grep -a -b -E '^################' "$scriptPath" | head -c 16 | cut -d : -f 1`
if [ "$endMarkerIndex" -le 100 ]; then
echo 'Internal error: unable to find end of script / start of binary data marker.'
exit 2
fi
blobStart=`expr $endMarkerIndex + 17`
if [ "$blobStart" -le "$endMarkerIndex" ]; then
echo 'Internal error: unable to find end of script / start of binary data marker.'
exit 2
fi
echo 'Extracting files...'
if [ $dryRun -gt 0 ]; then
echo ">> dry run: tail -c +$blobStart \"$scriptPath\" | bunzip2 -c | tar -xvop -C / -f -"
else
2014-01-10 06:58:31 +00:00
rm -rf '/tmp/_zt1tmp'
mkdir '/tmp/_zt1tmp'
tail -c +$blobStart "$scriptPath" | bunzip2 -c | tar -xop -C '/tmp/_zt1tmp' -f -
fi
2014-01-10 06:58:31 +00:00
cd '/tmp/_zt1tmp'
if [ $dryRun -eq 0 -a ! -d './Applications/ZeroTier One.app' ]; then
2014-01-10 22:09:08 +00:00
echo 'Archive extraction failed, cannot find files in /tmp/_zt1tmp.'
exit 2
fi
2014-01-10 06:58:31 +00:00
echo 'Installing zerotier-one service...'
mkdir -p "$zthome"
chown root:admin "$zthome"
chmod 0750 "$zthome"
cp -fa ./Library/Application\ Support/ZeroTier/One/* "$zthome"
chown -R root:wheel "$zthome/tap.kext"
chown -R root:wheel "$zthome/pre10.8/tap.kext"
2014-01-03 23:39:09 +00:00
echo 'Installing/updating ZeroTier One.app...'
2014-01-10 22:09:08 +00:00
if [ ! -z "$ztapp" -a -d "$ztapp" -a -f "$ztapp/Contents/Info.plist" ]; then
# Preserve ownership of current app across updates... that way the admin
# user who dragged it into /Applications can just trash it the way they
# would any other app. This works (due to mdfind up top) even if they put
# it somewhere non-standard on their system.
2014-01-03 23:39:09 +00:00
currentAppOwner=`stat -f '%u' "$ztapp"`
currentAppGroup=`stat -f '%g' "$ztapp"`
2014-01-10 06:58:31 +00:00
rm -rf "$ztapp"
mv -f './Applications/ZeroTier One.app' "$ztapp"
2014-01-03 23:39:09 +00:00
if [ ! -z "$currentAppOwner" -a ! -z "$currentAppGroup" ]; then
chown -R $currentAppOwner "$ztapp"
chgrp -R $currentAppGroup "$ztapp"
2014-01-10 22:09:08 +00:00
else
chown -R root "$ztapp"
chgrp -R admin "$ztapp"
2014-01-03 23:39:09 +00:00
fi
else
# If there is no existing app, just drop the shipped one into place
2014-01-10 22:09:08 +00:00
ztapp="/Applications/ZeroTier One.app"
mv -f './Applications/ZeroTier One.app' "$ztapp"
chown -R root "$ztapp"
chgrp -R admin "$ztapp"
2014-01-03 23:39:09 +00:00
fi
2014-01-10 06:58:31 +00:00
# Set up symlink that watches for app deletion
rm -f "$zthome/shutdownIfUnreadable"
ln -sf "$ztapp/Contents/Info.plist" "$zthome/shutdownIfUnreadable"
echo 'Installing zerotier-cli command line utility...'
2014-01-10 22:09:08 +00:00
rm -f /usr/bin/zerotier-cli
ln -sf "/Library/Application Support/ZeroTier/One/zerotier-one" /usr/bin/zerotier-cli
2014-01-10 22:09:08 +00:00
# This lets the install helper AppleScript thingy go ahead and authorize the
# user after the installer is done, skiping that step for the user who did
# the service install.
2014-01-03 20:15:47 +00:00
if [ ! -f '/Library/Application Support/ZeroTier/One/authtoken.secret' ]; then
echo 'Pre-creating authtoken.secret for ZeroTier service...'
if [ $dryRun -eq 0 ]; then
rm -f '/Library/Application Support/ZeroTier/One/authtoken.secret'
head -c 1024 /dev/urandom | md5 | head -c 24 >'/Library/Application Support/ZeroTier/One/authtoken.secret'
chmod 0600 '/Library/Application Support/ZeroTier/One/authtoken.secret'
fi
fi
echo 'Installing and (re-)starting zerotier-one service via launchctl...'
2014-01-10 06:58:31 +00:00
mv -f './Library/LaunchDaemons/com.zerotier.one.plist' '/Library/LaunchDaemons/'
if [ ! -z "`launchctl list | grep -F com.zerotier.one`" ]; then
launchctl unload /Library/LaunchDaemons/com.zerotier.one.plist
2014-01-10 22:09:08 +00:00
sleep 1
fi
launchctl load /Library/LaunchDaemons/com.zerotier.one.plist
sleep 1
2014-01-10 06:58:31 +00:00
/usr/bin/zerotier-cli info
cd /tmp
rm -rf _zt1tmp
exit 0
# Do not remove the last line or add a carriage return to it! The installer
# looks for an unterminated line beginning with 16 #'s in itself to find
# the binary blob data, which is appended after it.
################