Debian NSLU2 post-install part 2

My last post about the Linksys NSLU2 was 3 months ago. I have almost everything prepared for “Debian NSLU2 post-install part 2″, but real world intruded. I lost my job due to “corporate restructuring”, and everything else seemed more urgent.

A month went by, then two months. After three months of being jobless, and now with the world’s economy going deep south, it looked like I might be in this for the long haul. So, I decided to unpack the slug from storage and continue where I left off.

Here is part 2. Basically, just a bunch of links I have in my notes, to configure various stuffs.

References

Debian on NSLU2: Tips for running Linux on a flash device
How do you set ‘swappiness’?
Debian on NSLU2: Tips for reducing memory usage
My Debian Linux on the NSLU2 installation and configuration guide
pkg-nslu2-utils

I did not apply everything in these pages, just those that were relevant. The last two links provided the starting point for hacking the beeper and LEDs to do what I wanted.

Beep IP

Here is my version of beep IP:

#!/bin/bash

# Beep IP address through internal PC speaker
# Original author: Sebastiaan Giebels, 2007
# Tested on Debian Linux @NSLU2
# http://www.pcprobleemloos.nl/nslu2/doku.php

# Modified by: chewearn, 2008
# Tested on Debian Linux @NSLU2
# Tested on Ubuntu Linux PC


# Static configurations **************
PLATFORM="NSLU2"
#PLATFORM="PC"

IPMODE="short"
#IPMODE="long"

DEBUG=0

# ***********************************


# Retrieve dot-separated ipv4 address from the ifconfig information
# using grep and cut
if [ $IPMODE == "short" ]; then
	IPADDRESS=`/sbin/ifconfig | grep -A1 "eth0" | grep "inet" | \
		cut -d "." -f 4 | cut -d " " -f 1`

	if [ $DEBUG -ge 2 ]; then
		IPADDRESS="0123456789"
	fi
fi

if [ $IPMODE == "long" ]; then
	IPADDRESS=`/sbin/ifconfig | grep -A1 "eth0" | grep "inet" | \
		cut -d ":" -f 2 | cut -d " " -f 1`

	if [ $DEBUG -ge 2 ]; then
		IPADDRESS="01.234.567.89"
	fi
fi


if [ $DEBUG -ge 1 ]; then
	echo $IPADDRESS
fi


# For all characters in dotted ipv4 address
for ((a=0; a < ${#IPADDRESS} ; a++)); do
	NUMBER=${IPADDRESS:$a:1}

	if [ $DEBUG -ge 1 ]; then
		echo $NUMBER
	fi


	if [ $NUMBER == "." ]; then
		if [ $PLATFORM == "NSLU2" ]; then
			`/usr/bin/beep -l 45 -f 10 -D 1000`
		else
			`/usr/bin/beep -l 45 -f 1000 -D 1000`
		fi
		continue
	fi

	if [ $NUMBER == 0 ]; then
		if [ $PLATFORM == "NSLU2" ]; then
			`/usr/bin/beep -l 45 -f 15 -d 150 -r 2`
		else
			`/usr/bin/beep -l 45 -f 1500 -d 150 -r 2`
		fi
	fi

	if [[ $NUMBER -ge 5 && $NUMBER -le 9 ]]; then
		NUMBER=$[$NUMBER-5]
		if [ $PLATFORM == "NSLU2" ]; then
			`/usr/bin/beep -l 45 -f 15 -D 200`
		else
			`/usr/bin/beep -l 45 -f 1500 -D 200`
		fi
	fi

	if [[ $NUMBER -ge 1 && $NUMBER -le 4 ]]; then
		if [ $PLATFORM == "NSLU2" ]; then
			`/usr/bin/beep -l 45 -f 20 -d 150 -r $NUMBER`
		else
			`/usr/bin/beep -l 45 -f 2000 -d 150 -r $NUMBER`
		fi
	fi

	sleep 1
done

USB hotplug beep and LED control

And my version of USB hotplug beep and LED control:

#!/bin/bash

LOCKFILE="/tmp/usb-hotplug.lock"

# Lock to convert multiple triggers to single run
if ( set -o noclobber; echo "$$" > "$LOCKFILE" ) 2> /dev/null; then
	trap 'rm -f "$LOCKFILE"; exit $?' INT TERM EXIT


	D1_FAST="Bus=03 Lev=01 Prnt=01 Port=02"
	D1_SLOW="Bus=01 Lev=01 Prnt=01 Port=01"
	D2_FAST="Bus=03 Lev=01 Prnt=01 Port=01"
	D2_SLOW="Bus=02 Lev=01 Prnt=01 Port=00"

	BEEP="/usr/bin/beep"
	BEEPUP="$BEEP -l 100 -f 15 -n -l 150 -f 20"
	BEEPDN="$BEEP -l 100 -f 20 -n -l 150 -f 15"

	LEDS="/usr/bin/leds"
	LED1ON="$LEDS disk-1 on"
	LED1OF="$LEDS disk-1 off"
	LED2ON="$LEDS disk-2 on"
	LED2OF="$LEDS disk-2 off"

	DEVINFOFILE="/proc/bus/usb/devices"

	D1_STAT_FILE="/tmp/whatisinusb1"
	D2_STAT_FILE="/tmp/whatisinusb2"

	D1_CURR=`grep "$D1_FAST\|$D1_SLOW" $DEVINFOFILE`
	D2_CURR=`grep "$D2_FAST\|$D2_SLOW" $DEVINFOFILE`

	D1_PREV=`cat $D1_STAT_FILE`
	D2_PREV=`cat $D2_STAT_FILE`

	if [ "$D1_CURR" != "" ] ; then
		$LED1ON
		if [ "$D1_PREV" == "" ] ; then
			$BEEPUP
		fi
	else
		$LED1OF
		if [ "$D1_PREV" != "" ] ; then
			$BEEPDN
		fi
	fi

	if [ "$D2_CURR" != "" ] ; then
		$LED2ON
		if [ "$D2_PREV" == "" ] ; then
			$BEEPUP
		fi
	else
		$LED2OF
		if [ "$D2_PREV" != "" ] ; then
			$BEEPDN
		fi
	fi

	if [ "$D1_CURR" != "$D1_PREV" ] ; then
		echo "$D1_CURR" > $D1_STAT_FILE
	fi

	if [ "$D2_CURR" != "$D2_PREV" ] ; then
		echo "$D2_CURR" > $D2_STAT_FILE
	fi


	rm -f "$LOCKFILE"
	trap - INT TERM EXIT
fi

Comments 2

  1. zcat wrote:

    Hi. Thanks for the sound info and links. My slug is a boon. I use it as a samba fileserver and DAAP server for music…Next project Solar powered with security webcam
    Methinks I’m in the same boat as you – jobless and future uncertain. I live in South Africa so the recession is global. HumHo what to do?

    Posted 20 Feb 2009 at 4:40 pm
  2. chewearn wrote:

    hi zcat
    Thanks for reading. It’s interesting how we could extend a simple device to do so many things. That’s the power of open source. :smile:

    Too bad about the global recession. I am trying my best to sit it out until recovery. Good luck!

    Posted 22 Feb 2009 at 4:18 pm

Post a Comment

Your email is never published nor shared. Required fields are marked *