Use overlay file system to do writes on local file system instead on USB mass storage
@@ -4,7 +4,10 @@ ACTION=$1
DEVBASE=$2
EXTRAARG=$3
DEVICE="/dev/${DEVBASE}"
-BASEDIR=/data/library/music
+BASEDIR=/mnt
+UPPERDIR=/data/library/overlaydir
+WORKDIR=/data/library/workdir
+MUSICDIR=/data/library/music
# See if this drive is already mounted
MOUNT_POINT=$(/bin/mount | /bin/grep ${DEVICE} | /usr/bin/awk '{ print $3 }')
@@ -28,11 +31,18 @@ do_mount()
fi
# Figure out a mount point to use
- LABEL=${ID_FS_LABEL}
# If there is a partition UUID, use this as it should be unique
- if [ "${ID_FS_PARTUUID}" != "" ]; then
+ if [[ -z "${LABEL}" ]]; then
LABEL=${ID_FS_PARTUUID}
fi
+ if [[ -z "${LABEL}" ]]; then
+ LABEL=${ID_FS_UUID}
+ fi
+ # Otherwise try the label
+ if [[ -z "${LABEL}" ]]; then
+ LABEL=${ID_FS_LABEL}
+ fi
+ # still nothing? Use the device name
if [[ -z "${LABEL}" ]]; then
LABEL=${DEVBASE}
elif /bin/grep -q " /media/${LABEL} " /etc/mtab; then
@@ -62,6 +72,12 @@ do_mount()
exit 1
fi
+ # Overlay mount
+ mkdir -p $UPPERDIR
+ mkdir -p $WORKDIR
+ mkdir -p ${MUSICDIR}/${LABEL}
+ mount -t overlay -o lowerdir=${MOUNT_POINT},upperdir=${UPPERDIR},workdir=${WORKDIR} overlay ${MUSICDIR}/${LABEL}
+
# Rescan MPD
if [ "$EXTRAARG" != "norescan" ]; then
if [ -x /opt/hifiberry/bin/update-mpd-db ]; then
