Skip to content

Instantly share code, notes, and snippets.

@aarmot
Last active December 16, 2015 01:49
Show Gist options
  • Save aarmot/5357471 to your computer and use it in GitHub Desktop.
Save aarmot/5357471 to your computer and use it in GitHub Desktop.
OpenWRT NAS conf
#!/bin/sh
# Configure OpenWrt NAS
# Attached USB drive is accessible through
# 1. http://nasbox/A
# 2. CIFS - //nasbox/A
# 3. DLNA
# where "nasbox" is your router name and "A" represents one of the mountpoints below
# Names of mountpoints under /mnt/
# Specify enough to match maximum partition count on your USB drive
#
MOUNTPOINTS="A B"
# Create mountpoints
#
for m in $MOUNTPOINTS; do
mkdir -m 444 /mnt/$m
touch /mnt/$m/USB_DISK_NOT_PRESENT
ln -s /mnt/$m /www/$m
done
# Hotplug
# Assuming the disk name is "sda"
#
USBDISK=/dev/sda
i=0
uci delete fstab.@mount[0]
for m in $MOUNTPOINTS; do
uci add fstab mount
uci set fstab.@mount[-1].target=/mnt/$m
uci set fstab.@mount[-1].device=$USBDISK$((++i))
uci set fstab.@mount[-1].options=rw,sync,noatime,nodiratime
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].enabled_fsck=0
done
uci commit fstab
# Mount vfat & ntfs filesystems world-writable
sed -i -e 's|^#!/bin/sh|&\numask 0|' -e 's/ /\t/g' /etc/hotplug.d/block/??-mount
# Samba conf
#
n="$(uci get system.@system[0].hostname)"
uci set samba.@samba[0].name="$n"
uci set samba.@samba[0].workgroup="$n"
uci set samba.@samba[0].description="$n Samba server"
uci set samba.@samba[0].homes=0
for m in $MOUNTPOINTS; do
uci add samba sambashare
uci set samba.@sambashare[-1].name=$m
uci set samba.@sambashare[-1].path=/mnt/$m
uci set samba.@sambashare[-1].guest_ok=yes
uci set samba.@sambashare[-1].read_only=no
uci set samba.@sambashare[-1].create_mask='0777'
uci set samba.@sambashare[-1].dir_mask='0777'
done
uci commit samba
# DLNA conf
#
n="$(uci get system.@system[0].hostname)"
uci set minidlna.config.friendly_name="$n DLNA Server"
uci set minidlna.config.enabled=1
uci delete minidlna.config.media_dir
uci add_list minidlna.config.media_dir="/mnt"
uci commit minidlna
# -- END --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment