@@ -27,7 +27,7 @@ FC23_HYPER="hyper-container-0.6-1.fc23.x86_64"
2727# ######### Constant ##########
2828SUPPORT_DISTRO=(debian ubuntu fedora centos linuxmint)
2929LINUX_MINT_CODE=(rafaela rebecca qiana)
30- UBUNTU_CODE=(trusty utopic vivid wily)
30+ UBUNTU_CODE=(trusty utopic vivid wily xenial )
3131DEBIAN_CODE=(jessie wheezy)
3232CENTOS_VER=(6 7)
3333FEDORA_VER=(20 21 22 23)
@@ -101,7 +101,7 @@ COMMENT
101101 fi
102102}
103103check_user () {
104- if [ " ${CURRENT_USER} " != " root" ]; then
104+ if [[ " ${CURRENT_USER} " != " root" ] ]; then
105105 if (command_exist sudo); then
106106 BASH_C=" sudo -E bash -c"
107107 else
@@ -113,13 +113,13 @@ check_user() {
113113}
114114check_deps () {
115115 show_message info " Check dependency "
116- check_deps_qemu || check_deps_xen || exit ${${ ERR_NO_HYPERVISOR[0]} }
116+ check_deps_qemu || check_deps_xen || exit ${ERR_NO_HYPERVISOR[0]}
117117 check_deps_initsystem
118118 show_message done " Done"
119119}
120120check_os_platform () {
121121 ARCH=" $( uname -m) "
122- if [ " ${ARCH} " != " x86_64" ]; then
122+ if [[ " ${ARCH} " != " x86_64" ] ]; then
123123 show_message error " ${ERR_NOT_SUPPORT_PLATFORM[1]} " && exit ${ERR_NOT_SUPPORT_PLATFORM[0]}
124124 fi
125125}
@@ -130,34 +130,34 @@ check_os_distro() {
130130 LSB_VER=" $( lsb_release -sr) "
131131 LSB_CODE=" $( lsb_release -sc) "
132132 fi
133- if [ -z " ${LSB_DISTRO} " ]; then
134- if [ -r /etc/lsb-release ]; then
133+ if [[ -z " ${LSB_DISTRO} " ] ]; then
134+ if [[ -r /etc/lsb-release ] ]; then
135135 LSB_DISTRO=" $( . /etc/lsb-release && echo " ${DISTRIB_ID} " ) "
136136 LSB_VER=" $( . /etc/lsb-release && echo " ${DISTRIB_RELEASE} " ) "
137137 LSB_CODE=" $( . /etc/lsb-release && echo " ${DISTRIB_CODENAME} " ) "
138- elif [ -r /etc/os-release ]; then
138+ elif [[ -r /etc/os-release ] ]; then
139139 LSB_DISTRO=" $( . /etc/os-release && echo " $ID " ) "
140140 LSB_VER=" $( . /etc/os-release && echo " $VERSION_ID " ) "
141- elif [ -r /etc/fedora-release ]; then
141+ elif [[ -r /etc/fedora-release ] ]; then
142142 LSB_DISTRO=" fedora"
143- elif [ -r /etc/debian_version ]; then
143+ elif [[ -r /etc/debian_version ] ]; then
144144 LSB_DISTRO=" Debian"
145145 LSB_VER=" $( cat /etc/debian_version) "
146- elif [ -r /etc/centos-release ]; then
146+ elif [[ -r /etc/centos-release ] ]; then
147147 LSB_DISTRO=" CentOS"
148148 LSB_VER=" $( cat /etc/centos-release | cut -d' ' -f3) "
149149 fi
150150 fi
151151 LSB_DISTRO=$( echo " ${LSB_DISTRO} " | tr ' [:upper:]' ' [:lower:]' )
152- if [ " ${LSB_DISTRO} " == " debian" ]; then
152+ if [[ " ${LSB_DISTRO} " == " debian" ] ]; then
153153 case ${LSB_VER} in
154154 8) LSB_CODE=" jessie" ;;
155155 7) LSB_CODE=" wheezy" ;;
156156 esac
157157 fi
158158 case " ${LSB_DISTRO} " in
159159 linuxmint)
160- if [ " ${LSB_DISTRO} " == " linuxmint" ]
160+ if [[ " ${LSB_DISTRO} " == " linuxmint" ] ]
161161 then SUPPORT_CODE_LIST=" ${LINUX_MINT_CODE[@]} " ;
162162 fi
163163 if (echo " ${SUPPORT_CODE_LIST} " | grep -vqw " ${LSB_CODE} " ); then
@@ -166,7 +166,7 @@ check_os_distro() {
166166 fi
167167 ;;
168168 ubuntu|debian)
169- if [ " ${LSB_DISTRO} " == " ubuntu" ]
169+ if [[ " ${LSB_DISTRO} " == " ubuntu" ] ]
170170 then SUPPORT_CODE_LIST=" ${UBUNTU_CODE[@]} " ;
171171 else SUPPORT_CODE_LIST=" ${DEBIAN_CODE[@]} " ;
172172 fi
@@ -177,7 +177,7 @@ check_os_distro() {
177177 ;;
178178 centos|fedora)
179179 CMAJOR=$( echo ${LSB_VER} | cut -d" ." -f1 )
180- if [ " ${LSB_DISTRO} " == " centos" ]
180+ if [[ " ${LSB_DISTRO} " == " centos" ] ]
181181 then SUPPORT_VER_LIST=" ${CENTOS_VER[@]} " ;
182182 else SUPPORT_VER_LIST=" ${FEDORA_VER[@]} " ;
183183 fi
@@ -186,7 +186,7 @@ check_os_distro() {
186186 exit ${ERR_NOT_SUPPORT_DISTRO_VERSION[0]}
187187 fi
188188 ;;
189- * ) if [ ! -z ${LSB_DISTRO} ]; then echo -e -n " \nCurrent OS is '${LSB_DISTRO} ${LSB_VER} (${LSB_CODE} )'" ;
189+ * ) if [[ ! -z ${LSB_DISTRO} ] ]; then echo -e -n " \nCurrent OS is '${LSB_DISTRO} ${LSB_VER} (${LSB_CODE} )'" ;
190190 else echo -e -n " \nCan not detect OS type" ; fi
191191 show_message error " ${ERR_NOT_SUPPORT_DISTRO[1]} "
192192 exit ${ERR_NOT_SUPPORT_DISTRO[0]}
@@ -196,12 +196,12 @@ check_os_distro() {
196196check_deps_xen () {
197197 set +e
198198 ${BASH_C} " which xl" > /dev/null 2>&1
199- if [ $? -ne 0 ]; then
199+ if [[ $? -ne 0 ] ]; then
200200 show_message info " ${ERR_XEN_NOT_INSTALL[1]} "
201201 return ${ERR_XEN_NOT_INSTALL[0]}
202202 else
203203 ${BASH_C} " xl info" > /dev/null 2>&1
204- if [ $? -eq 0 ]; then
204+ if [[ $? -eq 0 ] ]; then
205205 XEN_MAJOR=$( ${BASH_C} " xl info" | grep xen_major | awk ' {print $3}' )
206206 XEN_MINOR=$( ${BASH_C} " xl info" | grep xen_minor | awk ' {print $3}' )
207207 XEN_VERSION=$( ${BASH_C} " xl info" | grep xen_version | awk ' {print $3}' )
@@ -225,7 +225,7 @@ check_deps_qemu() { #QEMU 2.0+ should be installed
225225 if (command_exist qemu-system-x86_64); then
226226 local QEMU_VER=$( qemu-system-x86_64 --version | awk ' {print $4}' | cut -d" ," -f1)
227227 read QMAJOR QMINOR QFIX < <( echo ${QEMU_VER} | awk -F' .' ' {print $1,$2,$3 }' )
228- if [ ${QMAJOR} -lt 2 ] ; then
228+ if [[ ${QMAJOR} -lt 2 ] ] ; then
229229 show_message info " ${ERR_QEMU_LOW_VERSION[1]} \n" && return ${ERR_QEMU_LOW_VERSION[0]}
230230 fi
231231 else
@@ -235,7 +235,7 @@ check_deps_qemu() { #QEMU 2.0+ should be installed
235235 return 0
236236}
237237check_deps_initsystem () {
238- if [ " ${LSB_DISTRO} " == " ubuntu" -a " ${LSB_CODE} " == " utopic" ]; then
238+ if [[ " ${LSB_DISTRO} " == " ubuntu" ]] && [[ " ${LSB_CODE} " == " utopic" ] ]; then
239239 INIT_SYSTEM=" sysvinit"
240240 elif (command_exist systemctl); then
241241 INIT_SYSTEM=" systemd"
@@ -248,7 +248,7 @@ fetch_hyper_package() {
248248 show_message info " Fetch checksum and package...\n"
249249 set +e
250250 ${BASH_C} " ping -c 3 -W 2 hypercontainer-install.s3.amazonaws.com >/dev/null 2>&1"
251- if [ $? -ne 0 ]; then
251+ if [[ $? -ne 0 ] ]; then
252252 S3_URL=" http://mirror-hypercontainer-install.s3.amazonaws.com"
253253 else
254254 S3_URL=" http://hypercontainer-install.s3.amazonaws.com"
@@ -259,48 +259,48 @@ fetch_hyper_package() {
259259 local CURL_C=$( echo $( get_curl) | awk -F" |" ' {print $2}' )
260260 show_message debug " ${SRC_URL} => ${TGT_FILE} "
261261 mkdir -p ${BOOTSTRAP_DIR} && cd ${BOOTSTRAP_DIR}
262- if [ -s ${TGT_FILE} ]; then
263- if [ " ${USE_WGET} " == " true" ]; then
262+ if [[ -s ${TGT_FILE} ] ]; then
263+ if [[ " ${USE_WGET} " == " true" ] ]; then
264264 ${CURL_C} ${SRC_URL} .md5 2>&1 | grep --line-buffered " %" | sed -u -e " s,\.,,g" | awk ' {printf("\b\b\b\b%4s", $2)}'
265265 else
266266 ${CURL_C} ${TGT_FILE} .md5 ${SRC_URL} .md5
267267 fi
268- if [ -s " ${TGT_FILE} .md5" ]; then
268+ if [[ -s " ${TGT_FILE} .md5" ] ]; then
269269 NEW_MD5=$( cat ${TGT_FILE} .md5 | awk ' {print $1}' )
270270 OLD_MD5=$( md5sum ${TGT_FILE} | awk ' {print $1}' )
271271 if [[ ! -z ${OLD_MD5} ]] && [[ ! -z ${NEW_MD5} ]] && [[ " ${OLD_MD5} " != " ${NEW_MD5} " ]]; then
272272 show_message info " ${LIGHT} Found new hyper version, will download it now!\n"
273273 ${BASH_C} " \rm -rf ${BOOTSTRAP_DIR} /*"
274- elif [ ! -z ${OLD_MD5} -a " ${OLD_MD5} " == " ${NEW_MD5} " ]; then # no update
274+ elif [[ ! -z ${OLD_MD5} ]] && [[ " ${OLD_MD5} " == " ${NEW_MD5} " ] ]; then # no update
275275 ${BASH_C} " \rm -rf ${BOOTSTRAP_DIR} /${UNTAR_DIR} "
276276 else
277277 ${BASH_C} " \rm -rf ${BOOTSTRAP_DIR} /*"
278278 fi
279279 fi
280- elif [ -f ${TGT_FILE} ]; then
280+ elif [[ -f ${TGT_FILE} ] ]; then
281281 ${BASH_C} " \rm -rf ${BOOTSTRAP_DIR} /*"
282282 fi
283- if [ ! -f ${TGT_FILE} ]; then
283+ if [[ ! -f ${TGT_FILE} ] ]; then
284284 \r m -rf ${TGT_FILE} .md5 > /dev/null 2>&1
285- if [ " ${USE_WGET} " == " true" ]; then
285+ if [[ " ${USE_WGET} " == " true" ] ]; then
286286 ${CURL_C} ${SRC_URL} .md5 2>&1 | grep --line-buffered " %" | sed -u -e " s,\.,,g" | awk ' {printf("\b\b\b\b%4s", $2)}'
287287 ${CURL_C} ${SRC_URL} 2>&1 | grep --line-buffered " %" | sed -u -e " s,\.,,g" | awk ' {printf("\b\b\b\b%4s", $2)}'
288288 else
289289 ${CURL_C} ${TGT_FILE} .md5 ${SRC_URL} .md5
290290 ${CURL_C} ${TGT_FILE} ${SRC_URL}
291291 fi
292- if [ $? -ne 0 ]; then
292+ if [[ $? -ne 0 ] ]; then
293293 show_message error " ${ERR_FETCH_INST_PKG_FAILED[1]} " && exit " ${ERR_FETCH_INST_PKG_FAILED[0]} "
294294 else
295295 MD5_REMOTE=$( cat ${TGT_FILE} .md5 | awk ' {print $1}' ) ; MD5_LOCAL=$( md5sum ${TGT_FILE} | awk ' {print $1}' )
296- if [ ${MD5_REMOTE} != ${MD5_LOCAL} ]; then
296+ if [[ ${MD5_REMOTE} != ${MD5_LOCAL} ] ]; then
297297 echo " required checksum: ${MD5_REMOTE} , but downloaded package is ${MD5_LOCAL} "
298298 show_message error " ${ERR_INST_PKG_MD5_ERROR[1]} " && exit " ${ERR_INST_PKG_MD5_ERROR[0]} "
299299 fi
300300 fi
301301 fi
302302 ${BASH_C} " cd ${BOOTSTRAP_DIR} && tar xzf ${PKG_FILE} "
303- if [ $? -ne 0 ]; then
303+ if [[ $? -ne 0 ] ]; then
304304 show_message error " ${ERR_UNTAR_PKG_FAILED[1]} " && exit " ${ERR_UNTAR_PKG_FAILED[0]} "
305305 fi
306306 BOOTSTRAP_DIR=" ${BOOTSTRAP_DIR} /${UNTAR_DIR} "
@@ -312,7 +312,7 @@ install_hyper() {
312312 set +e
313313 cd ${BOOTSTRAP_DIR}
314314 ${BASH_C} " ./install.sh" 1> /dev/null
315- if [ $? -ne 0 ]; then
315+ if [[ $? -ne 0 ] ]; then
316316 show_message error " ${ERR_EXEC_INSTALL_FAILED[1]} " && exit " ${ERR_EXEC_INSTALL_FAILED[0]} "
317317 fi
318318 echo -n " ."
@@ -334,20 +334,20 @@ install_hyper() {
334334install_hyperd_service () {
335335 local SRC_INIT_FILE=" "
336336 local TGT_INIT_FILE=" "
337- if [ " ${INIT_SYSTEM} " == " sysvinit" ]; then
338- if [ " ${LSB_DISTRO} " == " debian" -a " ${LSB_CODE} " == " wheezy" ] ; then
337+ if [[ " ${INIT_SYSTEM} " == " sysvinit" ] ]; then
338+ if [[ " ${LSB_DISTRO} " == " debian" ]] && [[ " ${LSB_CODE} " == " wheezy" ] ] ; then
339339 SRC_INIT_FILE=" ${BOOTSTRAP_DIR} /service/init.d/hyperd.ubuntu"
340- elif [ " ${LSB_DISTRO} " == " linuxmint" ] ; then
340+ elif [[ " ${LSB_DISTRO} " == " linuxmint" ] ] ; then
341341 SRC_INIT_FILE=" ${BOOTSTRAP_DIR} /service/init.d/hyperd.ubuntu"
342342 else
343343 SRC_INIT_FILE=" ${BOOTSTRAP_DIR} /service/init.d/hyperd.${LSB_DISTRO} "
344344 fi
345345 TGT_INIT_FILE=" /etc/init.d/hyperd"
346- elif [ " ${INIT_SYSTEM} " == " systemd" ]; then
346+ elif [[ " ${INIT_SYSTEM} " == " systemd" ] ]; then
347347 SRC_INIT_FILE=" ${BOOTSTRAP_DIR} /service/systemd/hyperd.service"
348348 TGT_INIT_FILE=" /lib/systemd/system/hyperd.service"
349349 fi
350- if [ -s ${SRC_INIT_FILE} ]; then
350+ if [[ -s ${SRC_INIT_FILE} ] ]; then
351351 ${BASH_C} " cp ${SRC_INIT_FILE} ${TGT_INIT_FILE} "
352352 ${BASH_C} " chmod +x ${TGT_INIT_FILE} "
353353 else
@@ -359,9 +359,9 @@ install_hyperd_service() {
359359stop_running_hyperd () {
360360 set +e
361361 pgrep hyperd > /dev/null 2>&1
362- if [ $? -eq 0 ]; then
362+ if [[ $? -eq 0 ] ]; then
363363 echo -e " \nStopping running hyperd service before install"
364- if [ " ${INIT_SYSTEM} " == " systemd" ]
364+ if [[ " ${INIT_SYSTEM} " == " systemd" ] ]
365365 then ${BASH_C} " systemctl stop hyperd"
366366 else ${BASH_C} " service hyperd stop" ;
367367 fi
@@ -371,14 +371,14 @@ stop_running_hyperd() {
371371}
372372start_hyperd_service () {
373373 show_message info " Start hyperd service\n"
374- if [ " ${INIT_SYSTEM} " == " systemd" ]
374+ if [[ " ${INIT_SYSTEM} " == " systemd" ] ]
375375 then ${BASH_C} " systemctl start hyperd"
376376 else ${BASH_C} " service hyperd start" ;
377377 fi
378378 sleep 3
379379 set +e
380380 pgrep hyperd > /dev/null 2>&1
381- if [ $? -eq 0 ]; then
381+ if [[ $? -eq 0 ] ]; then
382382 show_message success " \nhyperd is running."
383383 cat << COMMENT
384384----------------------------------------------------
@@ -410,15 +410,15 @@ install_from_rpm(){
410410 show_message info " Fetch rpm package for $1 ...\n"
411411 set +e
412412 ${BASH_C} " ping -c 3 -W 2 hypercontainer-install.s3.amazonaws.com >/dev/null 2>&1"
413- if [ $? -ne 0 ]; then
413+ if [[ $? -ne 0 ] ]; then
414414 S3_URL=" http://mirror-hypercontainer-install.s3.amazonaws.com"
415415 else
416416 S3_URL=" http://hypercontainer-install.s3.amazonaws.com"
417417 fi
418418 case " $1 " in
419419 centos7)
420420 rpm -qa | grep ${CENTOS7_HYPER} > /dev/null 2>&1
421- if [ $? -eq 0 ]; then
421+ if [[ $? -eq 0 ] ]; then
422422 show_message info " ${ERR_HYPER_NO_NEW_VERSION[1]} " ; exit 1
423423 fi
424424 if (command_exist hyperctl hyperd); then
@@ -431,7 +431,7 @@ install_from_rpm(){
431431 ;;
432432 fedora23)
433433 rpm -qa | grep ${FC23_HYPER} > /dev/null 2>&1
434- if [ $? -eq 0 ]; then
434+ if [[ $? -eq 0 ] ]; then
435435 show_message info " ${ERR_HYPER_NO_NEW_VERSION[1]} " ; exit 1
436436 fi
437437 if (command_exist hyperctl hyperd); then
@@ -448,7 +448,7 @@ install_from_rpm(){
448448}
449449display_support () {
450450 echo " Sorry, we are suffering from some technical issue($1 ), please contact ${SUPPORT_EMAIL} "
451- if [ $# -eq 0 ]; then exit ${ERR_UNKNOWN}
451+ if [[ $# -eq 0 ] ]; then exit ${ERR_UNKNOWN}
452452 else exit $1
453453 fi
454454}
0 commit comments