Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. umask 077
  4.  
  5. args="$@"
  6. echo "Installing Sophos Anti-Virus for Linux with arguments: [$args]"
  7.  
  8. cleanupAndExit()
  9. {
  10. [ -z "$OVERRIDE_INSTALLER_CLEANUP" ] && rm -rf "$SOPHOS_TEMP_DIRECTORY"
  11. exit $1
  12. }
  13.  
  14. createSymlinks()
  15. {
  16. for baselib in `ls`
  17. do
  18. shortlib=$baselib
  19. while extn=$(echo $shortlib | sed -n '/\.[0-9][0-9]*$/s/.*\(\.[0-9][0-9]*\)$/\1/p')
  20. [ -n "$extn" ]
  21. do
  22. shortlib=$(basename $shortlib $extn)
  23. ln -s $baselib $shortlib
  24. done
  25. done
  26. }
  27.  
  28. uname -a | grep -i Linux >/dev/null
  29. if [ $? -eq 1 ] ; then
  30. echo "This installer only runs on Linux." >&2
  31. cleanupAndExit 1
  32. fi
  33.  
  34. if [ $(id -u) -ne 0 ]; then
  35. echo "Please run this installer as root." >&2
  36. cleanupAndExit 2
  37. fi
  38.  
  39. INSTALL_LOCATION=/opt/sophos-av
  40. # Handle arguments
  41. for i in "$@"
  42. do
  43. case $i in
  44. --update-source-creds=*)
  45. export OVERRIDE_SOPHOS_CREDS="${i#*=}"
  46. shift
  47. ;;
  48. --instdir=*)
  49. export INSTALL_LOCATION="${i#*=}"
  50. shift
  51. ;;
  52. esac
  53. done
  54.  
  55. [ -n "$OVERRIDE_SOPHOS_CREDS" ] && {
  56. echo "Overriding sophos credentials with $OVERRIDE_SOPHOS_CREDS"
  57. }
  58.  
  59. handleInstallerErrorcodes()
  60. {
  61. errcode=$1
  62. if [ $errcode -eq 2 ]
  63. then
  64. echo "Cannot connect to Sophos Cloud." >&2
  65. cleanupAndExit 3
  66. elif [ $errcode -eq 0 ]
  67. then
  68. echo "Finished downloading the medium installer."
  69. else
  70. echo "Failed to download the medium installer! (Error code = $errcode)" >&2
  71. cleanupAndExit 10
  72. fi
  73. }
  74.  
  75. check_free()
  76. {
  77. local path=$1
  78. local space=$2
  79.  
  80. local install_path=${INSTALL_LOCATION%/*}
  81. local free=$(df -kP $install_path | sed -e "1d" | awk '{print $4}')
  82. local mountpoint=$(df -kP $install_path | sed -e "1d" | awk '{print $6}')
  83.  
  84. local free_mb
  85. free_mb=$(( free / 1024 ))
  86.  
  87. if [ $free_mb -gt $space ]
  88. then
  89. return 0
  90. fi
  91. 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."
  92. cleanupAndExit 5
  93. }
  94.  
  95. if [ -z "$SOPHOS_TEMP_DIRECTORY" ]; then
  96. SOPHOS_TEMP_DIRECTORY=`mktemp -d` || SOPHOS_TEMP_DIRECTORY="/tmp/sophos.thininstall"
  97. fi
  98.  
  99. mkdir -p "$SOPHOS_TEMP_DIRECTORY"
  100.  
  101. ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' $0`
  102. MIDDLEBIT=`awk '/^__MIDDLE_BIT__/ {print NR + 1; exit 0; }' $0`
  103. DIFFERENCE=`expr $ARCHIVE - $MIDDLEBIT`
  104.  
  105. tail -n+$MIDDLEBIT $0 | head -$DIFFERENCE > $SOPHOS_TEMP_DIRECTORY/credentials.txt
  106. tail -n+$ARCHIVE $0 > $SOPHOS_TEMP_DIRECTORY/installer.tar.gz
  107.  
  108. cd $SOPHOS_TEMP_DIRECTORY
  109.  
  110. INSTDIR=`readlink /usr/local/bin/sweep | sed 's/bin\/savscan//g'`
  111. if [ "$INSTDIR" != "" ] && [ -d $INSTDIR ]
  112. then
  113. echo "Found an existing installation of SAV in $INSTDIR"
  114. else
  115. INSTDIR="/opt/sophos-av"
  116. fi
  117.  
  118. if [ -z "$OVERRIDE_CLOUD_TOKEN" ]
  119. then
  120. CLOUD_TOKEN=$(grep 'TOKEN=' credentials.txt | sed 's/TOKEN=//')
  121. else
  122. CLOUD_TOKEN=$OVERRIDE_CLOUD_TOKEN
  123. fi
  124.  
  125. if [ -z "$OVERRIDE_CLOUD_URL" ]
  126. then
  127. CLOUD_URL=$(grep 'URL=' credentials.txt | sed 's/URL=//')
  128. else
  129. CLOUD_URL=$OVERRIDE_CLOUD_URL
  130. fi
  131.  
  132. if [ -d $INSTDIR ]; then
  133. if [ -f "${INSTDIR}/engine/registerMCS" ]
  134. then
  135. echo "Attempting to register existing installation with Sophos Cloud"
  136. echo "Cloud token is [$CLOUD_TOKEN], Cloud URL is [$CLOUD_URL]"
  137. ${INSTDIR}/engine/registerMCS $CLOUD_TOKEN $CLOUD_URL
  138.  
  139. if [ $? -ne 0 ]; then
  140. echo "ERROR: Failed to register in the cloud - error $?" >&2
  141. cleanupAndExit 6
  142. fi
  143.  
  144. cleanupAndExit 0
  145. else
  146. echo "Please uninstall SAV before using this installer" >&2
  147. cleanupAndExit 7
  148. fi
  149. fi
  150.  
  151. check_free $INSTALL_LOCATION 1024
  152.  
  153. tar -zxf installer.tar.gz
  154. rm installer.tar.gz
  155.  
  156. export LD_LIBRARY_PATH=installer/bin64:installer/bin32
  157.  
  158. mkdir distribute
  159. mkdir cache
  160. mkdir warehouse
  161. mkdir warehouse/catalogue
  162.  
  163. MACHINE_TYPE=`uname -m`
  164. if [ $MACHINE_TYPE = "x86_64" ]; then
  165. BIN=installer/bin64
  166. else
  167. BIN=installer/bin32
  168. fi
  169. [ -z "$OVERRIDE_SOPHOS_CERTS" ] && OVERRIDE_SOPHOS_CERTS=$BIN
  170. export OVERRIDE_SOPHOS_CERTS
  171. echo "Downloading medium installer"
  172. $BIN/installer credentials.txt
  173. handleInstallerErrorcodes $?
  174.  
  175. ## Verify manifest.dat
  176. CERT=$BIN/rootca.crt
  177. [ -n $OVERRIDE_SOPHOS_CERTS ] && CERT=$OVERRIDE_SOPHOS_CERTS/rootca.crt
  178. [ -f $CERT ] || CERT=$BIN/rootca.crt
  179.  
  180. $BIN/versig -c$CERT -fdistribute/manifest.dat -ddistribute --check-install-sh \
  181. || {
  182. echo "ERROR: Failed to verify medium installer: $?" >&2
  183. cleanupAndExit 8
  184. }
  185.  
  186. [ -z "$OVERRIDE_PROD_SOPHOS_CERTS" ] || cp $OVERRIDE_PROD_SOPHOS_CERTS/* distribute/update/certificates/
  187.  
  188. credentials=""
  189. if [ -z "$OVERRIDE_SOPHOS_CREDS" ]
  190. then
  191. creds=$(grep 'UPDATE_CREDENTIALS=' credentials.txt | sed 's/UPDATE_CREDENTIALS=//')
  192. credentials="--update-source-username=$creds --update-source-password=$creds"
  193. else
  194. credentials="--update-source-username=$OVERRIDE_SOPHOS_CREDS --update-source-password=$OVERRIDE_SOPHOS_CREDS"
  195. fi
  196.  
  197. cd distribute
  198.  
  199. chmod u+x install.sh
  200. if [ -f "installOptions" ]
  201. then
  202. echo -n " $credentials $args" >> installOptions
  203. else
  204. echo "INTERNAL ERROR: No 'installOptions' file in medium installer." >&2
  205. cleanupAndExit 9
  206. fi
  207.  
  208. if [ $MACHINE_TYPE = "x86_64" ]
  209. then
  210. cd lib64
  211. else
  212. cd lib32
  213. fi
  214. createSymlinks
  215. cd ..
  216.  
  217. echo "Running medium installer (this may take some time)"
  218. ./install.sh --minipkg
  219. inst_ret=$?
  220. if [ $inst_ret -ne 0 ] && [ $inst_ret -ne 4 ]
  221. then
  222. echo "ERROR: Installer returned $inst_ret (see above messages)" >&2
  223. exit 10
  224. fi
  225.  
  226. $INSTALL_LOCATION/engine/registerMCS $CLOUD_TOKEN $CLOUD_URL
  227. ret=$?
  228. if [ $ret -ne 0 ]
  229. then
  230. echo "ERROR: Failed to register in the cloud - error $ret" >&2
  231. exit 11
  232. fi
  233.  
  234. cleanupAndExit $inst_ret
  235. __MIDDLE_BIT__
  236.  
  237. TOKEN=6bff06db65b3f1831408e07317aa51f63658744211b763f9662783b414dd3b9f
  238. URL=https://dzr-mcs-amzn-us-west-2-fa88.upe.p.hmr.sophos.com/sophos/management/ep
  239. UPDATE_CREDENTIALS=7ef3dd2559256be0737ab7b3b4edccb2
  240. __ARCHIVE_BELOW__
  241. ‹à÷U
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement