#!/bin/bash # Build an IMG file capable of being booted in a virtual environment # The default settings are vda device which the Cumulus environment expects # and controller mode usage () { echo "" echo "Usage: " echo " build-img [--cpe] [--dest ] [--part [1 | 2]]" echo " --dest " echo " --cpe Boots in CPE mode. Default is controller mode." echo "" } DEST_ISO=bootimage_auto.iso DEST_IMG=tis.img AUTO_MODE=controller HELP=0 PART=0 # read the options TEMP=`getopt -o hp:d: --long help,cpe,part:,dest: -n 'test.sh' -- "$@"` eval set -- "$TEMP" # extract options and their arguments into variables. while true ; do case "$1" in -h|--help) HELP=1 ; shift ;; --cpe) AUTO_MODE=cpe; shift ;; -d | --dest) DEST_IMG="$2"; shift; shift ;; -p | --part) PART="$2"; shift; shift ;; --) shift ; break ;; *) echo "Internal error!" ; exit 1 ;; esac done if [ $HELP -eq 1 ]; then usage exit 0 fi echo PART=$PART # Step 1: Build an ISO that autoboots # Cumulus default device is vda if [ $PART -ne 2 ]; then build-iso --file bootimage_auto.iso --auto $AUTO_MODE --device vda --cumulus fi # Step 2: Convert the ISO to IMG if [ $PART -ne 1 ]; then if [ ! -e "/dev/loop-control" -o ! -e "/dev/kvm" ]; then CMD="cd $MY_WORKSPACE/export; \ $MY_REPO/addons/wr-cgcs/layers/cgcs/extras.ND/scripts/install_iso_to_disk_image.sh bootimage_auto.iso $DEST_IMG" if [ "$HOSTNAME" == "yow-cgts3-centos7" ]; then echo "Attempting to run kvm_iso_to_img on yow-cgts3-lx" ssh -o StrictHostKeyChecking=no yow-cgts3-lx "$CMD" if [ $? -ne 0 ]; then echo "Failed to run update-efiboot-image on yow-cgts3-lx" fi fi if [ "$HOSTNAME" == "yow-cgts2-centos7" ]; then echo "Attempting to run kvm_iso_to_img on yow-cgts2-lx" ssh -o StrictHostKeyChecking=no yow-cgts2-lx "$CMD" if [ $? -ne 0 ]; then echo "Failed to run update-efiboot-image on yow-cgts2-lx" fi fi if [ ! -f "$MY_WORKSPACE/export/$DEST_IMG" ]; then printf "\n" printf "****************************************************************** \n" printf "No kvm and/or loop device on this machine. To complete the build \n" printf "please copy '$MY_WORKSPACE/export/bootimage_auto.iso' to a machine \n" printf "that supports kvm and loop devices and run ... \n" printf " $MY_REPO/addons/wr-cgcs/layers/cgcs/extras.ND/scripts/install_iso_to_disk_image.sh bootimage_auto.iso $DEST_IMG\n" printf "****************************************************************** \n" exit 1 fi fi if [ ! -f "$MY_WORKSPACE/export/$DEST_IMG" ]; then ( cd $MY_WORKSPACE/export $MY_REPO/addons/wr-cgcs/layers/cgcs/extras.ND/scripts/install_iso_to_disk_image.sh bootimage_auto.iso $DEST_IMG exit $? ) fi fi