| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 | #!/bin/sh# ====================================================================#  TorPostFlight is distributed under this license##  Copyright (c) 2006 Andrew Lewman## Redistribution and use in source and binary forms, with or without# modification, are permitted provided that the following conditions are# met:##     * Redistributions of source code must retain the above copyright# notice, this list of conditions and the following disclaimer.##     * Redistributions in binary form must reproduce the above# copyright notice, this list of conditions and the following disclaimer# in the documentation and/or other materials provided with the# distribution.##     * Neither the names of the copyright owners nor the names of its# contributors may be used to endorse or promote products derived from# this software without specific prior written permission.## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# ======================================================================# TorPostflight gets invoked after any install or upgrade.ADDSYSUSER=$RECEIPT_PATH/addsysuserif [ ! -x "$ADDSYSUSER" ]; then  echo "Could not find addsysuser script."  exit 1fiTORUSER=_torTORGROUP=daemonTARGET=$2/Library/TorTORDIR=$TARGET/var/lib/torLOGFILE=/var/log/tor.logTORBUTTON_VERSION="1.1.11-alpha"# Check defaults for TARGETif [ "$TARGET" == "//Library/Tor" ]; then	TARGET=/Library/Torfi# Create user $TORUSER in group daemon.  If it's already there, great.$ADDSYSUSER $TORUSER "Tor System user" $TORDIR# Create the tor directory, if it doesn't exist.if [ ! -d $TORDIR ]; then  mkdir -p $TORDIRfi# Check its permissions.chown $TORUSER $TORDIRchgrp daemon $TORDIRchmod 700 $TORDIRif [ ! -f $LOGFILE ]; then    touch $LOGFILE    chown $TORUSER $LOGFILE    chgrp daemon $LOGFILE    chmod 660 $LOGFILEfi# Create the configuration file only if there wasn't one already.if [ ! -f $TARGET/torrc ]; then  cp $TARGET/torrc.sample $TARGET/torrcfi# Ensure symbolic linkscd /usr/binif [ -e /usr/bin/tor -a ! -L /usr/bin/tor ]; then  mv tor tor_oldfiif [ -e /usr/bin/tor-resolve -a ! -L /usr/bin/tor-resolve ]; then  mv tor-resolve tor-resolve_oldfiln -sf $TARGET/tor .ln -sf $TARGET/tor-resolve .cd /usr/share/man/man1MAN1=$TARGET/man/man1ln -sf $MAN1/*.1 .if [ -d /Library/StartupItems/Privoxy ]; then  find /Library/StartupItems/Privoxy -print0 | xargs -0 chown root:wheelfi# Copy Documentationif [ -d $PACKAGE_PATH/Contents/Resources/documents ];then   cp -r $PACKAGE_PATH/Contents/Resources/documents $TARGET/documentsfi# Copy Uninstallerif [ -f $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript ]; then    cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript $TARGET/Tor_Uninstaller.applescript   chmod 550 $TARGET/Tor_Uninstaller.applescriptfiif [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then   cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh   chmod 550 $TARGET/uninstall_tor_bundle.shfiif [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then   cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txtfiif [ -d /Library/StartupItems/Tor ]; then   rm -f /Library/StartupItems/Tor/Tor.loc   echo "$TARGET" > /Library/StartupItems/Tor/Tor.locfiif [ -f /Applications/Firefox.app/Contents/MacOS/firefox ]; then  if [ -f $TARGET/torbutton-$TORBUTTON_VERSION.xpi ]; then      /Applications/Firefox.app/Contents/MacOS/firefox -install-global-extension $TARGET/torbutton-$TORBUTTON_VERSION.xpi# The following is a kludge to get around the fact that the installer# runs as root.  This means the Torbutton extension will install with# root permissions; thereby making uninstalling Torbutton from inside# Firefox impossible.  The user will be caught in an endless loop of# uninstall -> automatic re-installation of Torbutton.  The OSX# installer doesn't tell you the owner of Firefox, therefore we have to# parse it.      USR=`ls -alrt /Applications/Firefox.app/Contents/MacOS/extensions/ | tail -1 | awk '{print $3}'`      GRP=`ls -alrt /Applications/Firefox.app/Contents/MacOS/extensions/ | tail -1 | awk '{print $4}'`      chown -R $USR:$GRP /Applications/Firefox.app/Contents/MacOS/extensions/  fifi
 |