diff options
| author | Oyvind Repvik <nail@nslu2-linux.org> | 2007-03-07 12:48:51 +0000 |
|---|---|---|
| committer | Oyvind Repvik <nail@nslu2-linux.org> | 2007-03-07 12:48:51 +0000 |
| commit | a65cef2f115dba3e18d1e7be6e2b63c630ad83f3 (patch) | |
| tree | f668f4e7219a325162bf3eef4e33bdbd1cddaf68 /packages | |
| parent | 7d14765f8a9935fbb46dadd6da34ebfa0a03d603 (diff) | |
turbostation: More init-stuff
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/openturbostation-init/.mtn2git_empty | 0 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/.mtn2git_empty | 0 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/boot/.mtn2git_empty | 0 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/conffiles | 55 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/functions | 413 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/initscripts/.mtn2git_empty | 0 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/links.conf | 6 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/modulefunctions | 39 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/reflash | 163 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/sysconf | 793 | ||||
| -rw-r--r-- | packages/openturbostation-init/files/turnup | 861 | ||||
| -rw-r--r-- | packages/openturbostation-init/openprotium-init_0.10.bb | 148 |
12 files changed, 2478 insertions, 0 deletions
diff --git a/packages/openturbostation-init/.mtn2git_empty b/packages/openturbostation-init/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/openturbostation-init/.mtn2git_empty diff --git a/packages/openturbostation-init/files/.mtn2git_empty b/packages/openturbostation-init/files/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/openturbostation-init/files/.mtn2git_empty diff --git a/packages/openturbostation-init/files/boot/.mtn2git_empty b/packages/openturbostation-init/files/boot/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/openturbostation-init/files/boot/.mtn2git_empty diff --git a/packages/openturbostation-init/files/conffiles b/packages/openturbostation-init/files/conffiles new file mode 100644 index 0000000000..e1408a3227 --- /dev/null +++ b/packages/openturbostation-init/files/conffiles @@ -0,0 +1,55 @@ +# conffiles +# Known SlugOS configuration files. These files are preserved on +# a flash upgrade. Other configuration files, found from: +# +# /usr/lib/ipkg/*.conffiles +# /etc/*.conf +# +# are preserved too with an operation of 'diff' if they have been +# changed since /etc/.configured was created. +# +# Lines starting with # are comments, other lines have +# two fields: +# +# operation file +# +# The file must *NOT* have a leading / +# +# operation may be: +# ignore Do not preserve this file +# preserve Preserve this file unconditionally +# diff Compare file with the new version, ask if different +# +preserve linuxrc +preserve etc/.configured +preserve etc/TZ +diff etc/default/conffiles +diff etc/default/devpts +preserve etc/default/rcS +preserve etc/default/sysconf +diff etc/default/usbd +preserve etc/defaultdomain +preserve etc/dropbear/dropbear_dss_host_key +preserve etc/dropbear/dropbear_rsa_host_key +preserve etc/ssh/ssh_host_dsa_key +preserve etc/ssh/ssh_host_dsa_key.pub +preserve etc/ssh/ssh_host_rsa_key +preserve etc/ssh/ssh_host_rsa_key.pub +preserve etc/fstab +preserve etc/group +preserve etc/gshadow +preserve etc/hostname +preserve etc/hosts +preserve etc/localtime +ignore etc/modules +ignore etc/modules.conf +preserve etc/motd +preserve etc/network/interfaces +preserve etc/ntp.drift +preserve etc/passwd +preserve etc/profile +preserve etc/resolv.conf +preserve etc/shadow +preserve etc/syslog.conf +preserve etc/timezone +preserve root/.ssh/authorized_keys diff --git a/packages/openturbostation-init/files/functions b/packages/openturbostation-init/files/functions new file mode 100644 index 0000000000..2108288ab5 --- /dev/null +++ b/packages/openturbostation-init/files/functions @@ -0,0 +1,413 @@ +#!/bin/sh +# . this file to load the following utility functions +# +# hardware +# the 'Hardware' string from cpuinfo, or, if not found +# try a little harder with 'machine' +hardware(){ + local hdw + hdw=`sed -n 's!^Hardware *: !!p' /proc/cpuinfo` + test -n "$hdw" || { + hdw=`sed -n 's!^machine *: !!p' /proc/cpuinfo` + } + echo $hdw +} +# +# machine +# outputs an identifier of the current machine - i.e. the board +# slugos is running on. +machine(){ + case "$(hardware)" in + *Coyote*) echo coyote;; + *IXDPG425*) echo ixdpg425;; + *WRV54G*) echo wrv54g;; + *IXDP425*) echo ixdp425;; + *IXDP465*) echo ixdp465;; + *IXCDP1100*) echo ixcdp1100*;; + *Avila*) echo avila;; + *Loft*) echo loft;; + *NAS?100d*) echo nas100d;; + *NSLU2*) echo nslu2;; + *StorCenter*) echo storcenter;; + *) echo unknown;; + esac +} +# +# single_user_ok +# if the machine is capable of single user interaction return +# true, else return false. The result of this function is +# preempted by setting SULOGIN to 'yes' or 'ok' in /etc/default/rcS +single_user_ok() { + # list known good machines in the 'case' + test "$SULOGIN" = yes -o "$SULOGIN" = ok || + case "$(machine)" in + ixdp*|avila|loft) + test "$SULOGIN" != never;; + *) return 1;; + esac +} +# +# load_functions "source" +# load the functions in '/sbin/source' - relies on /sbin/source being +# a shell script and having support for this function. +load_functions(){ + test -n "$1" -a -x "/sbin/$1" && . "/sbin/$1" || { + echo "$0: /sbin/$1: script not found" >&2 + return 1 + } +} +# +# mtdev "name" +# return (output) the character device name for flash parition "name" +# /proc/mtd has the general form: +# dev: size erasesize name +# mtd5: 00020000 00020000 "FIS directory" +# use this rather than hard-wiring the device because the partition +# table can change - looking in /proc/mtd is more reliable. +mtdev(){ + if test $(machine) = storcenter ; then + sed -n 's!^mtd\([0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/mtd/\1!p' /proc/mtd + else + sed -n 's!^\(mtd[0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/\1!p' /proc/mtd + fi +} +# +# mtblockdev "name" +# as mtdev but output the name of the block (not character) device +mtblockdev(){ + if test "$(machine)" = storcenter ; then + sed -n 's!^mtd\([0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/mtdblock/\1!p' /proc/mtd + else + sed -n 's!^mtd\([0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/mtdblock\1!p' /proc/mtd + fi +} +# +# mtsize "name" +# the size of the partition as a hexadecimal value (with 0x at the front) +mtsize(){ + sed -n 's!^mtd[0-9][0-9]*: \([^ ]*\)[^"]*"'"$1"'"$!0x\1!p' /proc/mtd +} +# +# sysvalmatch "section" "name" 'pattern' "configuration file" +# sysvalof "section" "name" "configuration file" +# sysval "section" "name" +# outputs the value of the SysConf variable 'name' from section 'section', +# if there are multiple definitions only the last is output +# NOTE: these functions should only be used internally, add entries to 'config' +# below if necessary. This is because 'config' does the defaulting. +sysvalmatch(){ + sed -n '/^\['"$1"'\]$/,/^\[.*\]$/s/^'"$2"'=\('"$3"'\)$/\1/p' "$4" | sed -n '$p' +} +sysvalof(){ + sysvalmatch "$1" "$2" '.*' "$3" +} +sysval(){ + test -r "$config_root/etc/default/sysconf" && + sysvalof "$1" "$2" "$config_root/etc/default/sysconf" +} +# +# syssection "section" +# outputs all the values from the given section changed to the format "name value" +# (i.e. the '=' is dropped). +syssection(){ + test -r "$config_root/etc/default/sysconf" && + sed -n '/^\['"$1"'\]$/,/^\[.*\]$/s/^\([^=]*\)=\(.*\)$/\1 \2/p' "$config_root/etc/default/sysconf" +} +# +# config "value" +# convenience callers for specific values to avoid mis-typing in scripts +# NOTE: this function does the defaulting, 'sysval' does not! +# config_root: if set this will override the root where config/sysval +# looks for /etc/default/sysconf +config(){ + local mac + mac="$(test -r /proc/net/maclist && + sed -n '/^[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]$/p' /proc/net/maclist | + sed -n 1p)" + # + case "$1" in + mac) test -n "$mac" && echo "$mac";; + host) if test -n "$(sysval network disk_server_name)" + then + sysval network disk_server_name + elif test -n "$(sysval network default_server_name)" + then + sysval network default_server_name + elif test -n "$mac" + then + echo "$mac" | sed -n 's/^\(..\):\(..\):\(..\):\(..\):\(..\):\(..\)$/slug\1\2\3\4\5\6/p' + else + # because we want the name to remain constant: + echo "turbostation" + fi;; + domain) sysval network w_d_name;; + iface) if test -n "$(sysval network lan_interface)" + then + sysval network lan_interface + else + echo eth0 + fi;; + ip) if test -n "$(sysval network ip_addr)" + then + sysval network ip_addr + else + echo 192.168.1.16 + fi;; + netmask)sysval network netmask;; + gateway)sysval network gateway;; + dns) sysval network dns_server1;; + dns2) sysval network dns_server2;; + dns3) sysval network dns_server3;; + boot) if test -n "$(sysval network bootproto)" + then + sysval network bootproto + else + echo dhcp + fi;; + valid) test -r "$config_root/etc/default/sysconf" -a -n "$mac";; + *) return 1;; + esac +} +# +# checkif "iface" +# Validate an interface name by making sure that it exists +# in /proc/net/dev (and is not lo). The listing outputs the +# interface followed by a :, the check function looks for +# something of the form '$1[a-zA-Z0-9]*:' and outputs the +# part preceding the ':' +checkif(){ + sed -n '/^[ ]*lo:/d;s/^[ ]*\('"$1"'[a-zA-Z0-9]*\):.*$/\1/p;tE;d;:E;q' /proc/net/dev +} +# +# checkmount "mountpoint" +# tests an already mounted mountpoint to see whether to attempt to +# boot with this as root. Returns success if it appears ok. +checkmount(){ + # basic test for init (the kernel will try to load this) + # but require a shell in bin/sh too + test \( -d "$1/mnt" \) -a \ + \( -x "$1/bin/sh" -o -h "$1/bin/sh" \) -a \ + \( -x "$1/usr/sbin/chroot" -o -h "$1/usr/sbin/chroot" -o \ + -x "$1/sbin/chroot" -o -h "$1/sbin/chroot" \) -a \ + \( -x "$1/sbin/init" -o -h "$1/sbin/init" -o \ + -x "$1/etc/init" -o -h "$1/etc/init" -o \ + -x "$1/bin/init" -o -h "$1/bin/init" \) +} +# +# swivel "new root" "old root" +# NOTE: the arguments must be paths relative to /, bad things +# will happen if the arguments themselves start with / +# Pivot to a new root. This does all the fancy pivot_root stuff +# including closing streams and does a umount /proc - it doesn't +# matter if this fails (failure codes are ignored), but if /proc +# was mounted it must be restored by the caller on return. +# Normally this function never returns! +# On return 0,1,2 are connected to /dev/console - this may not +# have been true before! +swivel(){ + cd "$1" + exec <&- >&- 2>&- + # This is just-in-case the called mounted /proc and was + # unable to close it because of the streams + umount /proc 2>/dev/null + if pivot_root . "$2" + then + # everything must move out of the old root, this process + # is $2/bin/sh so it must die, IO is redirected + # just in case - typically it will be to a device so it + # won't hold the old root open. + # the exec here is the first point at which the old root + # is unused - before the exec regardless of the close of + # 0,1,2 above ash still has *this* shell script open! + # (it's on fd 10). + # init closes all file descriptors, there's no point + # supplying it with fds. + # NOTE: this used to use $2/usr/sbin/chroot, however on + # linux / is already . when the command is executed + # therefore it is essential to use the local (new root) + # chroot to ensure it gets the correct shared libraries. + if test -x usr/sbin/chroot -o -h usr/sbin/chroot + then + chroot=usr/sbin/chroot + elif test -x sbin/chroot -o -h sbin/chroot + then + chroot=sbin/chroot + else + chroot=chroot + fi + # + exec "$chroot" . bin/sh -c "\ + test -x sbin/init && exec sbin/init + test -x etc/init && exec etc/init + test -x bin/init && exec bin/init + mount -t sysfs sysfs /mnt + umount /mnt + sync;sync;sync + exit 1" + fi + # + # recovery - must restore the old root + cd "$2" + sbin/pivot_root . "$1" + # cd is back to $1 - either pivot_root doesn't change it and the + # chroot above was not executed, or pivot_root does change it and + # has just changed it back! + exec <>/dev/console >&0 2>&0 +} +# +# ifup "interface" +# bring that interface up with the configured ip and other +# information +ifup(){ + local ip hostname router subnet iface HOSTNAME NETMASK BROADCAST + + iface="$1" + ip="$(config ip)" + hostname="$(config host)" + router="$(config gateway)" + broadcast= + + if test -n "$ip" + then + # only if an ip was specified + subnet="$(config netmask)" + else + ip=192.168.1.77 + fi + + # First try udhcpc - note that the /boot/udhcpc.script + # simply records the values returned and the udhcpc + # is not left running so this will only work for + # the lease length time! + ifconfig "$iface" up + if test "$(config boot)" != static + then + test -n "$hostname" && HOSTNAME="-H $hostname" + # The script writes the required shell variable assignments + # to file descriptor 9 + eval $(udhcpc -i "$iface" -n -q -r "$ip" $HOSTNAME -s /boot/udhcpc.script 9>&1 >/dev/null) + fi + + test -n "$broadcast" && BROADCAST="broadcast $broadcast" + test -n "$subnet" && NETMASK="netmask $subnet" + + if ifconfig "$iface" "$ip" $NETMASK $BROADCAST + then + for route in $router + do + route add default gw "$route" dev "$iface" + done + return 0 + else + ifconfig "$iface" down + return 1 + fi +} +# +# ifdown "interface" +# take the interface down +ifdown(){ + ifconfig "$1" down +} +# +# mountflash "flash device" "flash root directory" {mount options} +# Finds and mounts the flash file system on the given directory +mountflash(){ + local ffsdev ffsdir + + ffsdev="$1" + test -n "$ffsdev" -a -b "$ffsdev" || { + echo "$0: unable to find flash file system to copy ($ffsdev)" >&2 + return 1 + } + shift + + ffsdir="$1" + test -n "$ffsdir" -a -d "$ffsdir" || { + echo "$0: mountflash $ffsdir: not a directory (internal error)" >&2 + return 1 + } + shift + + mount -t jffs2 "$@" "$ffsdev" "$ffsdir" || { + echo "$0: $ffsdev: unable to mount flash file system on $ffsdir" >&2 + return 1 + } + return 0 +} +# +# umountflash [-r] "flash device" +# unmount any instance of the given flash device, if -r is specified a mount on +# root is an error, otherwise a mount on root is ignored (and remains). +umountflash(){ + local rootok ffsno ffsdev + rootok=1 + case "$1" in + -r) rootok= + shift;; + esac + # + # The argument is ffsdev + ffsdev="$1" + ffsno="$(devio "<<$ffsdev" prd)" + test -n "$ffsno" -a "$ffsno" -ge 0 || { + echo "$0: $ffsdev: device number $ffsno is not valid, cannot continue." >&2 + return 1 + } + # + # Make sure that Flashdisk isn't mounted on / + if test -z "$rootok" -a "$(devio "<</etc/init.d/sysconfsetup" prd)" -eq "$ffsno" + then + echo "$0: $ffsdev is mounted on /, use turnup ram" >&2 + return 1 + fi + # + # The function is currently always used interactively, so output + echo "$0: umounting any existing mount of $ffsdev" >&2 + # + # check each mount point, do this last first because otherwise nested + # mounts of ffsdev cannot be umounted. + ffs_umount() { + local device mp type options stuff + + read device mp type options stuff + test -z "$device" && return 0 + + # handle following entries first + ffs_umount || return 1 + + # handle this entry, since this is currently only used for unmounting + # the flash root partition we know a file which must exist... + case "$mp/$type" in + //jffs2);; # skip / + */jffs2)test "$(devio "<<$mp/etc/init.d/sysconfsetup" prd 2>/dev/null)" -ne "$ffsno" || + umount "$mp" || { + echo "$0: $mp: unable to umount $ffsdev" >&2 + return 1 + };; + esac + + return 0 + } + # + ffs_umount </proc/mounts || { + echo "$0: umount $ffsdev from all mount points then re-run $0" >&2 + return 1 + } + + return 0 +} + +# +# uuid_by_partition +# output a list of partitions and their UUIDs +uuid_by_partition() { + blkid -c /dev/null -s UUID | sed -n 's/^\([^:]*\): .*UUID="\([^"]*\)".*$/\1 \2/p' +} + +# +# partition_of uuid +# return the partition corresponding to the UUID +partition_of() { + sed -n 's/^\([^ ]*\) '"$1"'$/\1/p' +} diff --git a/packages/openturbostation-init/files/initscripts/.mtn2git_empty b/packages/openturbostation-init/files/initscripts/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/openturbostation-init/files/initscripts/.mtn2git_empty diff --git a/packages/openturbostation-init/files/links.conf b/packages/openturbostation-init/files/links.conf new file mode 100644 index 0000000000..fdd1f3ce23 --- /dev/null +++ b/packages/openturbostation-init/files/links.conf @@ -0,0 +1,6 @@ +# This file does not exist. Please do not ask the debian maintainer about it. +# You may use it to do strange and wonderful things, at your risk. + +# The new RTC class does not create the /dev/rtc symlink, and udev rules don't get run for built-in modules. +# So it looks like we have to do this here for the moment, until someone comes up with a better idea ... +L rtc rtc0 diff --git a/packages/openturbostation-init/files/modulefunctions b/packages/openturbostation-init/files/modulefunctions new file mode 100644 index 0000000000..430e376ad8 --- /dev/null +++ b/packages/openturbostation-init/files/modulefunctions @@ -0,0 +1,39 @@ +#!/bin/sh +# "." this file, then call the appropriate routines to load modules +# you might need. This is run from /etc/rcS.d/S21loadmodules.sh +# at boot time. Possible examples are commented out, none of which +# are needed on openprotium since they are already in the kernel. + +. /etc/default/functions + + +loaddiskmods(){ + : +# modprobe scsi_mod +# modprobe sd_mod +# modprobe usbcore +# case "$(machine)" in +# nslu2) +# modprobe ehci-hcd +# modprobe ohci-hcd +# ;; +# esac +# modprobe usb-storage +} + +loadnetmods(){ + : +# modprobe af_packet +# case "$(machine)" in +# ixdp425|nslu2|nas100d) +# modprobe ixp4xx_mac +# ;; +# esac +} + +loadmiscmods(){ + : +# modprobe ixp4xx_rng +# modprobe i2c_dev +} + diff --git a/packages/openturbostation-init/files/reflash b/packages/openturbostation-init/files/reflash new file mode 100644 index 0000000000..f2947822f6 --- /dev/null +++ b/packages/openturbostation-init/files/reflash @@ -0,0 +1,163 @@ +#!/bin/sh +# +# Open Protium Reflash. This script will take a firmware image consisting +# of a compressed linux kernel image, concatentated with a jffs2 root +# filesystem image. The kernel MTD device is discovered by locating +# the MTD partition with the tag "kernel" and the filesystem MTD device +# is dicovered by locating the MTD partition with the tag "filesystem." +# There is no TOC inside the firmware images so there is no direct way +# to validate that the sizes of the parts in the firmware match the +# existing MTD partitions. So there could be a mismatch. However, a +# a mismatch size will be detect as this script mounts the newly laid +# done filesystem, a mismatch guarantees this to fail. That being said +# the script does validate the total size to prevent overwriting +# uboot. Furthermore the script makes sure the fsdev is not in use and +# that the various images are block aligned. + +flimg=$1 +if [ -z "$flimg" ]; then + echo "Usage: reflash <image file>" + exit 1 +fi + +if [ \! -f $flimg -o \! -r $flimg ]; then + # + # not a file or not readable + # + echo "error: Image file [$flimg] not available" + exit 1 +fi + +dmesg | grep StorCenter >/dev/null 2>&1 +if [ $? -ne 0 ]; then + exit 0 +fi + +blksize=512 +mtd=/proc/mtd +mtab=/proc/mounts +mntdir=/tmp/fs.$$ + +ktag=kernel +fstag=filesystem + +kdev=` grep $ktag $mtd | awk -F: '{print $1}' | sed -e 's?mtd?/dev/mtdblock/?g'` +fsdev=`grep $fstag $mtd | awk -F: '{print $1}' | sed -e 's?mtd?/dev/mtdblock/?g'` + +flsize=`ls -l $flimg | awk '{print $5}'` +ksize=`grep $ktag $mtd | awk '{print "0x" $2}'` +fssize=`grep $fstag $mtd | awk '{print "0x" $2}'` + +# +# Size comes out of dc in exp notation and test wont accept a hex number +# so dumo it in hex then use awk to convert to decimal +# +size=0x`dc 16 o $ksize $fssize + p` +size=`echo $size | awk '{printf ("%d",$1)}'` + +# +# Make sure we are block aligned +# +kblks=`dc $ksize $blksize / p` +r=`dc $ksize $blksize % p` +if [ $r -ne 0 ]; then + echo "error: Kernel partition is not block aligned." + exit 1 +fi + +# +# Make sure we are block aligned +# +fsblks=`dc $fssize $blksize / p` +r=`dc $fssize $blksize % p` +if [ $r -ne 0 ]; then + echo "error: Filesystem partition is not block aligned." + exit 1 +fi + +# +# Check to see that we have enough room +# +if [ $flsize -gt $size ]; then + echo "error: Image size is bigger then available space." + exit 1 +fi + +# +# Is fsdev mounted? +# +grep $fsdev $mtab > /dev/null 2>&1 +if [ $? -eq 0 ]; then + echo "error: $fsdev mounted" + exit 1 +fi + +# +# If root is a jffs2 then close enough, im out +# +grep jffs2 $mtab > /dev/null 2>&1 +if [ $? -eq 0 ]; then + echo "error: $fsdev may be mounted" + exit 1 +fi + + +# +# Mount fsdev and save fsdev/linuxrc +# +mkdir $mntdir /tmp/$$ +mount -t jffs2 $fsdev $mntdir +if [ $? -ne 0 ]; then + echo "error: Unable to mount $fsdev" + exit 1 +fi +echo "Preserving /linuxrc in /tmp/$$" +cp $mntdir/linuxrc* /tmp/$$ +umount $mntdir + +echo "Image:" +echo " Name : $flimg" +echo " Length: $flsize" +echo +echo "Kernel:" +echo " Device: $kdev" +echo " Length: $ksize" +echo " Blocks: $kblks" +echo +echo "Filesystem:" +echo " Device: $fsdev" +echo " Length: $fssize" +echo " Blocks: $fsblks" +echo +echo 'Ready to flash, Continue? (yes/no)' +read continue +if [ "z$continue" != "zyes" ]; then + rm -rf $mntdir /tmp/$$ + exit 0 +fi + +# +# Lets do the flash +# +echo Preserving existing flash in: $flimg.sav.$$ +dd of=$flimg.sav.$$ if=$kdev bs=$blksize count=$kblks +dd of=$flimg.sav.$$ if=$fsdev bs=$blksize count=$fsblks seek=$kblks + +echo Flashing new firmware.... +dd if=$flimg of=$kdev bs=$blksize count=$kblks +dd if=$flimg of=$fsdev bs=$blksize count=$fsblks skip=$kblks +sync +sleep 5 + +# +# Mount fsdev and restore fsdev/linuxrc +# +mount -t jffs2 $fsdev $mntdir +if [ $? -ne 0 ]; then + echo "error: Unable to re-mount $fsdev" + exit 1 +fi +echo "Restoring /linuxrc" +cp /tmp/$$/linuxrc* $mntdir +umount $mntdir +rm -rf $mntdir /tmp/$$ diff --git a/packages/openturbostation-init/files/sysconf b/packages/openturbostation-init/files/sysconf new file mode 100644 index 0000000000..8866c076b8 --- /dev/null +++ b/packages/openturbostation-init/files/sysconf @@ -0,0 +1,793 @@ +#!/bin/sh +# sysconf +# +# utility to manipulate system configuration information help +# in a RedBoot SysConf partition +# +# load the utility functions (unless this is being called just +# to load these functions!) +test "$1" != sysconf && . /etc/default/functions + +# NSLU2 flash layout is non-standard. +case "$(machine)" in +nslu2) + kpart="Kernel" + syspart="SysConf" + ffspart="Flashdisk";; +*) + kpart="kernel" + syspart="sysconfig" + ffspart="filesystem";; +esac +# +# sysconf_valid +# return true if the SysConf partition exists and seems to be +# potentially valid (it starts with a reasonable length). +sysconf_valid(){ + local sysdev + sysdev="$(mtblockdev $syspart)" + test -n "$sysdev" -a -b "$sysdev" && + devio "<<$sysdev" '!! b.10>s32768<&!' +} + +# +# sysconf_read [prefix] +# read the $syspart partition (if present) writing the result into +# /etc/default/sysconf, if the result is empty it will be removed. +sysconf_read(){ + local sysdev sedcmd mac config_root + config_root="$1" + rm -f /tmp/sysconf.new + sysdev="$(mtblockdev $syspart)" + if sysconf_valid + then + # Read the defined part of $syspart into /etc/default/sysconf. + # $syspart has lines of two forms: + # + # [section] + # name=value + # + # In practice $syspart also contains other stuff, use the command: + # + # devio '<</dev/mtd1;cpb' + # + # to examine the current settings. The badly formatted stuff + # is removed (to be exact, the sed script selects only lines + # which match one of the two above). The lan interface, which + # on NSLU2 defaults to ixp0, is changed to the correct value for + # slugos, eth0. The bootproto, which LinkSys sets to static in + # manufacturing, is reset to dhcp if the IP is still the + # original (192.168.1.77) + sedcmd='/^\[[^][]*\]$/p;' + # only do the ip_addr and lan_interface fixups on NSLU2 + if test "$(machine)" = nslu2 + then + sedcmd="$sedcmd"' + s/^lan_interface=ixp0$/lan_interface=eth0/; + /^ip_addr=192\.168\.1\.77$/,/^bootproto/s/^bootproto=static$/bootproto=dhcp/;' + fi + # always fix up the hardware addr if it is present + mac="$(config mac)" + if test -n "$mac" + then + sedcmd="$sedcmd"' + s/^hw_addr=.*$/hw_addr='"$mac"'/;' + fi + # and only print lines of the correct form + sedcmd="$sedcmd"' + /^[-a-zA-Z0-9_][-a-zA-Z0-9_]*=/p' + + devio "<<$sysdev" cpb fb1,10 | sed -n "$sedcmd" >/tmp/sysconf.new + fi + # + # test the result - sysconf must be non-empty + if test -s /tmp/sysconf.new + then + mv /tmp/sysconf.new "$config_root/etc/default/sysconf" + else + rm -f /tmp/sysconf.new + return 1 + fi +} + +# +# sysconf_default [prefix] +# Provde a default /etc/default/sysconf when there is no $syspart partition, +# or when it is invalid, this function will read from an existing sysconf, +# copying the values into the new one. +# sysconf_line tag config-tag +# write an appropriate line if the config value is non-empty +sysconf_line(){ + config "$2" | { + local value + read value + test -n "$value" && echo "$1"="$value" + } +} +# +sysconf_default(){ + local config_root + config_root="$1" + { echo '[network]' + sysconf_line hw_addr mac + sysconf_line disk_server_name host + sysconf_line w_d_name domain + sysconf_line lan_interface iface + sysconf_line ip_addr ip + sysconf_line netmask netmask + sysconf_line gateway gateway + sysconf_line dns_server1 dns + sysconf_line dns_server2 dns2 + sysconf_line dns_server3 dns3 + sysconf_line bootproto boot + } >/tmp/sysconf.new + mv /tmp/sysconf.new "$config_root/etc/default/sysconf" +} + +# +# sysconf_reload [prefix] +# read the values from /etc/default/sysconf and use these values to set +# up the following system files: +# +# /etc/hostname +# /etc/defaultdomain +# /etc/resolv.conf +# /etc/network/interfaces +# /etc/motd +# +sysconf_reload(){ + local config_root host domain iface boot ip netmask gateway ifname iftype + config_root="$1" + host="$(config host)" + test -n "$host" && echo "$host" >"$config_root/etc/hostname" + domain="$(config domain)" + test -n "$domain" && echo "$domain" >"$config_root/etc/defaultdomain" + # + # The DNS server information gives up to three nameservers, + # but this currently only binds in the first. + { + test -n "$domain" && echo "search $domain" + test -n "$(config dns)" && echo "nameserver $(config dns)" + test -n "$(config dns2)" && echo "nameserver $(config dns2)" + test -n "$(config dns3)" && echo "nameserver $(config dns3)" + } >"$config_root/etc/resolv.conf" + # + # Ethernet information. This goes into /etc/network/interfaces, + # however this is only used for static setup (and this is not + # the default). With dhcp the slugos udhcp script, + # /etc/udhcpc.d/50default, loads the values from sysconf. + iface="$(config iface)" + boot="$(config boot)" + # Only dhcp and static are supported at present - bootp + # support requires installation of appropriate packages + # dhcp is the fail-safe + case "$boot" in + dhcp|static) ;; + *) boot=dhcp;; + esac + # + ip="$(config ip)" + netmask="$(config netmask)" + gateway="$(config gateway)" + { + echo "# /etc/network/interfaces" + echo "# configuration file for ifup(8), ifdown(8)" + echo "#" + echo "# The loopback interface" + echo "auto lo" + echo "iface lo inet loopback" + echo "#" + echo "# The interface used by default during boot" + echo "auto $iface" + echo "# Automatically generated from /etc/default/sysconf" + echo "# address, netmask and gateway are ignored for 'dhcp'" + echo "# but required for 'static'" + echo "iface $iface inet $boot" + # The following are ignored for DHCP but are harmless + test -n "$ip" && echo " address $ip" + test -n "$netmask" && echo " netmask $netmask" + test -n "$gateway" && echo " gateway $gateway" + # + # Now read all the other ARPHRD_ETHER (type=1) interfaces + # and add an entry for each. + for ifname in $(test -d /sys/class/net && ls /sys/class/net) + do + if test -r "/sys/class/net/$ifname/type" -a "$ifname" != "$iface" + then + read iftype <"/sys/class/net/$ifname/type" + case "$iftype" in + 1) echo "#" + echo "# /sys/class/net/$ifname:" + echo "auto $ifname" + echo "iface $ifname inet dhcp";; + esac + fi + done + } >"$config_root/etc/network/interfaces" + # + # Finally rewrite /etc/motd + { echo "Host name: $host" + echo "Domain name: $domain" + echo "Host MAC: $(config mac)" + echo "Network boot method: $boot" + case "$boot" in + static) echo "Host IP address: $ip";; + esac + echo "Use 'turnup init' to reset the configuration" + echo "Use 'turnup preserve' to save the configuration permanently" + echo "Use 'turnup restore' to restore a previously saved configuration" + echo "Use 'turnup disk|nfs -i <device> options to initialise a non-flash root" + echo "Use 'turnup help' for more information" + } >"$config_root/etc/motd" +} + +# +# sysconf_save_conffiles <flash-directory> <dest> <list> +# preserve the configuration files in a directory or in a CPIO archive +# (which is *not* compressed). If <dest> is a directory the files are +# copied, otherwise a CPIO archive is made with that name. <list> is +# the listing file giving the preserved files and the processing option. +sysconf_save_conffiles(){ + local ffsdir dest list file + ffsdir="$1" + saved="$2" + list="$3" + test -n "$ffsdir" -a -r "$ffsdir/etc/default/conffiles" -a -n "$saved" -a -n "$list" || { + echo "sysconf_save_conffiles: invalid arguments: '$*'" >&2 + echo " usage sysconf_save_conffiles <flash-directory> <dest> <list>" >&2 + return 1 + } + # + ( cd "$ffsdir" + find etc/*.conf $(sed 's!^/!!' usr/lib/ipkg/info/*.conffiles) ! -type d -newer etc/.configured -print | + sed 's/^/diff /' + exec sed 's/#.*$//;/^[ ]*$/d' etc/default/conffiles + ) | sed 's!^/*!!' | + awk '{ op=$1; $1=""; file[$0]=op } + END{ for (f in file) if (file[f] != "ignore") print file[f] f }' | + while read op file + do + if test -e "$ffsdir/$file" + then + echo "$op $file" >&3 + echo "$file" + fi + done 3>"$list" | ( + cd "$ffsdir" + if test -d "$saved" + then + exec cpio -p -d -m -u "$saved" + else + exec cpio -o -H crc >"$saved" + fi + ) +} + +# +# sysconf_verify file +# this is called with the name of a 'diff' file which is, indeed, +# different and with all the std streams connected to the tty. It +# returns a status code to say whether (0) or not (1) to copy the +# file over. +# +# globals: the following must be defined in the calling context! +# saved: the directory containing the unpacked saved files +# ffsdir: the flash directory to which the files are being restored (/) +# +sysconf_verify_help() { + echo "Please specify how to handle this file or link, the options are as follows," |
