Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #DEBUG=; set -x # comment/uncomment to disable/enable debug mode
- # name: ddwrt-dhcp-lease-persist.sh
- # version: 1.0.4, 29-jun-2019, by eibgrad
- # purpose: make dhcp leases persistent w/ external storage (e.g., usb)
- # script type: startup (autostart)
- # installation:
- # 1. enable jffs2 (administration->jffs2)
- # 2. enable syslogd (services->services->system log)
- # 3. use shell (telnet/ssh) to execute one of the following commands:
- # curl -kLs bit.ly/ddwrt-installer|tr -d '\r'|sh -s MxA19W1M startup
- # or
- # wget -qO - bit.ly/ddwrt-installer|tr -d '\r'|sh -s MxA19W1M startup
- # 4. modify options using vi editor (optional):
- # vi /jffs/etc/config/ddwrt-dhcp-lease-persist.startup
- # 5. reboot
- {
- # ------------------------------ BEGIN OPTIONS ------------------------------- #
- # external storage mounting point (default=/opt)
- MOUNT="/opt"
- #MOUNT="/tmp/mnt/sda1" # (hd0,0), (drive1,partition1)
- #MOUNT="/tmp/mnt/sda2" # (hd0,1), (drive1,partition2)
- # external storage directory (default=/ (root))
- DIR="$MOUNT"
- #DIR="$MOUNT/ddwrt/system_files" # example of non-root storage
- # external storage file
- FILE="$DIR/dnsmasq.leases"
- # max time (in secs) to wait for external storage to be mounted (0=infinite)
- MAX_WAIT=120
- # ------------------------------- END OPTIONS -------------------------------- #
- # ---------------------- DO NOT CHANGE BELOW THIS LINE ----------------------- #
- # start the timer
- start_time=$(date +%s)
- # wait for the external storage to be mounted
- while :; do
- # determine if external storage is mounted
- df | grep -Eq "[[:space:]]+$MOUNT\$" && break
- if [ $MAX_WAIT -gt 0 ]; then
- # exit upon reaching execution limit
- [ $(($(date +%s) - start_time)) -ge $MAX_WAIT ] && exit 1
- fi
- sleep 3
- done
- # wait for dhcp server to appear in process table
- while ! pidof dnsmasq >/dev/null 2>&1; do sleep 3; done
- # stop dhcp server
- stopservice dnsmasq && sleep 3
- # create persistent directory as necessary
- [ -d $DIR ] || mkdir -p $DIR
- # copy dhcp leases (if any) to persistent file
- [ -f $FILE ] || cp /tmp/dnsmasq.leases $FILE
- # force dhcp server to use persistent file
- ln -sf $FILE /tmp/dnsmasq.leases
- # restart dhcp server
- restart dnsmasq
- exit 0
- } 2>&1 | logger $([ ${DEBUG+x} ] && echo "-p user.debug") \
- -t $(echo $(basename $0) | grep -Eo '^.{0,23}')[$$] &
Add Comment
Please, Sign In to add comment