Skip to content

Instantly share code, notes, and snippets.

@muresan
Last active May 23, 2024 06:56
Show Gist options
  • Save muresan/1ec18856f412a80e0afe to your computer and use it in GitHub Desktop.
Save muresan/1ec18856f412a80e0afe to your computer and use it in GitHub Desktop.
Script to automatically mount NTFS filesystems for OpenWRT
#!/bin/bash
# filename: /etc/hotplug.d/block/10-mount
# automatically mount ntfs volumes into $BASEDIR with $LABEL or $UUID, depending on what's available.
# to be used with OpenWRT.
BASEDIR=/media
export PATH=/usr/bin:/usr/sbin:/bin:/sbin
if [ "$HOTPLUG_TYPE" = "block" ]; then
# workaround bug in blkid from OpenWRT 14.07, does not escape spaces in LABEL
eval `blkid -o export /dev/$DEVNAME | sed 's/\(LABEL=\)\(.*\)/\1"\2"/'`
# change TYPE to ntfs-3g to allow it to be mounted
TYPE=`echo $TYPE|sed s/^ntfs$/ntfs-3g/`
if [ -n "$LABEL" -o -n "$UUID" ]; then
case "$ACTION" in
add)
if [ -n "$LABEL" -a "$TYPE" = "ntfs-3g" ]; then
mkdir -p ${BASEDIR}/"$LABEL"
mount -t $TYPE LABEL="$LABEL" ${BASEDIR}/"$LABEL"
elif [ -n "$UUID" -a "$TYPE" = "ntfs-3g" ]; then
mkdir -p ${BASEDIR}/"$UUID"
mount -t $TYPE UUID="$UUID" ${BASEDIR}/"$UUID"
fi
;;
remove)
# DEVNAME has full path here, because it was chanbed by the eval `blkid`
umount -l "$DEVNAME"
;;
esac
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment