@@ -10,26 +10,30 @@ MOUNTPATH=/mnt/cloud/systemvm
1010TMPDIR=${TMP} /cloud/systemvm
1111
1212
13+ clean_up () {
14+ sudo umount $MOUNTPATH
15+ }
16+
1317inject_into_iso () {
1418 local isofile=${systemvmpath}
1519 local newpubkey=$2
1620 local backup=${isofile} .bak
1721 local tmpiso=${TMP} /$1
1822 [ ! -f $isofile ] && echo " $( basename $0 ) : Could not find systemvm iso patch file $isofile " && return 1
1923 sudo mount -o loop $isofile $MOUNTPATH
20- [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to mount original iso $isofile " && return 1
21- diff -q $MOUNTPATH /authorized_keys $newpubkey & > /dev/null && return 0
24+ [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to mount original iso $isofile " && clean_up && return 1
25+ diff -q $MOUNTPATH /authorized_keys $newpubkey & > /dev/null && clean_up && return 0
2226 sudo cp -b $isofile $backup
23- [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to backup original iso $isofile " && return 1
27+ [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to backup original iso $isofile " && clean_up && return 1
2428 rm -rf $TMPDIR
2529 mkdir -p $TMPDIR
26- [ ! -d $TMPDIR ] && echo " $( basename $0 ) : Could not find/create temporary dir $TMPDIR " && return 1
30+ [ ! -d $TMPDIR ] && echo " $( basename $0 ) : Could not find/create temporary dir $TMPDIR " && clean_up && return 1
2731 sudo cp -fr $MOUNTPATH /* $TMPDIR /
28- [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to copy from original iso $isofile " && return 1
32+ [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to copy from original iso $isofile " && clean_up && return 1
2933 sudo cp $newpubkey $TMPDIR /authorized_keys
30- [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to copy key $newpubkey from original iso to new iso " && return 1
34+ [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to copy key $newpubkey from original iso to new iso " && clean_up && return 1
3135 mkisofs -quiet -r -o $tmpiso $TMPDIR
32- [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to create new iso $tmpiso from $TMPDIR " && return 1
36+ [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to create new iso $tmpiso from $TMPDIR " && clean_up && return 1
3337 sudo umount $MOUNTPATH
3438 [ $? -ne 0 ] && echo " $( basename $0 ) : Failed to unmount old iso from $MOUNTPATH " && return 1
3539 sudo cp -f $tmpiso $isofile
0 commit comments