1
0

backup_setup.sh 18 KB

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