From 3c0f9b11eaff9dbf4ebc7cbd920053fe8fcd55af Mon Sep 17 00:00:00 2001 From: Abraham Arce Date: Tue, 30 Oct 2018 07:20:31 -0600 Subject: [PATCH] [Doc] Usage and ISO Check Common Code Usage function and ISO file checking are common between all-in-one and standard controller setups. Make both scripts shared same code located at a functions file. Change-Id: Ic47072be8f9d646ef1dcaf9193453dfcd4534783 Signed-off-by: Abraham Arce --- deployment/libvirt/functions.sh | 17 ++++++++++++++++ deployment/libvirt/setup_allinone.sh | 18 +++-------------- .../libvirt/setup_standard_controller.sh | 20 +++---------------- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/deployment/libvirt/functions.sh b/deployment/libvirt/functions.sh index 63179d1f..5f8a7065 100644 --- a/deployment/libvirt/functions.sh +++ b/deployment/libvirt/functions.sh @@ -1,5 +1,22 @@ #!/usr/bin/env bash +usage() { + echo "$0 [-h] [-i ]" + echo "" + echo "Options:" + echo " -i: StarlingX ISO image" + echo "" +} + +iso_image_check() { + local ISOIMAGE=$1 + FILETYPE=$(file --mime-type -b ${ISOIMAGE}) + if ([ "$FILETYPE" != "application/x-iso9660-image" ]); then + echo "$ISOIMAGE is not an application/x-iso9660-image type" + exit -1 + fi +} + # delete a node's disk file in a safe way delete_disk() { local fpath="$1" diff --git a/deployment/libvirt/setup_allinone.sh b/deployment/libvirt/setup_allinone.sh index 5069db71..72c9ecac 100755 --- a/deployment/libvirt/setup_allinone.sh +++ b/deployment/libvirt/setup_allinone.sh @@ -1,19 +1,12 @@ #!/usr/bin/env bash SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )" - -usage() { - echo "$0 [-h] [-i ]" - echo "" - echo "Options:" - echo " -i: StarlingX ISO image" - echo "" -} +source ${SCRIPT_DIR}/functions.sh while getopts "i:" o; do case "${o}" in i) - ISOIMAGE="$OPTARG" + ISOIMAGE=$(readlink -f "$OPTARG") ;; *) usage @@ -28,12 +21,7 @@ if [ -z "${ISOIMAGE}" ]; then exit -1 fi -ISOIMAGE=$(readlink -f "$ISOIMAGE") -FILETYPE=$(file --mime-type -b ${ISOIMAGE}) -if ([ "$FILETYPE" != "application/x-iso9660-image" ]); then - echo "$ISOIMAGE is not an application/x-iso9660-image type" - exit -1 -fi +iso_image_check ${ISOIMAGE} BRIDGE_INTERFACE=${BRIDGE_INTERFACE:-stxbr} CONTROLLER=${CONTROLLER:-controller-allinone} diff --git a/deployment/libvirt/setup_standard_controller.sh b/deployment/libvirt/setup_standard_controller.sh index 0ce994ab..77bf8c92 100755 --- a/deployment/libvirt/setup_standard_controller.sh +++ b/deployment/libvirt/setup_standard_controller.sh @@ -1,21 +1,12 @@ #!/usr/bin/env bash -#set -x - SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )" - -usage() { - echo "$0 [-h] [-i ]" - echo "" - echo "Options:" - echo " -i: StarlingX ISO image" - echo "" -} +source ${SCRIPT_DIR}/functions.sh while getopts "i:" o; do case "${o}" in i) - ISOIMAGE="$OPTARG" + ISOIMAGE=$(readlink -f "$OPTARG") ;; *) usage @@ -30,12 +21,7 @@ if [ -z "${ISOIMAGE}" ]; then exit -1 fi -ISOIMAGE=$(readlink -f "$ISOIMAGE") -FILETYPE=$(file --mime-type -b ${ISOIMAGE}) -if ([ "$FILETYPE" != "application/x-iso9660-image" ]); then - echo "$ISOIMAGE is not an application/x-iso9660-image type" - exit -1 -fi +iso_image_check ${ISOIMAGE} BRIDGE_INTERFACE=${BRIDGE_INTERFACE:-stxbr} CONTROLLER=${CONTROLLER:-controller}