54 lines
1.4 KiB
Bash
Executable file
54 lines
1.4 KiB
Bash
Executable file
#!/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 /tmp/cache-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, but only if CLEAN isn't set
|
|
if [ "${CLEAN:-}" != "1" ] && [ ! -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:-}" = "1" ]; then
|
|
rm -rf /tmp/overlay /tmp/work /tmp/media-for-rave /tmp/cache-for-rave || true
|
|
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
|