[Fedora-livecd-list] [PATCH 2/3] livecd-iso-to-disk: Catch all failures
Lubomir Rintel
lkundrak at v3.sk
Fri Mar 11 15:25:24 UTC 2011
The utility used to success also in cases where catasthropic failures, such as
failure to install boot loader occured. This turns on shell options to catch
such problems and only tolerates non-zero exit values on case-by-case basis.
The utility with this change applied has received fair amount of testing
(against vfat and ext3 filesystems, with permutations of --format and --efi),
though some more testing might be useful.
---
tools/livecd-iso-to-disk.sh | 40 ++++++++++++++++++++++++----------------
1 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh
index 8e3b481..9914630 100755
--- a/tools/livecd-iso-to-disk.sh
+++ b/tools/livecd-iso-to-disk.sh
@@ -274,9 +274,13 @@ cleanup() {
}
exitclean() {
- echo "Cleaning up to exit..."
- cleanup
- exit 1
+ RETVAL=$?
+ if [ -d "$SRCMNT" ] || [ -d "$TGTMNT" ];
+ then
+ [ "$RETVAL" = 0 ] || echo "Cleaning up to exit..."
+ cleanup
+ fi
+ exit $RETVAL
}
isdevloop() {
@@ -395,7 +399,7 @@ checkLVM() {
dev=$1
if [ -x /sbin/pvs -a \
- "$(/sbin/pvs -o vg_name --noheadings $dev* 2>/dev/null)" ]; then
+ "$(/sbin/pvs -o vg_name --noheadings $dev* 2>/dev/null || :)" ]; then
echo "Device, $dev, contains a volume group and cannot be formated!"
echo "You can remove the volume group using vgremove."
exitclean
@@ -410,7 +414,7 @@ createGPTLayout() {
echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
echo "Press Enter to continue or ctrl-c to abort"
read
- umount ${device}* &> /dev/null
+ umount ${device}* &> /dev/null || :
/sbin/parted --script $device mklabel gpt
partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit b print" |grep ^$device:)
size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/B$//')
@@ -421,7 +425,7 @@ createGPTLayout() {
sleep 5
getpartition ${device#/dev/}
TGTDEV=${device}${partnum}
- umount $TGTDEV &> /dev/null
+ umount $TGTDEV &> /dev/null || :
/sbin/mkdosfs -n LIVE $TGTDEV
TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
}
@@ -433,7 +437,7 @@ createMSDOSLayout() {
echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
echo "Press Enter to continue or ctrl-c to abort"
read
- umount ${device}* &> /dev/null
+ umount ${device}* &> /dev/null || :
/sbin/parted --script $device mklabel msdos
partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit b print" |grep ^$device:)
size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/B$//')
@@ -448,7 +452,7 @@ createMSDOSLayout() {
else
TGTDEV=${device}
fi
- umount $TGTDEV &> /dev/null
+ umount $TGTDEV &> /dev/null || :
/sbin/mkdosfs -n LIVE $TGTDEV
TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
}
@@ -460,7 +464,7 @@ createEXTFSLayout() {
echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
echo "Press Enter to continue or ctrl-c to abort"
read
- umount ${device}* &> /dev/null
+ umount ${device}* &> /dev/null || :
/sbin/parted --script $device mklabel msdos
partinfo=$(LC_ALL=C /sbin/parted --script -m $device "unit b print" |grep ^$device:)
size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/B$//')
@@ -471,7 +475,7 @@ createEXTFSLayout() {
sleep 5
getpartition ${device#/dev/}
TGTDEV=${device}${partnum}
- umount $TGTDEV &> /dev/null
+ umount $TGTDEV &> /dev/null || :
/sbin/mkfs.$TGTFS -L LIVE $TGTDEV
TGTLABEL="UUID=$(/sbin/blkid -s UUID -o value $TGTDEV)"
}
@@ -507,7 +511,7 @@ checkGPT() {
checkFilesystem() {
dev=$1
- TGTFS=$(/sbin/blkid -s TYPE -o value $dev)
+ TGTFS=$(/sbin/blkid -s TYPE -o value $dev || :)
if [ "$TGTFS" != "vfat" ] && [ "$TGTFS" != "msdos" ]; then
if [ "$TGTFS" != "ext2" ] && [ "$TGTFS" != "ext3" ] && [ "$TGTFS" != "ext4" ] && [ "$TGTFS" != "btrfs" ]; then
echo "Target filesystem must be vfat, ext[234] or btrfs"
@@ -638,6 +642,10 @@ copyFile() {
cp "$1" "$2"
}
+set -e
+set -o pipefail
+trap exitclean EXIT
+
cryptedhome=1
keephome=1
homesizemb=0
@@ -772,8 +780,7 @@ fi
if [ -z "$noverify" ]; then
# verify the image
echo "Verifying image..."
- checkisomd5 --verbose "$SRC"
- if [ $? -ne 0 ]; then
+ if ! checkisomd5 --verbose "$SRC"; then
echo "Are you SURE you want to continue?"
echo "Press Enter to continue or ctrl-c to abort"
read
@@ -871,7 +878,7 @@ if [[ live == $srctype ]]; then
targets="$TGTMNT/$SYSLINUXPATH"
[[ -n $efi ]] && targets+=" $TGTMNT/EFI/boot"
[[ -n $xo ]] && targets+=" $TGTMNT/boot/olpc.fth"
- duTable=($(du -c -B 1M $targets 2> /dev/null))
+ duTable=($(du -c -B 1M $targets 2> /dev/null || :))
((tbd += ${duTable[*]: -2:1}))
fi
@@ -903,7 +910,7 @@ if [[ live == $srctype ]]; then
sources+=" $SRCMNT/isolinux $SRCMNT/syslinux"
[[ -n $efi ]] && sources+=" $SRCMNT/EFI/boot"
[[ -n $xo ]] && sources+=" $SRCMNT/boot/olpc.fth"
- duTable=($(du -c -B 1M "$thisScriptpath" $sources 2> /dev/null))
+ duTable=($(du -c -B 1M "$thisScriptpath" $sources 2> /dev/null || :))
((livesize += ${duTable[*]: -2:1}))
fi
@@ -1047,7 +1054,8 @@ fi
if [[ live == $srctype ]]; then
# Copy this installer script.
- cp -fTp "$thisScriptpath" $TGTMNT/$LIVEOS/livecd-iso-to-disk &> /dev/null
+ cp -fT "$thisScriptpath" $TGTMNT/$LIVEOS/livecd-iso-to-disk
+ chmod +x $TGTMNT/$LIVEOS/livecd-iso-to-disk &> /dev/null || :
# When the source is an installed Live USB/SD image, restore the boot config
# file to a base state before updating.
--
1.7.1
More information about the livecd
mailing list