From 1dfd27f6ae46fafec95aa1d5879d51b56fc3bf80 Mon Sep 17 00:00:00 2001 From: Lyssieth Date: Tue, 10 Oct 2023 22:31:44 +0300 Subject: [PATCH] feat: improve the Justfile/mount-tool a bit. --- Justfile | 5 ++++- mount-tool.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ mount.sh | 23 ---------------------- 3 files changed, 58 insertions(+), 24 deletions(-) create mode 100755 mount-tool.sh delete mode 100644 mount.sh diff --git a/Justfile b/Justfile index d25bd4e..eb5fdae 100644 --- a/Justfile +++ b/Justfile @@ -4,7 +4,10 @@ build: docker buildx build --pull --platform linux/amd64 -t "forge.lys.ee/lyssieth/rave:amd64" --load . mount: - bash ./mount.sh + bash ./mount-tool.sh mount + +unmount: + bash ./mount-tool.sh unmount run: mount RAVE_STORAGE_DIR=/tmp/media-for-rave cargo r diff --git a/mount-tool.sh b/mount-tool.sh new file mode 100755 index 0000000..2b8934d --- /dev/null +++ b/mount-tool.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -euo pipefail # exit on error + +# check for `fuse-overlayfs` executable +if ! command -v fuse-overlayfs &>/dev/null; then + echo "fuse-overlayfs could not be found" + exit 1 +fi + +function mount_rave { + # check if already mounted; im /tmp so it's ephemeral + if [ -d /tmp/media-for-rave ]; then exit 0; fi + + # mount the music directory; assumes a fstab entry like: + # /dev/sda1 /mnt/Media ext4 defaults 0 0 + # or equivalent; as long as it mounts to /mnt/Media + sudo mount /mnt/Media + + # create the overlayfs + mkdir -p /tmp/overlay /tmp/work /tmp/media-for-rave + + # mount the overlayfs + fuse-overlayfs -o lowerdir=/mnt/Media/Music -o upperdir=/tmp/overlay -o workdir=/tmp/work /tmp/media-for-rave +} + +function unmount_rave { + # check if already unmounted + if [ ! -d /tmp/media-for-rave ]; then exit 0; fi + + # unmount the overlayfs + umount /tmp/media-for-rave || true + + # clean up the overlayfs if `CLEAN` is set + if [ "${CLEAN:-}" = "true" ]; then + rm -rf /tmp/overlay /tmp/work /tmp/media-for-rave + fi + + # unmount the music directory + sudo umount /mnt/Media || true +} + +case "${1:-}" in +mount) + mount_rave + ;; +unmount) + unmount_rave + ;; +*) + echo "Usage: $0 {mount|unmount}" + exit 1 + ;; +esac diff --git a/mount.sh b/mount.sh deleted file mode 100644 index 07285e1..0000000 --- a/mount.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail # exit on error - -# check for `fuse-overlayfs` executable -if ! command -v fuse-overlayfs &>/dev/null; then - echo "fuse-overlayfs could not be found" - exit 1 -fi - -# check if already mounted; im /tmp so it's ephemeral -if [ -d /tmp/media-for-rave ]; then exit 0; fi - -# mount the music directory; assumes a fstab entry like: -# /dev/sda1 /mnt/Media ext4 defaults 0 0 -# or equivalent; as long as it mounts to /mnt/Media -sudo mount /mnt/Media - -# create the overlayfs -mkdir -p /tmp/overlay /tmp/work /tmp/media-for-rave - -# mount the overlayfs -fuse-overlayfs -o lowerdir=/mnt/Media/Music -o upperdir=/tmp/overlay -o workdir=/tmp/work /tmp/media-for-rave