summaryrefslogtreecommitdiff
path: root/mount.bcachefs.sh
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2020-08-24 20:23:45 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2020-08-24 23:17:17 -0400
commit487ddeb03c574e902c5b749b4307e87e2150976a (patch)
tree5ba3a73a912f63635ca55c502d241e4058bd0b77 /mount.bcachefs.sh
parentda730dc67c1bd10842c49a1534fe23e0d8fdb4be (diff)
Add a shell script version of mount.bcachefs
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.
Diffstat (limited to 'mount.bcachefs.sh')
-rwxr-xr-xmount.bcachefs.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/mount.bcachefs.sh b/mount.bcachefs.sh
new file mode 100755
index 00000000..b75fbf8b
--- /dev/null
+++ b/mount.bcachefs.sh
@@ -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[@]}