]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Add a shell script version of mount.bcachefs
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 25 Aug 2020 00:23:45 +0000 (20:23 -0400)
committerKent Overstreet <kent.overstreet@gmail.com>
Tue, 25 Aug 2020 03:17:17 +0000 (23:17 -0400)
Sadly, some people are still running distributions too old to properly
support rust :( In the long term we'd like to use Rust for more of
userspace (and potentially in the kernel); this is just a stopgap
measure.

Makefile
mount.bcachefs.sh [new file with mode: 0755]

index 062d5cdbe3b7222f0535dbbaffb23cb841e5b342..c91a06aad64d18ccc0ecf5ccb7fa8b3a2a3b1a1b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -127,6 +127,7 @@ install: bcachefs
        $(INSTALL) -m0644 -D bcachefs.8    -t $(DESTDIR)$(PREFIX)/share/man/man8/
        $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
        $(INSTALL) -m0755 -D initramfs/hook   $(DESTDIR)$(INITRAMFS_HOOK)
+       $(INSTALL) -m0755 -D mount.bcachefs.sh $(DESTDIR)$(ROOT_SBINDIR)
        sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
        echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
 
diff --git a/mount.bcachefs.sh b/mount.bcachefs.sh
new file mode 100755 (executable)
index 0000000..b75fbf8
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+join_by()
+{
+    local IFS="$1"
+    shift
+    echo "$*"
+}
+
+args=$(getopt -u -o 'sfnvo:t:N:' -n 'mount.bcachefs' -- "$@")
+if [ $? -ne 0 ]; then
+    echo 'Terminating...' >&2
+    exit 1
+fi
+
+read -r -a argv <<< "$args"
+
+for i in ${!argv[@]}; do
+    [[ ${argv[$i]} == '--' ]] && break
+done
+
+i=$((i+1))
+
+if [[ $((i + 2)) < ${#argv[@]} ]]; then
+    echo "Insufficient arguments"
+    exit 1
+fi
+
+UUID=${argv[$i]}
+
+if [[ ${UUID//-/} =~ ^[[:xdigit:]]{32}$ ]]; then
+    PARTS=()
+
+    for part in $(tail -n +3 /proc/partitions|awk '{print $4}'); do
+       uuid_line=$(bcachefs show-super /dev/$part|& head -n1)
+
+       if [[ $uuid_line =~ $UUID ]]; then
+           PARTS+=(/dev/$part)
+       fi
+    done
+
+    if [[ ${#PARTS[@]} == 0 ]]; then
+       echo "uuid $UUID not found"
+       exit 1
+    fi
+
+    argv[$i]=$(join_by : "${PARTS[@]}")
+fi
+
+exec mount -i -t bcachefs ${argv[@]}