return $?
}
+function ts_is_mounted {
+ local DEV=$1
+
+ grep -q $DEV /proc/mounts && return 0
+
+ if [ "${DEV#/dev/loop/}" != "$DEV" ]; then
+ return grep -q "/dev/loop${DEV#/dev/loop/}" /proc/mounts
+ fi
+ return 1
+}
+
function ts_swapoff {
local DEV="$1"
$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_is_mounted $DEVICE || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
ts_log "list the image"
ls -laR --time-style=long-iso $TS_MOUNTPOINT >> $TS_OUTPUT
# variant A)
$TS_CMD_MOUNT $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# variant B)
$TS_CMD_MOUNT $DEVICE 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
ts_fstab_add "LABEL=$LABEL"
$TS_CMD_MOUNT $DEVICE 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
ts_fstab_add "UUID=$UUID"
$TS_CMD_MOUNT $DEVICE 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
# variant A)
$TS_CMD_MOUNT $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# variant B)
$TS_CMD_MOUNT -L $LABEL 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
# variant C)
$TS_CMD_MOUNT LABEL=$LABEL 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "C) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "C) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "C) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
# variant A)
$TS_CMD_MOUNT -L $LABEL 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# variant B)
$TS_CMD_MOUNT "LABEL=$LABEL" 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
# variant A)
$TS_CMD_MOUNT -L $LABEL 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# variant B)
$TS_CMD_MOUNT "LABEL=$LABEL" 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
# variant A) -- UID=0
$TS_CMD_MOUNT $LINKNAME 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $LINKNAME || ts_die "A) Cannot umount $LINKNAME" $DEVICE
# varian B)
ts_init_suid $TS_CMD_UMOUNT
su $TS_TESTUSER -c "$TS_CMD_MOUNT $LINKNAME" 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
su $TS_TESTUSER -c "$TS_CMD_UMOUNT $LINKNAME" 2>&1 >> $TS_OUTPUT \
|| ts_die "B) Cannot umount $LINKNAME" $DEVICE
# varian A)
$TS_CMD_MOUNT $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# varian B)
$TS_CMD_MOUNT -U $UUID 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
# varian C)
$TS_CMD_MOUNT UUID=$UUID 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "C) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "C) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "C) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
# variant A)
$TS_CMD_MOUNT -U $UUID 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# variant B)
$TS_CMD_MOUNT "UUID=$UUID" 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
# variant A)
$TS_CMD_MOUNT -U $UUID 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# variant B)
$TS_CMD_MOUNT "UUID=$UUID" 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
$TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" $DEVICE
# variant A)
$TS_CMD_MOUNT -L $LABEL $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# variant B)
$TS_CMD_MOUNT LABEL=$LABEL $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts \
- || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE
# variant A)
$TS_CMD_MOUNT -U $UUID $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "A) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "A) Cannot umount $DEVICE" $DEVICE
# variant B)
$TS_CMD_MOUNT UUID=$UUID $TS_MOUNTPOINT 2>&1 >> $TS_OUTPUT
-grep -q $DEVICE /proc/mounts || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
+ts_is_mounted $DEVICE || ts_die "B) Cannot found $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
ts_device_deinit $DEVICE