hwinfo 2.6 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/sh

# If there is no hwinfo, we should create it, using the default
# file and the currently-active mac addresses. This is a hack to help
# people upgrading from older wr-switch-sw releases.
#
# This script is run late, because it will have effect at next boot only.
8
# If we run it too early, we can't get the mac address from wri1 which does
9 10 11 12 13 14 15
# not exist yet.

# This allows me to pass WRS_VERBOSE=y on the command line...
if [ -n "$WRS_VERBOSE" ]; then
    set -x
fi

16
log_output=/dev/kmsg
17

18
# This kernel has no hwinfo partition (strange...)
19 20 21 22 23
if ! grep -q hwinfo /proc/mtd; then
    # probably not an error, save script result for snmp
    echo "hwinfo_warning" > /tmp/hwinfo_read_status
    exit 0;
fi
24

25 26
if ! [ -f /wr/bin/sdb-read ]; then
    # If for some reason sdb-read is not available, don't touch hwinfo
27
    echo "Error: /wr/bin/sdb-read not available!" | tee $log_output
28 29 30 31 32
    # save script result for snmp
    echo "hwinfo_error" > /tmp/hwinfo_read_status
    exit 0;
fi

33
# Is there sdb in there? If so, nothing to do.
34 35 36 37 38
if /wr/bin/sdb-read /dev/mtd5ro > /dev/null; then
    # save script result for snmp
    echo "hwinfo_ok" > /tmp/hwinfo_read_status
    exit 0;
fi
39

40 41
echo "Creating SDB filesystem in /dev/mtd5"

42
# So, we must create an sdb file, we need the template
43
cp /wr/etc/sdb-for-dataflash.bin /tmp 
44
if [ $? -ne 0 ] ; then
45
    echo "Error: /wr/etc/sdb-for-dataflash.bin not found!" | tee $log_output
46 47 48
    echo "hwinfo_error" > /tmp/hwinfo_read_status
    exit 1
fi
49

50
# we need the eth addresses
51
ethaddr=$(ifconfig eth0 | grep HWaddr | awk '{print $5}')
52
wraddr=$(ifconfig wri1 | grep HWaddr | awk '{print $5}')
53

54
# if we run this early (upgrade mess from v4.0) there is no wri1,
55 56 57 58 59 60 61 62 63
# so pick if from the command line:
if [ "x$wraddr" = "x" ]; then
    wraddr=$(awk 'BEGIN {FS="="; RS=" "} /wr_nic.macaddr/ {print $2}' \
	/proc/cmdline)
fi
# and, to be super-pedantic, if empty use default and don't corrupt hwinfo
if [ "x$ethaddr" = "x" ]; then ethaddr="02:34:56:78:9A:BC"; fi
if [ "x$wraddr"  = "x" ]; then  wraddr="02:34:56:78:9A:00"; fi

64
# we lack sdb-write...
65 66
sed -i s,02:34:56:78:9A:BC,$ethaddr, /tmp/sdb-for-dataflash.bin
sed -i s,02:34:56:78:9A:00,$wraddr,  /tmp/sdb-for-dataflash.bin
67 68 69 70

# Create the writable device file and write in there, then remove it
test -c /dev/mtd5 || mknod /dev/mtd5 c 90 10
flash_erase /dev/mtd5 0 0
71
cat /tmp/sdb-for-dataflash.bin > /dev/mtd5
72
rm /dev/mtd5
73 74 75

# save script result for snmp
echo "hwinfo_ok" > /tmp/hwinfo_read_status
76 77 78

# reboot if hw info was updated
# Please note that reboot will take pleace after switch finishes booting
79
echo -e "\n\nOrdering reboot after hwinfo update!!!\n\n" | tee $log_output
80
reboot