backup_setup.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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/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/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. read -e -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 -e -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 -e -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 -e -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 -e -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 -e -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 -e -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 -e -p "Please enter the remote host port(Default: 22) : " remote_port
  134. [ -z "${remote_port}" ] && remote_port=22
  135. echo
  136. read -e -p "Please enter the remote host user(Default: root) : " remote_user
  137. [ -z "${remote_user}" ] && remote_user=root
  138. echo
  139. read -e -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 -e -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. wget -qc http://gosspublic.alicdn.com/ossutil/1.4.1/ossutil${OS_BIT} -O /usr/local/bin/ossutil
  162. chmod +x /usr/local/bin/ossutil
  163. fi
  164. while :; do echo
  165. echo 'Please select your backup aliyun datacenter:'
  166. echo -e "\t ${CMSG}1${CEND}. cn-hangzhou-华东 1 (杭州) ${CMSG}2${CEND}. cn-shanghai-华东 2 (上海)"
  167. echo -e "\t ${CMSG}3${CEND}. cn-qingdao-华北 1 (青岛) ${CMSG}4${CEND}. cn-beijing-华北 2 (北京)"
  168. echo -e "\t ${CMSG}5${CEND}. cn-zhangjiakou-华北 3 (张家口) ${CMSG}6${CEND}. cn-huhehaote-华北 5(呼和浩特)"
  169. echo -e "\t ${CMSG}7${CEND}. cn-shenzhen-华南 1 (深圳) ${CMSG}8${CEND}. cn-hongkong-香港"
  170. echo -e "\t ${CMSG}9${CEND}. us-west-美西 1 (硅谷) ${CMSG}10${CEND}. us-east-美东 1 (弗吉尼亚)"
  171. echo -e "\t${CMSG}11${CEND}. ap-southeast-亚太东南 1 (新加坡) ${CMSG}12${CEND}. ap-southeast-亚太东南 2 (悉尼)"
  172. echo -e "\t${CMSG}13${CEND}. ap-southeast-亚太东南 3 (吉隆坡) ${CMSG}14${CEND}. ap-southeast-亚太东南 5 (雅加达)"
  173. echo -e "\t${CMSG}15${CEND}. ap-northeast-亚太东北 1 (日本) ${CMSG}16${CEND}. ap-south-亚太南部 1 (孟买)"
  174. echo -e "\t${CMSG}17${CEND}. eu-central-欧洲中部 1 (法兰克福) ${CMSG}18${CEND}. me-east-中东东部 1 (迪拜)"
  175. read -e -p "Please input a number:(Default 1 press Enter) " Location
  176. [ -z "${Location}" ] && Location=1
  177. if [[ "${Location}" =~ ^[1-9]$|^1[0-8]$ ]]; then
  178. break
  179. else
  180. echo "${CWARNING}input error! Please only input number 1~18${CEND}"
  181. fi
  182. done
  183. [ "${Location}" == '1' ] && Host=oss-cn-hangzhou-internal.aliyuncs.com
  184. [ "${Location}" == '2' ] && Host=oss-cn-shanghai-internal.aliyuncs.com
  185. [ "${Location}" == '3' ] && Host=oss-cn-qingdao-internal.aliyuncs.com
  186. [ "${Location}" == '4' ] && Host=oss-cn-beijing-internal.aliyuncs.com
  187. [ "${Location}" == '5' ] && Host=oss-cn-zhangjiakou-internal.aliyuncs.com
  188. [ "${Location}" == '6' ] && Host=oss-cn-huhehaote-internal.aliyuncs.com
  189. [ "${Location}" == '7' ] && Host=oss-cn-shenzhen-internal.aliyuncs.com
  190. [ "${Location}" == '8' ] && Host=oss-cn-hongkong-internal.aliyuncs.com
  191. [ "${Location}" == '9' ] && Host=oss-us-west-1-internal.aliyuncs.com
  192. [ "${Location}" == '10' ] && Host=oss-us-east-1-internal.aliyuncs.com
  193. [ "${Location}" == '11' ] && Host=oss-ap-southeast-1-internal.aliyuncs.com
  194. [ "${Location}" == '12' ] && Host=oss-ap-southeast-2-internal.aliyuncs.com
  195. [ "${Location}" == '13' ] && Host=oss-ap-southeast-3-internal.aliyuncs.com
  196. [ "${Location}" == '14' ] && Host=oss-ap-southeast-5-internal.aliyuncs.com
  197. [ "${Location}" == '15' ] && Host=oss-ap-northeast-1-internal.aliyuncs.com
  198. [ "${Location}" == '16' ] && Host=oss-ap-south-1-internal.aliyuncs.com
  199. [ "${Location}" == '17' ] && Host=oss-eu-central-1-internal.aliyuncs.com
  200. [ "${Location}" == '18' ] && Host=oss-me-east-1-internal.aliyuncs.com
  201. [ "$(./include/check_port.py ${Host} 80)" == "False" ] && Host=`echo ${Host} | sed 's@-internal@@g'`
  202. [ -e "/root/.ossutilconfig" ] && rm -f /root/.ossutilconfig
  203. while :; do echo
  204. read -e -p "Please enter the aliyun oss Access Key ID: " KeyID
  205. [ -z "${KeyID}" ] && continue
  206. echo
  207. read -e -p "Please enter the aliyun oss Access Key Secret: " KeySecret
  208. [ -z "${KeySecret}" ] && continue
  209. /usr/local/bin/ossutil ls -e ${Host} -i ${KeyID} -k ${KeySecret} >/dev/null 2>&1
  210. if [ $? -eq 0 ];then
  211. /usr/local/bin/ossutil config -e ${Host} -i ${KeyID} -k ${KeySecret} >/dev/null 2>&1
  212. while :; do echo
  213. read -e -p "Please enter the aliyun oss bucket: " Bucket
  214. /usr/local/bin/ossutil mb oss://${Bucket} >/dev/null 2>&1
  215. [ $? -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}"
  216. done
  217. break
  218. fi
  219. done
  220. fi
  221. if [ `echo ${desc_bk} | grep -e 4` ]; then
  222. [ ! -e "${python_install_dir}/bin/python" ] && Install_Python
  223. [ ! -e "${python_install_dir}/lib/coscmd" ] && ${python_install_dir}/bin/pip install coscmd >/dev/null 2>&1
  224. while :; do echo
  225. echo 'Please select your backup qcloud datacenter:'
  226. echo -e "\t ${CMSG} 1${CEND}. ap-beijing-1-北京一区(华北) ${CMSG}2${CEND}. ap-beijing-北京"
  227. echo -e "\t ${CMSG} 3${CEND}. ap-shanghai-上海(华东) ${CMSG}4${CEND}. ap-guangzhou-广州(华南)"
  228. echo -e "\t ${CMSG} 5${CEND}. ap-chengdu-成都(西南) ${CMSG}6${CEND}. ap-chongqing-重庆"
  229. echo -e "\t ${CMSG} 7${CEND}. ap-singapore-新加坡 ${CMSG}8${CEND}. ap-hongkong-香港"
  230. echo -e "\t ${CMSG} 9${CEND}. na-toronto-多伦多 ${CMSG}10${CEND}. eu-frankfurt-法兰克福"
  231. echo -e "\t ${CMSG}11${CEND}. ap-mumbai-孟买 ${CMSG}12${CEND}. ap-seoul-首尔"
  232. echo -e "\t ${CMSG}13${CEND}. na-siliconvalley-硅谷 ${CMSG}14${CEND}. na-ashburn-弗吉尼亚"
  233. echo -e "\t ${CMSG}15${CEND}. ap-bangkok-曼谷 ${CMSG}16${CEND}. eu-moscow-莫斯科"
  234. echo -e "\t ${CMSG}17${CEND}. ap-tokyo-东京"
  235. read -e -p "Please input a number:(Default 1 press Enter) " Location
  236. [ -z "${Location}" ] && Location=1
  237. if [[ "${Location}" =~ ^[1-9]$|^1[0-7]$ ]]; then
  238. break
  239. else
  240. echo "${CWARNING}input error! Please only input number 1~17${CEND}"
  241. fi
  242. done
  243. [ "${Location}" == '1' ] && region='ap-beijing-1'
  244. [ "${Location}" == '2' ] && region='ap-beijing'
  245. [ "${Location}" == '3' ] && region='ap-shanghai'
  246. [ "${Location}" == '4' ] && region='ap-guangzhou'
  247. [ "${Location}" == '5' ] && region='ap-chengdu'
  248. [ "${Location}" == '6' ] && region='ap-chongqing'
  249. [ "${Location}" == '7' ] && region='ap-singapore'
  250. [ "${Location}" == '8' ] && region='ap-hongkong'
  251. [ "${Location}" == '9' ] && region='na-toronto'
  252. [ "${Location}" == '10' ] && region='eu-frankfurt'
  253. [ "${Location}" == '11' ] && region='ap-mumbai'
  254. [ "${Location}" == '12' ] && region='ap-seoul'
  255. [ "${Location}" == '13' ] && region='na-siliconvalley'
  256. [ "${Location}" == '14' ] && region='na-ashburn'
  257. [ "${Location}" == '15' ] && region='ap-bangkok'
  258. [ "${Location}" == '16' ] && region='eu-moscow'
  259. [ "${Location}" == '17' ] && region='ap-tokyo'
  260. while :; do echo
  261. read -e -p "Please enter the Qcloud COS APPID: " APPID
  262. [ -z "${APPID}" ] && continue
  263. echo
  264. read -e -p "Please enter the Qcloud COS SecretId: " SecretId
  265. [ -z "${SecretId}" ] && continue
  266. echo
  267. read -e -p "Please enter the Qcloud COS SecretKey: " SecretKey
  268. [ -z "$SecretKey" ] && continue
  269. echo
  270. read -e -p "Please enter the Qcloud COS bucket: " bucket
  271. [ -z "${bucket}" ] && continue
  272. echo
  273. ${python_install_dir}/bin/coscmd config -u ${APPID} -a ${SecretId} -s $SecretKey -r $region -b ${bucket} >/dev/null 2>&1
  274. ${python_install_dir}/bin/coscmd list >/dev/null 2>&1
  275. if [ $? = 0 ]; then
  276. echo "${CMSG}APPID/SecretId/SecretKey/region/bucket OK${CEND}"
  277. echo
  278. break
  279. else
  280. echo "${CWARNING}input error! APPID/SecretId/SecretKey/region/bucket invalid${CEND}"
  281. fi
  282. done
  283. fi
  284. if [ `echo ${desc_bk} | grep -e 5` ]; then
  285. if [ ! -e "/usr/local/bin/upx" ]; then
  286. if [ "${OS_BIT}" == '64' ]; then
  287. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx-linux-amd64-v0.2.3 -O /usr/local/bin/upx
  288. elif [ "${OS_BIT}" == '32' ]; then
  289. wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx-linux-386-v0.2.3 -O /usr/local/bin/upx
  290. fi
  291. chmod +x /usr/local/bin/upx
  292. fi
  293. while :; do echo
  294. read -e -p "Please enter the upyun ServiceName: " ServiceName
  295. [ -z "${ServiceName}" ] && continue
  296. echo
  297. read -e -p "Please enter the upyun Operator: " Operator
  298. [ -z "${Operator}" ] && continue
  299. echo
  300. read -e -p "Please enter the upyun Password: " Password
  301. [ -z "${Password}" ] && continue
  302. echo
  303. /usr/local/bin/upx login ${ServiceName} ${Operator} ${Password} >/dev/null 2>&1
  304. if [ $? = 0 ]; then
  305. echo "${CMSG}ServiceName/Operator/Password OK${CEND}"
  306. echo
  307. break
  308. else
  309. echo "${CWARNING}input error! ServiceName/Operator/Password invalid${CEND}"
  310. fi
  311. done
  312. fi
  313. if [ `echo ${desc_bk} | grep -e 6` ]; then
  314. if [ ! -e "/usr/local/bin/qrsctl" ]; then
  315. if [ "${OS_BIT}" == '64' ]; then
  316. wget -qc http://devtools.qiniu.com/linux/amd64/qrsctl -O /usr/local/bin/qrsctl
  317. elif [ "${OS_BIT}" == '32' ]; then
  318. wget -qc http://devtools.qiniu.com/linux/386/qrsctl -O /usr/local/bin/qrsctl
  319. fi
  320. chmod +x /usr/local/bin/qrsctl
  321. fi
  322. if [ ! -e "/usr/local/bin/qshell" ]; then
  323. wget -qc http://devtools.qiniu.com/qshell-v2.1.8.zip -O /tmp/qshell-v2.1.8.zip
  324. unzip -q /tmp/qshell-v2.1.8.zip -d /tmp/
  325. if [ "${OS_BIT}" == '64' ]; then
  326. /bin/cp /tmp/qshell-linux-x64 /usr/local/bin/qshell
  327. elif [ "${OS_BIT}" == '32' ]; then
  328. /bin/cp /tmp/qshell-linux-x86 /usr/local/bin/qshell
  329. fi
  330. chmod +x /usr/local/bin/qshell
  331. rm -f /tmp/qshell*
  332. fi
  333. while :; do echo
  334. echo 'Please select your backup qiniu datacenter:'
  335. echo -e "\t ${CMSG} 1${CEND}. 华东 ${CMSG}2${CEND}. 华北"
  336. echo -e "\t ${CMSG} 3${CEND}. 华南 ${CMSG}4${CEND}. 北美"
  337. echo -e "\t ${CMSG} 5${CEND}. 东南亚"
  338. read -e -p "Please input a number:(Default 1 press Enter) " Location
  339. [ -z "${Location}" ] && Location=1
  340. if [[ "${Location}" =~ ^[1-5]$ ]]; then
  341. break
  342. else
  343. echo "${CWARNING}input error! Please only input number 1~5${CEND}"
  344. fi
  345. done
  346. [ "${Location}" == '1' ] && zone='z0'
  347. [ "${Location}" == '2' ] && zone='z1'
  348. [ "${Location}" == '3' ] && zone='z2'
  349. [ "${Location}" == '4' ] && zone='na0'
  350. [ "${Location}" == '5' ] && zone='as0'
  351. while :; do echo
  352. read -e -p "Please enter the qiniu AccessKey: " AccessKey
  353. [ -z "${AccessKey}" ] && continue
  354. echo
  355. read -e -p "Please enter the qiniu SecretKey: " SecretKey
  356. [ -z "${SecretKey}" ] && continue
  357. echo
  358. read -e -p "Please enter the qiniu bucket: " bucket
  359. [ -z "${bucket}" ] && continue
  360. echo
  361. /usr/local/bin/qshell account ${AccessKey} ${SecretKey}
  362. /usr/local/bin/qrsctl login ${AccessKey} ${SecretKey}
  363. if /usr/local/bin/qrsctl bucketinfo ${bucket} > /dev/null 2>&1; then
  364. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${bucket}@" ./options.conf
  365. echo "${CMSG}AccessKey/SecretKey OK${CEND}"
  366. echo
  367. break
  368. elif /usr/local/bin/qrsctl mkbucket ${bucket} ${zone} > /dev/null 2>&1; then
  369. /usr/local/bin/qrsctl private ${bucket} 1
  370. echo "${CMSG}[${bucket}] createbucket OK${CEND}"
  371. sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${bucket}@" ./options.conf
  372. echo "${CMSG}AccessKey/SecretKey OK${CEND}"
  373. echo
  374. break
  375. else
  376. echo "${CWARNING}input error! AccessKey/SecretKey invalid${CEND}"
  377. fi
  378. done
  379. fi