The patch adds ts_fstab_add and ts_fstab_clean routines.
Signed-off-by: Karel Zak <kzak@redhat.com>
TS_DIFF="$TS_DIFFDIR/$TS_NAME"
TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME"
TS_INPUT="$TS_INPUTDIR/$TS_NAME"
+ TS_MOUNTPOINT="$(pwd)/$TS_OUTDIR/${TS_NAME}_mnt"
rm -f $TS_OUTPUT
touch $TS_OUTPUT
ts_log "$1"
if [ -n "$2" ] && [ -b "$2" ]; then
ts_device_deinit "$2"
+ ts_fstab_clean # for sure...
fi
ts_finalize
}
rm -f $TS_CMD_SWAPOFF
fi
}
+
+function ts_fstab_open {
+ echo "# <!-- util-linux-ng test entry" >> /etc/fstab
+}
+
+function ts_fstab_close {
+ echo "# -->" >> /etc/fstab
+}
+
+function ts_fstab_addline {
+ local SPEC="$1"
+ local MNT=${2:-"$TS_MOUNTPOINT"}
+ local FS=${3:-"auto"}
+ local OPT=${4:-"default"}
+
+ echo "$SPEC $MNT $FS defaults 0 0" >> /etc/fstab
+}
+
+function ts_fstab_add {
+ ts_fstab_open
+ ts_fstab_addline "$*"
+ ts_fstab_close
+}
+
+function ts_fstab_clean {
+ sed --in-place "
+/# <!-- util-linux-ng/!b
+:a
+/# -->/!{
+ N
+ ba
+}
+s/# <!-- util-linux-ng.*-->//;
+/^$/d" /etc/fstab
+}
+
IMAGE_DATA="$TS_OUTDIR/cramfs-data"
IMAGE_RE=$( echo $IMAGE | sed 's:/:\\/:g' )
LABEL="testCramfs"
-MOUNTPOINT="$TS_OUTDIR/cramfs-mnt"
+TS_MOUNTPOINT="$TS_OUTDIR/cramfs-mnt"
ts_log "create mountpoint dir"
-[ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT
+
+[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
ts_log "generate data"
if [ ! -d "$IMAGE_DATA" ]; then
[ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE
ts_log "mount the image"
-$TS_CMD_MOUNT -L $LABEL $MOUNTPOINT 2>&1 >> $TS_OUTPUT
+$TS_CMD_MOUNT -L $LABEL $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
# check it
grep -q $DEVICE /proc/mounts
[ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
ts_log "list the image"
-ls -laR $MOUNTPOINT >> $TS_OUTPUT
+ls -laR $TS_MOUNTPOINT >> $TS_OUTPUT
echo >> $TS_OUTPUT
ts_log "list checksums from new data"
-find $MOUNTPOINT -type f -exec md5sum {} \; >> $TS_OUTPUT
+find $TS_MOUNTPOINT -type f -exec md5sum {} \; >> $TS_OUTPUT
echo >> $TS_OUTPUT
ts_log "umount the image"
set -o pipefail
-MOUNTPOINT="$TS_OUTDIR/${TS_NAME}_mnt"
DEVICE=$(ts_device_init)
[ "$?" == 0 ] || ts_die "Cannot init device"
ts_device_has "TYPE" "ext3" $DEVICE
[ "$?" == "0" ] || ts_die "Cannot found ext3 on $DEVICE" $DEVICE
-[ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT
+[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
-$TS_CMD_MOUNT $DEVICE $MOUNTPOINT 2>&1 >> $TS_OUTPUT
+$TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
grep -q $DEVICE /proc/mounts
[ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
set -o pipefail
-MOUNTPOINT="$TS_OUTDIR/${TS_NAME}_mnt"
DEVICE=$(ts_device_init)
[ "$?" == 0 ] || ts_die "Cannot init device"
-
mkfs.ext3 -L $LABEL $DEVICE &> /dev/null
[ "$?" == "0" ] || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_udev_dev_support "by-label" $LABEL
[ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE
-[ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT
+[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
-$TS_CMD_MOUNT -L $LABEL $MOUNTPOINT 2>&1 >> $TS_OUTPUT
+$TS_CMD_MOUNT -L $LABEL $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
grep -q $DEVICE /proc/mounts
[ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
ts_skip_nonroot
# mountpoint
-MOUNTPOINT="$(pwd)/$TS_OUTDIR/mnt-remount"
-mkdir -p $MOUNTPOINT
+[ -d $TS_MOUNTPOINT ] || mkdir -p $TS_MOUNTPOINT
DEVICE=$(ts_device_init)
[ "$?" == 0 ] || ts_die "Cannot init device"
[ "$?" == "0" ] || ts_die "Cannot make ext2 on $DEVICE" $DEVICE
# mount read-write
-$TS_CMD_MOUNT $DEVICE $MOUNTPOINT
-[ "$?" == "0" ] || ts_die "Cannot mount $MOUNTPOINT" $DEVICE
+$TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT
+[ "$?" == "0" ] || ts_die "Cannot mount $TS_MOUNTPOINT" $DEVICE
# check the mount
-egrep -q "^$DEVICE $MOUNTPOINT" /etc/mtab
-[ "$?" == "0" ] || ts_die "Cannot found $MOUNTPOINT in /etc/mtab" $DEVICE
+egrep -q "^$DEVICE $TS_MOUNTPOINT" /etc/mtab
+[ "$?" == "0" ] || ts_die "Cannot found $TS_MOUNTPOINT in /etc/mtab" $DEVICE
# remount
-$TS_CMD_MOUNT -o remount,ro $MOUNTPOINT
-[ "$?" == "0" ] || ts_die "Cannot remount $MOUNTPOINT" $DEVICE
+$TS_CMD_MOUNT -o remount,ro $TS_MOUNTPOINT
+[ "$?" == "0" ] || ts_die "Cannot remount $TS_MOUNTPOINT" $DEVICE
# check the remount
-egrep -q "^$DEVICE $MOUNTPOINT ext2 ro 0 0" /etc/mtab
-[ "$?" == "0" ] || ts_die "Cannot found remounted $MOUNTPOINT in /etc/mtab" $DEVICE
+egrep -q "^$DEVICE $TS_MOUNTPOINT ext2 ro 0 0" /etc/mtab
+[ "$?" == "0" ] || ts_die "Cannot found remounted $TS_MOUNTPOINT in /etc/mtab" $DEVICE
ts_device_deinit $DEVICE
set -o pipefail
-MOUNTPOINT="$TS_OUTDIR/${TS_NAME}_mnt"
DEVICE=$(ts_device_init)
[ "$?" == 0 ] || ts_die "Cannot init device"
ts_udev_dev_support "by-uuid" $UUID
[ "$?" == "0" ] || ts_skip "udev ignores /dev/loop*" $DEVICE
-[ -d "$MOUNTPOINT" ] || mkdir -p $MOUNTPOINT
+[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
-$TS_CMD_MOUNT -U $UUID $MOUNTPOINT 2>&1 >> $TS_OUTPUT
+$TS_CMD_MOUNT -U $UUID $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
grep -q $DEVICE /proc/mounts
[ "$?" == "0" ] || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE