]> arthur.barton.de Git - ax-linux.git/commitdiff
btrfs-mksnapshot[-rootfs]: Clean up, use findmnt(8) master
authorAlexander Barton <alex@barton.de>
Sun, 26 Jan 2020 19:45:51 +0000 (20:45 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 26 Jan 2020 19:45:51 +0000 (20:45 +0100)
btrfs/mksnapshot/btrfs-mksnapshot
btrfs/mksnapshot/btrfs-mksnapshot-rootfs

index 15edff9a0cd2fdd98bf3f116527b857cb3a1d33b..3d2fde80af191ba0a97d734d59679eb95c31aa82 100755 (executable)
@@ -49,15 +49,7 @@ done
 [ -z "$DRY_RUN" ] || echo "VOLUME_PATH=$VOLUME_PATH"
 
 # Detect btrfs filesystem
-FS_NAME=$(btrfs filesystem show -m / 2>/dev/null | head -1 | cut -d"'" -f2)
-if [ -z "$FS_NAME" ]; then
-       FS_NAME=$(grep " btrfs " /etc/fstab \
-               | grep "^LABEL=" \
-               | grep " $VOLUME_PATH " \
-               | cut -d'"' -f2 \
-               | cut -d'=' -f2- \
-               | cut -d' ' -f1)
-fi
+FS_NAME=$(btrfs filesystem show -m "$VOLUME_PATH" 2>/dev/null | head -1 | cut -d"'" -f2)
 if [ -z "$FS_NAME" ]; then
        echo "$NAME: Failed to detect btrfs filesystem label for \"$VOLUME_PATH\"!"
        exit 1
@@ -66,10 +58,7 @@ fi
 [ -z "$DRY_RUN" ] || echo "FS_NAME=$FS_NAME"
 
 # Detect btrfs subvolume name
-VOLUME_NAME=$(grep " btrfs " /etc/fstab \
-       | grep "subvol=" \
-       | grep " $VOLUME_PATH " \
-       | sed -r 's|.*subvol=([^, \t]*).*|\1|')
+VOLUME_NAME=$(findmnt -nf -o source "$VOLUME_PATH" | grep -F '[' | sed -r 's|^.*\[/(.*)\]|\1|')
 if [ -z "$VOLUME_NAME" ] && [ "$VOLUME_PATH" = "/" ]; then
        VOLUME_NAME=$(btrfs subvolume get-default / | cut -d' ' -f9)
 fi
@@ -90,7 +79,7 @@ if [ ! -d "$FS_MOUNT_PATH" ]; then
        echo "$NAME: Directory \"$FS_MOUNT_PATH\" does not exist!"
        exit 1
 fi
-if grep " btrfs " /proc/mounts | grep " $FS_MOUNT_PATH " >/dev/null 2>&1; then
+if ! grep -q " $FS_MOUNT_PATH btrfs " /proc/mounts; then
        echo "$NAME: btrfs \"$FS_NAME\" seems not to be mounted on \"$FS_MOUNT_PATH\"!"
        exit 1
 fi
index 2744d03727e2bffe3e757a796f05348dd36d2265..dcb840d11719f41844f9c7f26dce05830f6f33db 100755 (executable)
@@ -19,7 +19,7 @@ Usage()
 
 [ $# -eq 0 ] || Usage
 
-if grep -Fq ' / btrfs ' /etc/fstab; then
+if [ "$(findmnt -fnr -o fstype /)" = "btrfs" ]; then
        if [ -x /usr/local/sbin/btrfs-mksnapshot ]; then
                /usr/local/sbin/btrfs-mksnapshot -1 / || exit 1
        else