Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- umask 077
- args="$@"
- echo "Installing Sophos Anti-Virus for Linux with arguments: [$args]"
- cleanupAndExit()
- {
- [ -z "$OVERRIDE_INSTALLER_CLEANUP" ] && rm -rf "$SOPHOS_TEMP_DIRECTORY"
- exit $1
- }
- createSymlinks()
- {
- for baselib in `ls`
- do
- shortlib=$baselib
- while extn=$(echo $shortlib | sed -n '/\.[0-9][0-9]*$/s/.*\(\.[0-9][0-9]*\)$/\1/p')
- [ -n "$extn" ]
- do
- shortlib=$(basename $shortlib $extn)
- ln -s $baselib $shortlib
- done
- done
- }
- uname -a | grep -i Linux >/dev/null
- if [ $? -eq 1 ] ; then
- echo "This installer only runs on Linux." >&2
- cleanupAndExit 1
- fi
- if [ $(id -u) -ne 0 ]; then
- echo "Please run this installer as root." >&2
- cleanupAndExit 2
- fi
- INSTALL_LOCATION=/opt/sophos-av
- # Handle arguments
- for i in "$@"
- do
- case $i in
- --update-source-creds=*)
- export OVERRIDE_SOPHOS_CREDS="${i#*=}"
- shift
- ;;
- --instdir=*)
- export INSTALL_LOCATION="${i#*=}"
- shift
- ;;
- esac
- done
- [ -n "$OVERRIDE_SOPHOS_CREDS" ] && {
- echo "Overriding sophos credentials with $OVERRIDE_SOPHOS_CREDS"
- }
- handleInstallerErrorcodes()
- {
- errcode=$1
- if [ $errcode -eq 2 ]
- then
- echo "Cannot connect to Sophos Cloud." >&2
- cleanupAndExit 3
- elif [ $errcode -eq 0 ]
- then
- echo "Finished downloading the medium installer."
- else
- echo "Failed to download the medium installer! (Error code = $errcode)" >&2
- cleanupAndExit 10
- fi
- }
- check_free()
- {
- local path=$1
- local space=$2
- local install_path=${INSTALL_LOCATION%/*}
- local free=$(df -kP $install_path | sed -e "1d" | awk '{print $4}')
- local mountpoint=$(df -kP $install_path | sed -e "1d" | awk '{print $6}')
- local free_mb
- free_mb=$(( free / 1024 ))
- if [ $free_mb -gt $space ]
- then
- return 0
- fi
- echo "Not enough space in $mountpoint to install Sophos Anti-Virus for Linux. You can install elsewhere by re-running this installer with the --instdir argument."
- cleanupAndExit 5
- }
- if [ -z "$SOPHOS_TEMP_DIRECTORY" ]; then
- SOPHOS_TEMP_DIRECTORY=`mktemp -d` || SOPHOS_TEMP_DIRECTORY="/tmp/sophos.thininstall"
- fi
- mkdir -p "$SOPHOS_TEMP_DIRECTORY"
- ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' $0`
- MIDDLEBIT=`awk '/^__MIDDLE_BIT__/ {print NR + 1; exit 0; }' $0`
- DIFFERENCE=`expr $ARCHIVE - $MIDDLEBIT`
- tail -n+$MIDDLEBIT $0 | head -$DIFFERENCE > $SOPHOS_TEMP_DIRECTORY/credentials.txt
- tail -n+$ARCHIVE $0 > $SOPHOS_TEMP_DIRECTORY/installer.tar.gz
- cd $SOPHOS_TEMP_DIRECTORY
- INSTDIR=`readlink /usr/local/bin/sweep | sed 's/bin\/savscan//g'`
- if [ "$INSTDIR" != "" ] && [ -d $INSTDIR ]
- then
- echo "Found an existing installation of SAV in $INSTDIR"
- else
- INSTDIR="/opt/sophos-av"
- fi
- if [ -z "$OVERRIDE_CLOUD_TOKEN" ]
- then
- CLOUD_TOKEN=$(grep 'TOKEN=' credentials.txt | sed 's/TOKEN=//')
- else
- CLOUD_TOKEN=$OVERRIDE_CLOUD_TOKEN
- fi
- if [ -z "$OVERRIDE_CLOUD_URL" ]
- then
- CLOUD_URL=$(grep 'URL=' credentials.txt | sed 's/URL=//')
- else
- CLOUD_URL=$OVERRIDE_CLOUD_URL
- fi
- if [ -d $INSTDIR ]; then
- if [ -f "${INSTDIR}/engine/registerMCS" ]
- then
- echo "Attempting to register existing installation with Sophos Cloud"
- echo "Cloud token is [$CLOUD_TOKEN], Cloud URL is [$CLOUD_URL]"
- ${INSTDIR}/engine/registerMCS $CLOUD_TOKEN $CLOUD_URL
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to register in the cloud - error $?" >&2
- cleanupAndExit 6
- fi
- cleanupAndExit 0
- else
- echo "Please uninstall SAV before using this installer" >&2
- cleanupAndExit 7
- fi
- fi
- check_free $INSTALL_LOCATION 1024
- tar -zxf installer.tar.gz
- rm installer.tar.gz
- export LD_LIBRARY_PATH=installer/bin64:installer/bin32
- mkdir distribute
- mkdir cache
- mkdir warehouse
- mkdir warehouse/catalogue
- MACHINE_TYPE=`uname -m`
- if [ $MACHINE_TYPE = "x86_64" ]; then
- BIN=installer/bin64
- else
- BIN=installer/bin32
- fi
- [ -z "$OVERRIDE_SOPHOS_CERTS" ] && OVERRIDE_SOPHOS_CERTS=$BIN
- export OVERRIDE_SOPHOS_CERTS
- echo "Downloading medium installer"
- $BIN/installer credentials.txt
- handleInstallerErrorcodes $?
- ## Verify manifest.dat
- CERT=$BIN/rootca.crt
- [ -n $OVERRIDE_SOPHOS_CERTS ] && CERT=$OVERRIDE_SOPHOS_CERTS/rootca.crt
- [ -f $CERT ] || CERT=$BIN/rootca.crt
- $BIN/versig -c$CERT -fdistribute/manifest.dat -ddistribute --check-install-sh \
- || {
- echo "ERROR: Failed to verify medium installer: $?" >&2
- cleanupAndExit 8
- }
- [ -z "$OVERRIDE_PROD_SOPHOS_CERTS" ] || cp $OVERRIDE_PROD_SOPHOS_CERTS/* distribute/update/certificates/
- credentials=""
- if [ -z "$OVERRIDE_SOPHOS_CREDS" ]
- then
- creds=$(grep 'UPDATE_CREDENTIALS=' credentials.txt | sed 's/UPDATE_CREDENTIALS=//')
- credentials="--update-source-username=$creds --update-source-password=$creds"
- else
- credentials="--update-source-username=$OVERRIDE_SOPHOS_CREDS --update-source-password=$OVERRIDE_SOPHOS_CREDS"
- fi
- cd distribute
- chmod u+x install.sh
- if [ -f "installOptions" ]
- then
- echo -n " $credentials $args" >> installOptions
- else
- echo "INTERNAL ERROR: No 'installOptions' file in medium installer." >&2
- cleanupAndExit 9
- fi
- if [ $MACHINE_TYPE = "x86_64" ]
- then
- cd lib64
- else
- cd lib32
- fi
- createSymlinks
- cd ..
- echo "Running medium installer (this may take some time)"
- ./install.sh --minipkg
- inst_ret=$?
- if [ $inst_ret -ne 0 ] && [ $inst_ret -ne 4 ]
- then
- echo "ERROR: Installer returned $inst_ret (see above messages)" >&2
- exit 10
- fi
- $INSTALL_LOCATION/engine/registerMCS $CLOUD_TOKEN $CLOUD_URL
- ret=$?
- if [ $ret -ne 0 ]
- then
- echo "ERROR: Failed to register in the cloud - error $ret" >&2
- exit 11
- fi
- cleanupAndExit $inst_ret
- __MIDDLE_BIT__
- TOKEN=6bff06db65b3f1831408e07317aa51f63658744211b763f9662783b414dd3b9f
- URL=https://dzr-mcs-amzn-us-west-2-fa88.upe.p.hmr.sophos.com/sophos/management/ep
- UPDATE_CREDENTIALS=7ef3dd2559256be0737ab7b3b4edccb2
- __ARCHIVE_BELOW__
- ‹à÷U
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement