1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616
17- set -e
18-
1917log () {
2018 echo " ` basename $0 ` : $@ "
2119}
2220
21+ fail () {
22+ log " Error $@ "
23+ exit 1
24+ }
25+
2326usage () {
2427 [[ -z " $1 " ]] || echo -e " USAGE ERROR: $@ \n"
2528 echo " ` basename $0 ` : CONFIGDRIVE DEVICE"
@@ -37,19 +40,20 @@ DEVICE="$2"
3740# Check for preexisting partition for configdrive
3841EXISTING_PARTITION=` /sbin/blkid -l -o device $DEVICE -t LABEL=config-2`
3942if [[ $? == 0 ]]; then
43+ log " Existing configdrive found on ${DEVICE} at ${EXISTING_PARTITION} "
4044 ISO_PARTITION=$EXISTING_PARTITION
4145else
4246 # Create small partition at the end of the device
4347 log " Adding configdrive partition to $DEVICE "
44- parted -a optimal -s -- $DEVICE mkpart primary ext2 -64MiB -0
48+ parted -a optimal -s -- $DEVICE mkpart primary ext2 -64MiB -0 || fail " creating configdrive on ${DEVICE} "
4549
4650 # Find partition we just created
4751 # Dump all partitions, ignore empty ones, then get the last partition ID
48- ISO_PARTITION=` sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk ' {print $1}' `
52+ ISO_PARTITION=` sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk ' {print $1}' ` || fail " finding ISO partition created on ${DEVICE} "
4953fi
5054
5155# This writes the ISO image to the config drive.
5256log " Writing Configdrive contents in $CONFIGDRIVE to $ISO_PARTITION "
53- dd if=$CONFIGDRIVE of=$ISO_PARTITION bs=64K oflag=direct
57+ dd if=$CONFIGDRIVE of=$ISO_PARTITION bs=64K oflag=direct || fail " writing Configdrive to ${ISO_PARTITION} "
5458
5559log " ${DEVICE} imaged successfully!"
0 commit comments