Guest User

Untitled

a guest
Apr 11th, 2020
799
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. INST_UPDATE_VER=update_10_69
  3. if [ `uname -m` = "x86_64" ]; then
  4. ARCH="linux64"
  5. else
  6. ARCH="linux32"
  7. fi
  8.  
  9. UPDATE_RPOC="AliYunDunUpdate"
  10. CLIENT_PROC="AliYunDun"
  11.  
  12. #check linux Gentoo os
  13. var=`lsb_release -a 2>/dev/null | grep Gentoo`
  14. if [ -z "${var}" ]; then
  15. var=`cat /etc/issue | grep Gentoo`
  16. fi
  17.  
  18. if [ -d "/etc/runlevels/default" -a -n "${var}" ]; then
  19. LINUX_RELEASE="GENTOO"
  20. else
  21. LINUX_RELEASE="OTHER"
  22. fi
  23.  
  24. AEGIS_INSTALL_DIR="/usr/local/aegis"
  25.  
  26. AEGIS_UPDATE_SITE="http://aegis.alicdn.com/download"
  27. AEGIS_UPDATE_SITE2="http://update.aegis.aliyun.com/download"
  28. AEGIS_UPDATE_SITE3="http://update2.aegis.aliyun.com/download"
  29. AEGIS_UPDATE_SITE4="http://update4.aegis.aliyun.com/download"
  30. AEGIS_UPDATE_SITE5="http://update5.aegis.aliyun.com/download"
  31. AEGIS_UPDATE_SITE6="http://update6.aegis.aliyun.com/download"
  32. DOWNLOAD_UPDATE_INDEX_VALUE=0
  33.  
  34. DEST_UPDATE_FILE=${AEGIS_INSTALL_DIR}/aegis_update/${UPDATE_RPOC}
  35.  
  36. download_file()
  37. {
  38. echo "start download from script"
  39.  
  40. checkValue=$3
  41. if [ 1 -gt ${checkValue} ]; then
  42. echo "download from 0"
  43. wget "${AEGIS_UPDATE_SITE}""$1" -O "$2" -t 1 -T 180
  44. if [ $? == 0 ]; then
  45. return 0
  46. fi
  47. fi
  48. if [ 2 -gt ${checkValue} ]; then
  49. echo "download from 1"
  50. wget "${AEGIS_UPDATE_SITE2}""$1" -O "$2" -t 1 -T 180
  51. if [ $? == 0 ]; then
  52. return 1
  53. fi
  54. fi
  55. if [ 3 -gt ${checkValue} ]; then
  56. echo "download from 2"
  57. wget "${AEGIS_UPDATE_SITE3}""$1" -O "$2" -t 1 -T 180
  58. if [ $? == 0 ]; then
  59. return 2
  60. fi
  61. fi
  62. if [ 4 -gt ${checkValue} ]; then
  63. echo "download from 3"
  64. wget "${AEGIS_UPDATE_SITE4}""$1" -O "$2" -t 1 -T 180
  65. if [ $? == 0 ]; then
  66. return 2
  67. fi
  68. fi
  69. if [ 5 -gt ${checkValue} ]; then
  70. echo "download from 4"
  71. wget "${AEGIS_UPDATE_SITE5}""$1" -O "$2" -t 1 -T 180
  72. if [ $? == 0 ]; then
  73. return 2
  74. fi
  75. fi
  76.  
  77. if [ 6 -gt ${checkValue} ]; then
  78. echo "download from 5"
  79. wget "${AEGIS_UPDATE_SITE6}""$1" -O "$2" -t 1 -T 180
  80. if [ $? == 0 ]; then
  81. return 2
  82. fi
  83. fi
  84.  
  85. rm -rf "$2"
  86. echo "download file error" 1>&2
  87. exit 1
  88. }
  89.  
  90. install_aegis()
  91. {
  92. echo "begin to install"
  93.  
  94. killall ${UPDATE_RPOC} 2>/dev/null
  95. killall ${CLIENT_PROC} 2>/dev/null
  96. killall aegis_cli 2>/dev/null
  97. killall aegis_update 2>/dev/null
  98. killall -9 AliHids 2>/dev/null
  99.  
  100. if [ -d "${AEGIS_INSTALL_DIR}/aegis_client" ];then
  101. rm -rf "${AEGIS_INSTALL_DIR}/aegis_client"
  102. fi
  103. if [ -d "${AEGIS_INSTALL_DIR}/aegis_update" ];then
  104. rm -rf "${AEGIS_INSTALL_DIR}/aegis_update"
  105. fi
  106. if [ -d "${AEGIS_INSTALL_DIR}/aegis_debug" ];then
  107. umount "${AEGIS_INSTALL_DIR}/aegis_debug"
  108. fi
  109.  
  110. mkdir -p "${AEGIS_INSTALL_DIR}/aegis_client"
  111. mkdir -p "${AEGIS_INSTALL_DIR}/aegis_update"
  112.  
  113. echo "downloading aegis_update..."
  114. download_file "/$ARCH/updates/${INST_UPDATE_VER}/aegis_update" "${DEST_UPDATE_FILE}" ${DOWNLOAD_UPDATE_INDEX_VALUE}
  115. DOWNLOAD_UPDATE_INDEX_VALUE=$?
  116. download_file "/$ARCH/updates/${INST_UPDATE_VER}/aegis_update.md5" "${AEGIS_INSTALL_DIR}/aegis_update/aegis_update.md5" ${DOWNLOAD_UPDATE_INDEX_VALUE}
  117. DOWNLOAD_UPDATE_INDEX_VALUE=$?
  118.  
  119. echo "checking aegis_update file..."
  120. md5_check=`md5sum "${DEST_UPDATE_FILE}" | awk '{print $1}' `
  121. md5_server=`head -1 "${AEGIS_INSTALL_DIR}/aegis_update/aegis_update.md5" | awk '{print $1}'`
  122. if [ "$md5_check"x = "$md5_server"x ]; then
  123. chmod +x "${DEST_UPDATE_FILE}"
  124. else
  125. echo "aegis_update checksum error."
  126. exit 1
  127. fi
  128. }
  129.  
  130. uninstall_service()
  131. {
  132. echo "uninstalling service..."
  133. if [ -f "/etc/init.d/aegis" ]; then
  134. /etc/init.d/aegis stop >/dev/null 2>&1
  135. rm -f /etc/init.d/aegis
  136. fi
  137.  
  138. if [ $LINUX_RELEASE = "GENTOO" ]; then
  139. rc-update del aegis default
  140. if [ -f "/etc/runlevels/default/aegis" ]; then
  141. rm -f "/etc/runlevels/default/aegis" >/dev/null 2>&1;
  142. fi
  143. elif [ -f /etc/init.d/aegis ]; then
  144. /etc/init.d/aegis uninstall
  145. for ((var=2; var<=5; var++)) do
  146. if [ -d "/etc/rc${var}.d/" ];then
  147. rm -f "/etc/rc${var}.d/S80aegis"
  148. elif [ -d "/etc/rc.d/rc${var}.d" ];then
  149. rm -f "/etc/rc.d/rc${var}.d/S80aegis"
  150. fi
  151. done
  152. fi
  153. }
  154.  
  155. install_service()
  156. {
  157. echo "installing service..."
  158.  
  159. if [ $LINUX_RELEASE = "GENTOO" ];then
  160. download_file "/linux_install/0061plus/aegis_gentoo" "/etc/init.d/aegis" ${DOWNLOAD_UPDATE_INDEX_VALUE}
  161. DOWNLOAD_UPDATE_INDEX_VALUE=$?
  162. download_file "/linux_install/0061plus/aegis_gentoo.md5" "${AEGIS_INSTALL_DIR}/aegis_update/aegis.md5" ${DOWNLOAD_UPDATE_INDEX_VALUE}
  163. DOWNLOAD_UPDATE_INDEX_VALUE=$?
  164. else
  165. download_file "/linux_install/0061plus/aegis" "/etc/init.d/aegis" ${DOWNLOAD_UPDATE_INDEX_VALUE}
  166. DOWNLOAD_UPDATE_INDEX_VALUE=$?
  167. download_file "/linux_install/0061plus/aegis.md5" "${AEGIS_INSTALL_DIR}/aegis_update/aegis.md5" ${DOWNLOAD_UPDATE_INDEX_VALUE}
  168. DOWNLOAD_UPDATE_INDEX_VALUE=$?
  169. fi
  170.  
  171. echo "checking aegis service file..."
  172. md5_check=`md5sum "/etc/init.d/aegis" | awk '{print $1}' `
  173. md5_server=`head -1 "${AEGIS_INSTALL_DIR}/aegis_update/aegis.md5" | awk '{print $1}'`
  174. if [ "$md5_check"x = "$md5_server"x ]; then
  175. echo "aegis checksum success."
  176. else
  177. echo "aegis checksum error."
  178. exit 1
  179. fi
  180.  
  181.  
  182. chmod 700 /etc/init.d/aegis
  183.  
  184. echo "remove old server"
  185.  
  186. #delete old aegis sever
  187. if [ $LINUX_RELEASE = "GENTOO" ]; then
  188. rc-update del aegis default 2> /dev/null
  189. if [ -f "/etc/runlevels/default/aegis" ]; then
  190. rm -f "/etc/runlevels/default/aegis"
  191. fi
  192. else
  193. for ((var=2; var<=5; var++))
  194. do
  195. if [ -f "/etc/rc${var}.d/S80aegis" ]; then
  196. rm -f "/etc/rc${var}.d/S80aegis"
  197. elif [ -f "/etc/rc.d/rc${var}.d/S80aegis" ];then
  198. rm -f "/etc/rc.d/rc${var}.d/S80aegis"
  199. fi
  200. done
  201. fi
  202.  
  203. echo "installing new server"
  204.  
  205. # install new aegis server
  206. if [ $LINUX_RELEASE = "GENTOO" ]; then
  207. rc-update add aegis default 2>/dev/null
  208. else
  209. for ((var=2; var<=5; var++)) do
  210. if [ -d "/etc/rc${var}.d/" ];then
  211. #redhat
  212. ln -s /etc/init.d/aegis /etc/rc${var}.d/S80aegis 2>/dev/null
  213. elif [ -d "/etc/rc.d/rc${var}.d" ]; then
  214. #suse
  215. ln -s /etc/init.d/aegis /etc/rc.d/rc${var}.d/S80aegis 2>/dev/null
  216. fi
  217. done
  218. fi
  219.  
  220. path="/etc/debian_version"
  221.  
  222. if [ -f "$path" -a -s "$path" ];
  223. then
  224. var=`awk -F. '{print $1}' $path`
  225.  
  226. if [ -z $(echo $var|grep "[^0-9]") ]; then
  227. if [ $var -ge 6 ]; then
  228. echo "insserv aegis"
  229. insserv aegis >/dev/null 2>&1
  230. fi
  231. fi
  232. fi
  233. }
  234.  
  235. #remove_ud()
  236. #{
  237. # if [ -f "${AEGIS_INSTALL_DIR}/globalcfg/ud" ];then
  238. # rm -f "${AEGIS_INSTALL_DIR}/globalcfg/ud" > /dev/null 2>&1
  239. # fi
  240. #
  241. # if [ -f "${AEGIS_INSTALL_DIR}/globalcfg/ui_ud" ];then
  242. # rm -f "${AEGIS_INSTALL_DIR}/globalcfg/ui_ud" > /dev/null 2>&1
  243. # fi
  244. #}
  245.  
  246. check_aegis()
  247. {
  248. var=1
  249. limit=18
  250. echo "Aegis client is installing , please wait for 1 to 3 minutes.";
  251.  
  252. while [[ $var -lt $limit ]]; do
  253. if [ -n "$(ps -ef|grep aegis_client|grep -v grep)" ]; then
  254. break
  255. else
  256. sleep 10
  257. fi
  258.  
  259. ((var++))
  260. done
  261. }
  262.  
  263. if [ `id -u` -ne "0" ]; then
  264. echo "ERROR: This script must be run as root." 1>&2
  265. exit 1
  266. fi
  267.  
  268.  
  269. uninstall_service
  270. install_aegis
  271. install_service
  272. #remove_ud
  273.  
  274. if [ -f /etc/init.d/aegis ];then
  275. /etc/init.d/aegis start
  276. fi
  277.  
  278. check_aegis
  279. #service aegis start
  280. echo "Aegis successfully installed"
  281. exit 0
RAW Paste Data