Skip to content

Instantly share code, notes, and snippets.

@fakuivan
Last active May 7, 2022 17:26
Show Gist options
  • Save fakuivan/8f06e4e02a650acd07d84259985cec69 to your computer and use it in GitHub Desktop.
Save fakuivan/8f06e4e02a650acd07d84259985cec69 to your computer and use it in GitHub Desktop.
A hotplug script for OpenWRT systems to mount and unmount a remote CIFS partition
#!/bin/sh
# Place this file on /etc/hotplug.d/iface. Example entry (on /etc/config/fstab):
#------------------------------------------------------------
#config netmount
# option target '/mnt'
# option src '//ADDRESS/RESOURCE'
# option fstype 'cifs' #or nfs
## don't use qoutes inside the string, else the qoutes, they will not be removed
# option options 'user=USER,password=PASSWORD'
# option enabled '1'
# option network 'br-lan'
#------------------------------------------------------------
# Delete these comments if you want to preserve space on /overlay
. /lib/functions.sh
network_mount() {
local config="$1"
local enabled
local target
local src
local options
local network
local fstype
config_get_bool enabled "$config" enabled 0
for opt in target src options network fstype
do
config_get "$opt" "$config" "$opt"
done
if [ "$enabled" = 1 -a "$INTERFACE" = "$network" ]
then
if [ "$ACTION" = "ifup" ]
then
logger "NetMount: $ACTION: Mounting $src in $target"
mount -t $fstype $src $target -o "$options"
elif [ "$ACTION" = "ifdown" ]
then
logger "NetMount: $ACTION: Umounting $src from $target"
umount $target
elif [ "$ACTION" = "ifupdate" ]
then
logger "NetMount: $ACTION: DHCP renew. Leaving $src mounted in $target"
else
logger "NetMount: Unknown action $ACTION: Leaving $src mounted in $target"
fi
fi
}
config_load fstab
config_foreach network_mount netmount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment