opkg update && opkg install partx-utils kmod-fs-vfat luci-app-attendedsysupgrade usbutils parted resize2fs curl nano lsblk block-mount kmod-usb-hid kmod-usb-ohci kmod-usb3 kmod-usb-storage btrfs-progs nvme-cli smartmontools iperf3 luci-app-commands luci-app-samba4 syncthing
notes: for some unknown reason classic samba server is a way faster then ksmdb if sendfile option is enabled (enable_extra_tuning), see cifsd-team/ksmbd#621
#format patrtition as btrfs
mkfs.btrfs --checksum xxhash -m DUP /dev/sda1 -L external
uci batch << EOF # external drive
add fstab mount # =cfg034d78
set fstab.@mount[-1].enabled='1'
set fstab.@mount[-1].label='external'
set fstab.@mount[-1].target='/mnt/external'
set fstab.@mount[-1].options='noatime,discard=async,compress=zstd:8'
EOF
uci commit
mkdir -p /mnt/external/data
#add samba user
echo "external:x:1001:1001:external:/dev/null:/bin/false" >> /etc/passwd
echo "external:x:1001:external,syncthing" >> /etc/group
chown -R external:external /mnt/external
echo -ne "mypass\nmypass\n" | smbpasswd -s -a external
uci batch << EOF # sambashare
add samba4 sambashare
set samba4.@sambashare[-1].name='external'
set samba4.@sambashare[-1].path='/mnt/external/data'
set samba4.@sambashare[-1].read_only='no'
set samba4.@sambashare[-1].users='external'
set samba4.@sambashare[-1].guest_ok='no'
set samba4.@sambashare[-1].create_mask='0666'
set samba4.@sambashare[-1].dir_mask='0777'
set samba4.@sambashare[-1].interface='lan'
set samba4.@sambashare[-1].enable_extra_tuning='1'
set samba4.@sambashare[-1].disable_async_io='1'
EOF
uci commit
Expose samba and avahi to wan, you don't need it if you don't know what is this!
uci batch << EOF #expose samba to wan
add firewall rule
set firewall.@rule[-1].name='Wan-Samba-Allow'
set firewall.@rule[-1].proto='tcp'
set firewall.@rule[-1].src='wan'
set firewall.@rule[-1].dest_port='445'
set firewall.@rule[-1].target='ACCEPT'
EOF
uci batch << EOF #expose avahi to wan
add firewall rule
set firewall.@rule[-1].name='Wan-Avahi-Allow'
set firewall.@rule[-1].proto='udp'
set firewall.@rule[-1].src='wan'
set firewall.@rule[-1].dest_port='5353'
set firewall.@rule[-1].target='ACCEPT'
EOF
uci commit
mkdir -p /mnt/external/syncthing
#add samba user to syncthing group
sed -i -e 's/:syncthing/:syncthing,external/g' /etc/group
uci batch << EOF # syncthing
set syncthing.syncthing.enabled='1'
set syncthing.syncthing.logfile='/mnt/external/syncthing'
set syncthing.syncthing.home='/mnt/external/syncthing'
set syncthing.syncthing.macprocs=1
EOF
uci batch << EOF #expose syncthing UI to wan
add firewall rule
set firewall.@rule[-1].name='Wan-SSH-Allow'
set firewall.@rule[-1].proto='tcp'
set firewall.@rule[-1].src='wan'
set firewall.@rule[-1].dest_port='22'
set firewall.@rule[-1].target='ACCEPT'
EOF
uci commit
Expose syncthing UI to wan, you don't need it if you don't know what is this!
uci batch << EOF #expose syncthing UI to wan
add firewall rule
set firewall.@rule[-1].name='Wan-Syncthing-GUI-Allow'
set firewall.@rule[-1].proto='tcp'
set firewall.@rule[-1].src='wan'
set firewall.@rule[-1].dest_port='8384'
set firewall.@rule[-1].target='ACCEPT'
EOF
uci batch << EOF #expose syncthing discovery to wan (device in you local network)
add firewall rule
set firewall.@rule[-1].name='Wan-Syncthing-Discovery-Allow'
set firewall.@rule[-1].proto='udp'
set firewall.@rule[-1].src='wan'
set firewall.@rule[-1].dest_port='21027'
set firewall.@rule[-1].target='ACCEPT'
EOF
uci commit