backup_setup.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  11. clear
  12. printf "
  13. #######################################################################
  14. # OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+ #
  15. # Setup the backup parameters #
  16. # For more information please visit https://oneinstack.com #
  17. #######################################################################
  18. "
  19. # Check if user is root
  20. [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  21. oneinstack_dir=$(dirname "`readlink -f $0`")
  22. pushd ${oneinstack_dir} > /dev/null
  23. . ./options.conf
  24. . ./versions.txt
  25. . ./include/color.sh
  26. . ./include/check_os.sh
  27. . ./include/check_dir.sh
  28. . ./include/download.sh
  29. . ./include/python.sh
  30. while :; do echo
  31. echo 'Please select your backup destination:'
  32. echo -e "\t${CMSG}1${CEND}. Localhost"
  33. echo -e "\t${CMSG}2${CEND}. Remote host"
  34. echo -e "\t${CMSG}3${CEND}. Aliyun OSS"
  35. echo -e "\t${CMSG}4${CEND}. Qcloud COS"
  36. echo -e "\t${CMSG}5${CEND}. UPYUN"
  37. echo -e "\t${CMSG}6${CEND}. QINIU"
  38. echo -e "\t${CMSG}7${CEND}. Google Drive"
  39. read -e -p "Please input numbers:(Default 1 press Enter) " desc_bk
  40. desc_bk=${desc_bk:-'1'}
  41. array_desc=(${desc_bk})
  42. array_all=(1 2 3 4 5 6 7)
  43. for v in ${array_desc[@]}
  44. do
  45. [ -z "`echo ${array_all[@]} | grep -w ${v}`" ] && desc_flag=1
  46. done
  47. if [ "${desc_flag}" == '1' ]; then
  48. unset desc_flag
  49. echo; echo "${CWARNING}input error! Please only input number 1 3 4 and so on${CEND}"; echo
  50. continue
  51. else
  52. sed -i 's@^backup_destination=.*@backup_destination=@' ./options.conf
  53. break
  54. fi
  55. done
  56. [ -n "`echo ${desc_bk} | grep -w 1`" ] && sed -i 's@^backup_destination=.*@backup_destination=local@' ./options.conf
  57. [ -n "`echo ${desc_bk} | grep -w 2`" ] && sed -i 's@^backup_destination=.*@&,remote@' ./options.conf
  58. [ -n "`echo ${desc_bk} | grep -w 3`" ] && sed -i 's@^backup_destination=.*@&,oss@' ./options.conf
  59. [ -n "`echo ${desc_bk} | grep -w 4`" ] && sed -i 's@^backup_destination=.*@&,cos@' ./options.conf
  60. [ -n "`echo ${desc_bk} | grep -w 5`" ] && sed -i 's@^backup_destination=.*@&,upyun@' ./options.conf
  61. [ -n "`echo ${desc_bk} | grep -w 6`" ] && sed -i 's@^backup_destination=.*@&,qiniu@' ./options.conf
  62. [ -n "`echo ${desc_bk} | grep -w 7`" ] && sed -i 's@^backup_destination=.*@&,gdrive@' ./options.conf
  63. sed -i 's@^backup_destination=,@backup_destination=@' ./options.conf
  64. while :; do echo
  65. echo 'Please select your backup content:'
  66. echo -e "\t${CMSG}1${CEND}. Only Database"
  67. echo -e "\t${CMSG}2${CEND}. Only Website"
  68. echo -e "\t${CMSG}3${CEND}. Database and Website"
  69. read -e -p "Please input a number:(Default 1 press Enter) " content_bk
  70. content_bk=${content_bk:-1}
  71. if [[ ! ${content_bk} =~ ^[1-3]$ ]]; then
  72. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  73. else
  74. break
  75. fi
  76. done
  77. [ "${content_bk}" == '1' ] && sed -i 's@^backup_content=.*@backup_content=db@' ./options.conf
  78. [ "${content_bk}" == '2' ] && sed -i 's@^backup_content=.*@backup_content=web@' ./options.conf
  79. [ "${content_bk}" == '3' ] && sed -i 's@^backup_content=.*@backup_content=db,web@' ./options.conf
  80. if [ -n "`echo ${desc_bk} | grep -Ew '1|2'`" ]; then
  81. while :; do echo
  82. echo "Please enter the directory for save the backup file: "
  83. read -e -p "(Default directory: ${backup_dir}): " new_backup_dir
  84. new_backup_dir=${new_backup_dir:-${backup_dir}}
  85. if [ -z "`echo ${new_backup_dir}| grep '^/'`" ]; then
  86. echo "${CWARNING}input error! ${CEND}"
  87. else
  88. break
  89. fi
  90. done
  91. sed -i "s@^backup_dir=.*@backup_dir=${new_backup_dir}@" ./options.conf
  92. fi
  93. while :; do echo
  94. echo "Please enter a valid backup number of days: "
  95. read -e -p "(Default days: 5): " expired_days
  96. expired_days=${expired_days:-5}
  97. [ -n "`echo ${expired_days} | sed -n "/^[0-9]\+$/p"`" ] && break || echo "${CWARNING}input error! Please only enter numbers! ${CEND}"
  98. done
  99. sed -i "s@^expired_days=.*@expired_days=${expired_days}@" ./options.conf
  100. if [ "${content_bk}" != '2' ]; then
  101. databases=`${db_install_dir}/bin/mysql -uroot -p$dbrootpwd -e "show databases\G" | grep Database | awk '{print $2}' | grep -Evw "(performance_schema|information_schema|mysql|sys)"`
  102. while :; do echo
  103. echo "Please enter one or more name for database, separate multiple database names with commas: "
  104. read -e -p "(Default database: `echo $databases | tr ' ' ','`) " db_name
  105. db_name=`echo ${db_name} | tr -d ' '`
  106. [ -z "${db_name}" ] && db_name="`echo $databases | tr ' ' ','`"
  107. D_tmp=0
  108. for D in `echo ${db_name} | tr ',' ' '`
  109. do
  110. [ -z "`echo $databases | grep -w $D`" ] && { echo "${CWARNING}$D was not exist! ${CEND}" ; D_tmp=1; }
  111. done
  112. [ "$D_tmp" != '1' ] && break
  113. done
  114. sed -i "s@^db_name=.*@db_name=${db_name}@" ./options.conf
  115. fi
  116. if [ "${content_bk}" != '1' ]; then
  117. websites=`ls ${wwwroot_dir}`
  118. while :; do echo
  119. echo "Please enter one or more name for website, separate multiple website names with commas: "
  120. read -e -p "(Default website: `echo $websites | tr ' ' ','`) " website_name
  121. website_name=`echo ${website_name} | tr -d ' '`
  122. [ -z "${website_name}" ] && website_name="`echo $websites | tr ' ' ','`"
  123. W_tmp=0
  124. for W in `echo ${website_name} | tr ',' ' '`
  125. do
  126. [ ! -e "${wwwroot_dir}/$W" ] && { echo "${CWARNING}${wwwroot_dir}/$W not exist! ${CEND}" ; W_tmp=1; }
  127. done
  128. [ "$W_tmp" != '1' ] && break
  129. done
  130. sed -i "s@^website_name=.*@website_name=${website_name}@" ./options.conf
  131. fi
  132. echo
  133. echo "You have to backup the content:"
  134. [ "${content_bk}" != '2' ] && echo "Database: ${CMSG}${db_name}${CEND}"
  135. [ "${content_bk}" != '1' ] && echo "Website: ${CMSG}${website_name}${CEND}"
  136. if [ -n "`echo ${desc_bk} | grep -w 2`" ]; then
  137. > tools/iplist.txt
  138. while :; do echo
  139. read -e -p "Please enter the remote host ip: " remote_ip
  140. [ -z "${remote_ip}" -o "${remote_ip}" == '127.0.0.1' ] && continue
  141. echo
  142. read -e -p "Please enter the remote host port(Default: 22) : " remote_port
  143. remote_port=${remote_port:-22}
  144. echo
  145. read -e -p "Please enter the remote host user(Default: root) : " remote_user
  146. remote_user=${remote_user:-root}
  147. echo
  148. read -e -p "Please enter the remote host password: " remote_password
  149. IPcode=$(echo "ibase=16;$(echo "${remote_ip}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  150. Portcode=$(echo "ibase=16;$(echo "${remote_port}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  151. PWcode=$(echo "ibase=16;$(echo "$remote_password" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
  152. [ -e "~/.ssh/known_hosts" ] && grep ${remote_ip} ~/.ssh/known_hosts | sed -i "/${remote_ip}/d" ~/.ssh/known_hosts
  153. ./tools/mssh.exp ${IPcode}P ${remote_user} ${PWcode}P ${Portcode}P true 10
  154. if [ $? -eq 0 ]; then
  155. [ -z "`grep ${remote_ip} tools/iplist.txt`" ] && echo "${remote_ip} ${remote_port} ${remote_user} $remote_password" >> tools/iplist.txt || echo "${CWARNING}${remote_ip} has been added! ${CEND}"
  156. while :; do
  157. read -e -p "Do you want to add more host ? [y/n]: " morehost_yn
  158. if [[ ! ${morehost_yn} =~ ^[y,n]$ ]]; then
  159. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  160. else
  161. break
  162. fi
  163. done
  164. [ "${morehost_yn}" == 'n' ] && break
  165. fi
  166. done
  167. fi
  168. if [ -n "`echo ${desc_bk} | grep -w 3`" ]; then
  169. if [ ! -e "/usr/local/bin/ossutil" ]; then
  170. wget -qc http://gosspublic.alicdn.com/ossutil/1.4.2/ossutil${OS_BIT} -O /usr/local/bin/ossutil
  171. chmod +x /usr/local/bin/ossutil
  172. fi
  173. while :; do echo
  174. echo 'Please select your backup aliyun datacenter:'
  175. echo -e "\t ${CMSG}1${CEND}. cn-hangzhou-华东 1 (杭州) ${CMSG}2${CEND}. cn-shanghai-华东 2 (上海)"
  176. echo -e "\t ${CMSG}3${CEND}. cn-qingdao-华北 1 (青岛) ${CMSG}4${CEND}. cn-beijing-华北 2 (北京)"
  177. echo -e "\t ${CMSG}5${CEND}. cn-zhangjiakou-华北 3 (张家口) ${CMSG}6${CEND}. cn-huhehaote-华北 5(呼和浩特)"
  178. echo -e "\t ${CMSG}7${CEND}. cn-shenzhen-华南 1 (深圳) ${CMSG}8${CEND}. cn-hongkong-香港"
  179. echo -e "\t ${CMSG}9${CEND}. us-west-美西 1 (硅谷) ${CMSG}10${CEND}. us-east-美东 1 (弗吉尼亚)"
  180. echo -e "\t${CMSG}11${CEND}. ap-southeast-亚太东南 1 (新加坡) ${CMSG}12${CEND}. ap-southeast-亚太东南 2 (悉尼)"
  181. echo -e "\t${CMSG}13${CEND}. ap-southeast-亚太东南 3 (吉隆坡) ${CMSG}14${CEND}. ap-southeast-亚太东南 5 (雅加达)"
  182. echo -e "\t${CMSG}15${CEND}. ap-northeast-亚太东北 1 (日本) ${CMSG}16${CEND}. ap-south-亚太南部 1 (孟买)"
  183. echo -e "\t${CMSG}17${CEND}. eu-central-欧洲中部 1 (法兰克福) ${CMSG}18${CEND}. me-east-中东东部 1 (迪拜)"
  184. read -e -p "Please input a number:(Default 1 press Enter) " Location
  185. Location=${Location:-1}
  186. if [[ "${Location}" =~ ^[1-9]$|^1[0-8]$ ]]; then
  187. break
  188. else
  189. echo "${CWARNING}input error! Please only input number 1~18${CEND}"
  190. fi
  191. done
  192. [ "${Location}" == '1' ] && Host=oss-cn-hangzhou-internal.aliyuncs.com
  193. [ "${Location}" == '2' ] && Host=oss-cn-shanghai-internal.aliyuncs.com
  194. [ "${Location}" == '3' ] && Host=oss-cn-qingdao-internal.aliyuncs.com
  195. [ "${Location}" == '4' ] && Host=oss-cn-beijing-internal.aliyuncs.com
  196. [ "${Location}" == '5' ] && Host=oss-cn-zhangjiakou-internal.aliyuncs.com
  197. [ "${Location}" == '6' ] && Host=oss-cn-huhehaote-internal.aliyuncs.com
  198. [ "${Location}" == '7' ] && Host=oss-cn-shenzhen-internal.aliyuncs.com
  199. [ "${Location}" == '8' ] && Host=oss-cn-hongkong-internal.aliyuncs.com
  200. [ "${Location}" == '9' ] && Host=oss-us-west-1-internal.aliyuncs.com
  201. [ "${Location}" == '10' ] && Host=oss-us-east-1-internal.aliyuncs.com
  202. [ "${Location}" == '11' ] && Host=oss-ap-southeast-1-internal.aliyuncs.com
  203. [ "${Location}" == '12' ] && Host=oss-ap-southeast-2-internal.aliyuncs.com
  204. [ "${Location}" == '13' ] && Host=oss-ap-southeast-3-internal.aliyuncs.com
  205. [ "${Location}" == '14' ] && Host=oss-ap-southeast-5-internal.aliyuncs.com
  206. [ "${Location}" == '15' ] && Host=oss-ap-northeast-1-internal.aliyuncs.com
  207. [ "${Location}" == '16' ] && Host=oss-ap-south-1-internal.aliyuncs.com
  208. [ "${Location}" == '17' ] && Host=oss-eu-central-1-internal.aliyuncs.com
  209. [ "${Location}" == '18' ] && Host=oss-me-east-1-internal.aliyuncs.com
  210. [ "$(./include/check_port.py ${Host} 80)" == "False" ] && Host=`echo ${Host} | sed 's@-internal@@g'`
  211. [ -e "/root/.ossutilconfig" ] && rm -f /root/.ossutilconfig
  212. while :; do echo
  213. read -e -p "Please enter the aliyun oss Access Key ID: " KeyID
  214. [ -z "${KeyID}" ] && continue
  215. echo
  216. read -e -p "Please enter the aliyun oss Access Key Secret: " KeySecret
  217. [ -z "${KeySecret}" ] && continue
  218. /usr/local/bin/ossutil ls -e ${Host} -i ${KeyID} -k ${KeySecret} >/dev/null 2>&1
  219. if [ $? -eq 0 ];then
  220. /usr/local/bin/ossutil config -e ${Host} -i ${KeyID} -k ${KeySecret} >/dev/null 2>&1
  221. while :; do echo
  222. read -e -p "Please enter the aliyun oss bucket: " Bucket
  223. /usr/local/bin/ossutil mb oss://${Bucket} >/dev/null 2>&1
  224. [ $? -eq 0 ] && { echo "${CMSG}[${Bucket}] createbucket OK${CEND}"; sed -i "s@^oss_bucket=.*@oss_bucket=${Bucket}@" ./options.conf; break; } || echo "${CWARNING}[${Bucket}] already exists, You need to use the OSS Console to create a bucket for storing.${CEND}"
  225. done
  226. break
  227. fi
  228. done
  229. fi
  230. if [ -n "`echo ${desc_bk} | grep -w 4`" ]; then
  231. Install_Python
  232. [ ! -e "${python_install_dir}/lib/coscmd" ] && ${python_install_dir}/bin/pip install coscmd >/dev/null 2>&1
  233. while :; do echo
  234. echo 'Please select your backup qcloud datacenter:'
  235. echo -e "\t ${CMSG} 1${CEND}. ap-beijing-1-北京一区(华北) ${CMSG}2${CEND}. ap-beijing-北京"
  236. echo -e "\t ${CMSG} 3${CEND}. ap-shanghai-上海(华东) ${CMSG}4${CEND}. ap-guangzhou-广州(华南)"
  237. echo -e "\t ${CMSG} 5${CEND}. ap-chengdu-成都(西南) ${CMSG}6${CEND}. ap-chongqing-重庆"
  238. echo -e "\t ${CMSG} 7${CEND}. ap-singapore-新加坡 ${CMSG}8${CEND}. ap-hongkong-香港"
  239. echo -e "\t ${CMSG} 9${CEND}. na-toronto-多伦多 ${CMSG}10${CEND}. eu-frankfurt-法兰克福"
  240. echo -e "\t ${CMSG}11${CEND}. ap-mumbai-孟买 ${CMSG}12${CEND}. ap-seoul-首尔"
  241. echo -e "\t ${CMSG}13${CEND}. na-siliconvalley-硅谷 ${CMSG}14${CEND}. na-ashburn-弗吉尼亚"
  242. echo -e "\t ${CMSG}15${CEND}. ap-bangkok-曼谷 ${CMSG}16${CEND}. eu-moscow-莫斯科"
  243. echo -e "\t ${CMSG}17${CEND}. ap-tokyo-东京"
  244. read -e -p "Please input a number:(Default 1 press Enter) " Location
  245. Location=${Location:-1}
  246. if [[ "${Location}" =~ ^[1-9]$|^1[0-7]$ ]]; then
  247. break
  248. else
  249. echo "${CWARNING}input error! Please only input number 1~17${CEND}"
  250. fi
  251. done
  252. [ "${Location}" == '1' ] && REGION='ap-beijing-1'
  253. [ "${Location}" == '2' ] && REGION='ap-beijing'
  254. [ "${Location}" == '3' ] && REGION='ap-shanghai'
  255. [ "${Location}" == '4' ] && REGION='ap-guangzhou'
  256. [ "${Location}" == '5' ] && REGION='ap-chengdu'
  257. [ "${Location}" == '6' ] && REGION='ap-chongqing'
  258. [ "${Location}" == '7' ] && REGION='ap-singapore'
  259. [ "${Location}" == '8' ] && REGION='ap-hongkong'
  260. [ "${Location}" == '9' ] && REGION='na-toronto'
  261. [ "${Location}" == '10' ] && REGION='eu-frankfurt'
  262. [ "${Location}" == '11' ] && REGION='ap-mumbai'
  263. [ "${Location}" == '12' ] && REGION='ap-seoul'
  264. [ "${Location}" == '13' ] && REGION='na-siliconvalley'
  265. [ "${Location}" == '14' ] && REGION='na-ashburn'
  266. [ "${Location}" == '15' ] && REGION='ap-bangkok'
  267. [ "${Location}" == '16' ] && REGION='eu-moscow'
  268. [ "${Location}" == '17' ] && REGION='ap-tokyo'
  269. while :; do echo
  270. read -e -p "Please enter the Qcloud COS APPID: " APPID
  271. [[ ! "${APPID}" =~ ^[0-9]+$ ]] && { echo "${CWARNING}input error, must be a number${CEND}"; continue; }
  272. echo
  273. read -e -p "Please enter the Qcloud COS SECRET_ID: " SECRET_ID
  274. [ -z "${SECRET_ID}" ] && continue
  275. echo
  276. read -e -p "Please enter the Qcloud COS SECRET_KEY: " SECRET_KEY
  277. [ -z "${SECRET_KEY}" ] && continue
  278. echo
  279. read -e -p "Please enter the Qcloud COS BUCKET: " BUCKET
  280. if [[ ${BUCKET} =~ "-${APPID}"$ ]]; then
  281. Bucket=${BUCKET}
  282. else
  283. [ -z "${BUCKET}" ] && continue
  284. echo
  285. Bucket=${BUCKET}-${APPID}
  286. fi
  287. ${python_install_dir}/bin/coscmd config -u ${APPID} -a ${SECRET_ID} -s ${SECRET_KEY} -r ${REGION} -b ${Bucket} >/dev/null 2>&1
  288. ${python_install_dir}/bin/coscmd list >/dev/null 2>&1
  289. if [ $? -eq 0 ];then
  290. echo "${CMSG}APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET OK${CEND}"
  291. echo
  292. break
  293. else
  294. ${python_install_dir}/bin/coscmd -b ${Bucket} createbucket >/dev/null 2>&1
  295. if [ $? -eq 0 ];then
  296. echo "${CMSG}APPID/SECRET_ID/SECRET_KEY/REGION OK, You createbucket ${Bucket}${CEND}"
  297. echo
  298. break
  299. else
  300. echo "${CWARNING}input error! APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET invalid${CEND}"
  301. continue
  302. fi
  303. fi
  304. done
  305. fi
  306. if [ -n "`echo ${desc_bk} | grep -w 5`" ]; then
  307. if [ ! -e "/usr/local/bin/upx" ]; then
  308. if [ "${OS_BIT}" == '64' ]; then
  309. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx-linux-amd64-v0.2.3 -O /usr/local/bin/upx
  310. elif [ "${OS_BIT}" == '32' ]; then
  311. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx-linux-386-v0.2.3 -O /usr/local/bin/upx
  312. fi
  313. chmod +x /usr/local/bin/upx
  314. fi
  315. while :; do echo
  316. read -e -p "Please enter the upyun ServiceName: " ServiceName
  317. [ -z "${ServiceName}" ] && continue
  318. echo
  319. read -e -p "Please enter the upyun Operator: " Operator
  320. [ -z "${Operator}" ] && continue
  321. echo
  322. read -e -p "Please enter the upyun Password: " Password
  323. [ -z "${Password}" ] && continue
  324. echo
  325. /usr/local/bin/upx login ${ServiceName} ${Operator} ${Password} >/dev/null 2>&1
  326. if [ $? = 0 ]; then
  327. echo "${CMSG}ServiceName/Operator/Password OK${CEND}"
  328. echo
  329. break
  330. else
  331. echo "${CWARNING}input error! ServiceName/Operator/Password invalid${CEND}"
  332. fi
  333. done
  334. fi
  335. if [ -n "`echo ${desc_bk} | grep -w 6`" ]; then
  336. if [ ! -e "/usr/local/bin/qrsctl" ]; then
  337. if [ "${OS_BIT}" == '64' ]; then
  338. wget -qc http://devtools.qiniu.com/linux/amd64/qrsctl -O /usr/local/bin/qrsctl
  339. elif [ "${OS_BIT}" == '32' ]; then
  340. wget -qc http://devtools.qiniu.com/linux/386/qrsctl -O /usr/local/bin/qrsctl
  341. fi
  342. chmod +x /usr/local/bin/qrsctl
  343. fi
  344. if [ ! -e "/usr/local/bin/qshell" ]; then
  345. wget -qc http://devtools.qiniu.com/qshell-v2.3.5.zip -O /tmp/qshell-v2.3.5.zip
  346. unzip -q /tmp/qshell-v2.3.5.zip -d /tmp/
  347. if [ "${OS_BIT}" == '64' ]; then
  348. /bin/cp /tmp/qshell-linux-x64 /usr/local/bin/qshell
  349. elif [ "${OS_BIT}" == '32' ]; then
  350. /bin/cp /tmp/qshell-linux-x86 /usr/local/bin/qshell
  351. fi
  352. chmod +x /usr/local/bin/qshell
  353. rm -f /tmp/qshell*
  354. fi
  355. while :; do echo
  356. echo 'Please select your backup qiniu datacenter:'
  357. echo -e "\t ${CMSG} 1${CEND}. 华东 ${CMSG}2${CEND}. 华北"
  358. echo -e "\t ${CMSG} 3${CEND}. 华南 ${CMSG}4${CEND}. 北美"
  359. echo -e "\t ${CMSG} 5${CEND}. 东南亚"
  360. read -e -p "Please input a number:(Default 1 press Enter) " Location
  361. Location=${Location:-1}
  362. if [[ "${Location}" =~ ^[1-5]$ ]]; then
  363. break
  364. else
  365. echo "${CWARNING}input error! Please only input number 1~5${CEND}"
  366. fi
  367. done
  368. [ "${Location}" == '1' ] && zone='z0'
  369. [ "${Location}" == '2' ] && zone='z1'
  370. [ "${Location}" == '3' ] && zone='z2'
  371. [ "${Location}" == '4' ] && zone='na0'
  372. [ "${Location}" == '5' ] && zone='as0'
  373. while :; do echo
  374. read -e -p "Please enter the qiniu AccessKey: " AccessKey
  375. [ -z "${AccessKey}" ] && continue
  376. echo
  377. read -e -p "Please enter the qiniu SecretKey: " SecretKey
  378. [ -z "${SecretKey}" ] && continue
  379. echo
  380. read -e -p "Please enter the qiniu bucket: " Bucket
  381. [ -z "${Bucket}" ] && continue
  382. echo
  383. /usr/local/bin/qshell account ${AccessKey} ${SecretKey}
  384. /usr/local/bin/qrsctl login ${AccessKey} ${SecretKey}
  385. if /usr/local/bin/qrsctl bucketinfo ${Bucket} > /dev/null 2>&1; then
  386. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${Bucket}@" ./options.conf
  387. echo "${CMSG}AccessKey/SecretKey OK${CEND}"
  388. echo
  389. break
  390. elif /usr/local/bin/qrsctl mkbucket ${Bucket} ${zone} > /dev/null 2>&1; then
  391. /usr/local/bin/qrsctl private ${Bucket} 1
  392. echo "${CMSG}[${Bucket}] createbucket OK${CEND}"
  393. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${Bucket}@" ./options.conf
  394. echo "${CMSG}AccessKey/SecretKey OK${CEND}"
  395. echo
  396. break
  397. else
  398. echo "${CWARNING}input error! AccessKey/SecretKey invalid${CEND}"
  399. fi
  400. done
  401. fi
  402. if [ -n "`echo ${desc_bk} | grep -w 7`" ]; then
  403. if [ ! -e "/usr/local/bin/gdrive" ]; then
  404. if [ "${OS_BIT}" == '64' ]; then
  405. wget -qc http://mirrors.linuxeye.com/oneinstack/src/gdrive-linux-x64 -O /usr/local/bin/gdrive
  406. elif [ "${OS_BIT}" == '32' ]; then
  407. wget -qc http://mirrors.linuxeye.com/oneinstack/src/gdrive-linux-386 -O /usr/local/bin/gdrive
  408. fi
  409. chmod +x /usr/local/bin/gdrive
  410. fi
  411. while :; do echo
  412. if gdrive about; then
  413. break
  414. fi
  415. done
  416. fi