Skip to content

Instantly share code, notes, and snippets.

@sfloess
Last active November 10, 2022 19:55
Show Gist options
  • Save sfloess/61e144da6ff169f346c23cceeb3ada6c to your computer and use it in GitHub Desktop.
Save sfloess/61e144da6ff169f346c23cceeb3ada6c to your computer and use it in GitHub Desktop.
DD-WRT

DD-WRT Tips and Tricks

Quickies

  • Install Entware
  • Anonymous samba share: mount.cifs //[host]/[share] [local dir] -o rw,noperm,guest,workgroup=[workgroup],sec=ntlm
    • Example: mount.cifs //192.168.168.2/exports /opt/debian/mnt/family-ap/exports -o rw,noperm,guest,workgroup=FLOSSWARE,sec=ntlm
    • Note the sec=ntlm option
  • To use things like cifs, nfs server, etc, use modprobe in your startup commands:
    • /sbin/modprobed cifs
    • /sbin/modprobe nfs
    • /sbin/modprobe nfsd
    • /sbin/modprobe isofs
  • To auto mount /opt, ensure using ext4 not xfs.

Scheduled Reboots

Great wiki article can be found here. Include something like this as part of your start-up command:

echo "startservice run_rc_shutdown; /sbin/reboot" > /tmp/restart_router
chmod a+x /tmp/restart_router
echo "[min] [hour] * * * root /tmp/restart_router" > /tmp/cron.d/restartrouter

As an example to reboot each morning at 2:00 am:

echo "startservice run_rc_shutdown; /sbin/reboot" > /tmp/restart_router
chmod a+x /tmp/restart_router
echo "00 02 * * * root /tmp/restart_router" > /tmp/cron.d/restartrouter

Running chroot Debian

#!/bin/sh

# Based on the script from https://github.com/DontBeAPadavan/chroot-debian
# umount (3 times with different flags) is from Qdebian.qpkd (qnapclub)

# Debian folder
CHROOT_DIR=`readlink -f /mnt/sda/debian`

CHROOT_SERVICES_LIST=$CHROOT_DIR/chroot-services.list

CHROOT_BIN=`which chroot`

MountedDirCount="$(/bin/mount | grep $CHROOT_DIR | wc -l)"

start() {
	if [ -f /etc/hosts ]; then
		cp /etc/hosts $CHROOT_DIR/etc/hosts
	fi
	
	if [ -f /etc/resolve.conf ]; then
		cp /etc/resolve.conf $CHROOT_DIR/etc/resolve.conf
	fi

	echo 'Starting Debian services...'
	for dir in dev dev/pts proc sys; do
		/bin/mount -o bind /$dir $CHROOT_DIR/$dir
		sleep 2
	done
	
	if [ ! -e "$CHROOT_SERVICES_LIST" ]; then
		echo 'WARNING: No Debian services defined.'
		echo "Please, define Debian services to start in $CHROOT_SERVICES_LIST file!"
		echo 'One service per line. Hint: these are script names from Debian /etc/init.d/'
	else
		for item in $(cat $CHROOT_SERVICES_LIST); do
			PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
			LC_ALL=C \
			LANGUAGE=C \
			LANG=C \
			$CHROOT_BIN $CHROOT_DIR /etc/init.d/$item start
		done
	fi
}

stop() {
	if [ -e "$CHROOT_SERVICES_LIST" ]; then
		echo 'Stopping Debian services...'
		for item in $(cat $CHROOT_SERVICES_LIST); do
			PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
			LC_ALL=C \
			LANGUAGE=C \
			LANG=C \
			$CHROOT_BIN $CHROOT_DIR /etc/init.d/$item stop
		done
	fi
	
	# device can be unstable in case we do not unmount properly
	#so we try to umount 3 times
	sleep 1
	for dir in dev/pts dev proc sys; do
		/bin/umount $CHROOT_DIR/$dir 2>/dev/null
		sleep 2
	done
	
	umount /root/.ssh
	umount ${CHROOT_DIR}/exports
	
	for dir in dev/pts dev proc sys; do
		/bin/umount -lf $CHROOT_DIR/$dir 2>/dev/null
		sleep 2
	done
	
	for dir in dev/pts dev proc sys; do
		/bin/umount -l $CHROOT_DIR/$dir 2>/dev/null
		sleep 2
	done
}

status() {
	if [ $MountedDirCount -gt 0 ]; then
		echo 'Debian services are running'
	else
		echo 'Debian services are stopped'
	fi
}

case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	restart)
		stop
		sleep 5
		start
	;;
	status)
		status
	;;
	*)
		echo "Usage: $0 (start|stop|restart|status)"
		exit 1
		;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment