diff options
| author | Denys Dmytriyenko <denis@denix.org> | 2009-03-17 14:32:59 -0400 |
|---|---|---|
| committer | Denys Dmytriyenko <denis@denix.org> | 2009-03-17 14:32:59 -0400 |
| commit | 709c4d66e0b107ca606941b988bad717c0b45d9b (patch) | |
| tree | 37ee08b1eb308f3b2b6426d5793545c38396b838 /recipes/slugos-init | |
| parent | fa6cd5a3b993f16c27de4ff82b42684516d433ba (diff) | |
rename packages/ to recipes/ per earlier agreement
See links below for more details:
http://thread.gmane.org/gmane.comp.handhelds.openembedded/21326
http://thread.gmane.org/gmane.comp.handhelds.openembedded/21816
Signed-off-by: Denys Dmytriyenko <denis@denix.org>
Acked-by: Mike Westerhof <mwester@dls.net>
Acked-by: Philip Balister <philip@balister.org>
Acked-by: Khem Raj <raj.khem@gmail.com>
Acked-by: Marcin Juszkiewicz <hrw@openembedded.org>
Acked-by: Koen Kooi <koen@openembedded.org>
Acked-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
Diffstat (limited to 'recipes/slugos-init')
32 files changed, 4531 insertions, 0 deletions
diff --git a/recipes/slugos-init/files/README b/recipes/slugos-init/files/README new file mode 100644 index 0000000000..264d4d8f85 --- /dev/null +++ b/recipes/slugos-init/files/README @@ -0,0 +1,49 @@ +OpenSlug-1.x Family Release README + +Warning: OpenSlug is not for the faint of heart! In fact, OpenSlug has a +specific target audience. + +Some background first. According to the NSLU2 - Linux developers, there are 4 +specific types ("camps") of NSLU2 - Linux users: + + Camp #1: Users who want full Linksys compatibility (including for future + Linksys firmware releases). They can load firmware images via + the Linksys web interface and telnet in - to load Optware - + Unslung packages with ipkg, but have no idea what RedBoot is or + does. + + Camp #2: "Camp #1 Plus users." They can telnet into RedBoot (ability + to "self-rescue" a non-working NSLU2), and are comfortable + using Linux. + + Camp #3: Power users! Firmware flashing via any interface is a walk + in the park. They aren't just *users*, but are developers or + administrators of computers and/or computer software. + However, they have no JTAG or custom bootloaders. + + Camp #4: Bleeding edge users. They create and use custom bootloaders, + certainly having no need or desire for Linksys compatibility, + modifying and/or changing the hardware as well. + +With those camps in mind, OpenSlug is targetted toward Camp #3 and Camp #4 +users. If you're not in Camps 3 & 4, then you should be looking to use the +Unslung firmware. If you are a Camp #2 user, and still want to use OpenSlug, +you need to practice gaining RedBoot access, and be able to recover from bad +flashes, "drive not formatted" conditions, and other common mistakes/problems +which are documented in the NSLU2-Linux Wiki at http://www.nslu2-linux.org. +Once you are comfortable doing those things, then you may consider using +OpenSlug. + +If you're still reading - and still intent on using OpenSlug, click through +the Intel license, download the latest OpenSlug binary and flash it to your +NSLU2! (Without any HD attached while flashing!!!) Your next stop should be +the OpenSlug Turnip page at: + + http://www.nslu2-linux.org/wiki/OpenSlug/OpenSlugTurnUp + +Please add your name and information to the OpenSlug database at the yahoo +NSLU2-Linux group at: + + http://groups.yahoo.com/group/nslu2-linux/ + +Happy OpenSlugging!
\ No newline at end of file diff --git a/recipes/slugos-init/files/boot/disk b/recipes/slugos-init/files/boot/disk new file mode 100644 index 0000000000..1829033d4e --- /dev/null +++ b/recipes/slugos-init/files/boot/disk @@ -0,0 +1,83 @@ +#!/bin/sh +# boot from the hard disk partition "$1" (which +# must be given) using options from the rest of +# the command line. + +# Use the standard init path (see /etc/init.d/rcS) +export PATH=/sbin:/bin:/usr/sbin:/usr/bin + +# Mount required fileystems if necessary +[ -e /proc/cpuinfo ] || mount -t proc proc /proc +[ -e /sys/class ] || mount -t sysfs sysfs /sys + +# Load the helper functions +. /etc/default/functions +. /etc/default/modulefunctions + +leds boot system + +if test -n "$1" +then + device="$1" + shift + # load USB & SCSI storage modules (/proc required!) + echo "boot: loading modules required for disk boot" + loaddiskmods + # waiting for disk + if test "$sleep" -gt 0 + then + echo "boot: waiting $sleep seconds for disk" + sleep "$sleep" + fi + # Attempt to assemble the RAID if necessary + if (echo $device | grep -q "^/dev/md") + then + if test -n "$MDUUID" + then + echo "boot: assembling RAID array (UUID)" + mdadm -Acpartitions --auto=md --uuid="$MDUUID" $device + else + echo "boot: assembling RAID array (config file)" + mdadm -As --auto=md $device + fi + fi + + # fire the boot + echo "boot: rootfs: mount $* $device [$UUID]" + + # Mount read-write because before exec'ing init + # If a UUID is given (in the environment) this + # is used in preference to the device, but if + # the UUID mount fails a standard device mount + # is attempted. + if test -n "$UUID" && + mount "$@" UUID="$UUID" /mnt || + mount "$@" "$device" /mnt + then + # checkmount checks for sh, chroot, init, /dev + # and /mnt (i.e. /mnt/mnt in this case). + # minimaldevnodes checks (and creates if required) + # a few mandatory /dev nodes we may need. + if checkmount /mnt && minimaldevnodes /mnt + then + # pivot to /initrd if available, else /mnt + cd / + if test -d /mnt/initrd + then + swivel mnt initrd + else + swivel mnt mnt + fi + # swivel failed + fi + # Failure: unmount the partition + umount /mnt + # Remount /proc and /sys if necessary + [ -e /proc/cpuinfo ] || mount -t proc proc /proc + [ -e /sys/class ] || mount -t sysfs sysfs /sys + fi +fi + +# fallback - use the flash boot +leds beep -f 1000 -r 2 +exec /boot/flash diff --git a/recipes/slugos-init/files/boot/flash b/recipes/slugos-init/files/boot/flash new file mode 100644 index 0000000000..01c20e963a --- /dev/null +++ b/recipes/slugos-init/files/boot/flash @@ -0,0 +1,29 @@ +#!/bin/sh +# boot from the current (flash) root partition +# nothing need be done apart from setting the +# system LED status correctly + +# Mount required filesystems if necessary +[ -e /proc/cpuinfo ] || mount -t proc proc /proc +[ -e /sys/class ] || mount -t sysfs sysfs /sys + +leds beep +. /etc/default/functions +leds boot system + +if [ -x /sbin/init ] +then + umount /proc 2>/dev/null + umount /sys 2>/dev/null + exec /sbin/init +fi + +# fallback if /sbin/init has been deleted (bad!) +# Mount required filesystems if necessary +[ -e /proc/cpuinfo ] || mount -t proc proc /proc +[ -e /sys/class ] || mount -t sysfs sysfs /sys +leds boot system panic +exec <>/dev/console >&0 2>&0 +test -x /sbin/sulogin && exec /sbin/sulogin +test -x /bin/sh && exec /bin/sh +exit 1 diff --git a/recipes/slugos-init/files/boot/kexec b/recipes/slugos-init/files/boot/kexec new file mode 100644 index 0000000000..a60be03142 --- /dev/null +++ b/recipes/slugos-init/files/boot/kexec @@ -0,0 +1,203 @@ +#!/bin/sh +# +# Loads the specified kernel and kexecs it. + +# The access method and path from which to fetch the kernel +# is specified in "$1" and "$2": +# +# flash /boot/zImage-ixp4xxbe +# nfs spike:/home/slug/vmlinuz +# wget http://devserv/kernels/vmlinuzbe +# wget ftp://ftpserv/pub/zImage +# /dev/sda1 /kernels/zImage-test +# UUID /kernels/zImage-test +# tftp server:/pub/kernels/vmlinuz +# +# Command-line options for the new kernel are in "$3". + + +# In order to use this, you must exec this script from the /linuxrc file. +# +# This sample linuxrc script boots from external disk. The last line of +# this example (exec /boot/flash) is a fallback; it will not normally be +# executed unless /boot/kexec is missing or damaged. +#-------------------- +# #!/bin/sh +# sleep=8 exec /boot/kexec /dev/sda1 /boot/zImage-ixp4xxbe \ +# "console=ttyS0,115200n8 root=/dev/sda1 rootfstype=ext3 rw init=/linuxrc" +# exec /boot/flash +#-------------------- +# +# This one boots from flash in the normal fashion, except the kernel is +# loaded using wget. This is common for kernel debugging. +#-------------------- +# #!/bin/sh +# exec /boot/kexec wget http://myserver/boot/zImage-ixp4xxbe \ +# "console=ttyS0,115200n8 root=/dev/mtdblock4 rootfstype=jffs2 rw \ +# init=/boot/flash noirqdebug" +# exec /boot/flash +#-------------------- + + +# Use the standard init path (see /etc/init.d/rcS) +export PATH=/sbin:/bin:/usr/sbin:/usr/bin + +# Wait at least a short while for the disks... +if [ ! "$sleep" -gt 0 ] ; then + sleep=1 +fi + +# Load the helper functions +. /etc/default/functions +. /etc/default/modulefunctions + +# Print a distinctive banner to make it easy to separate the in-flash +# kernel boot from the kexec'd kernel boot when looking at logs, etc. +echo '###########################################################' +echo '###################### KEXEC ######################' + +leds boot system + +if [ -n "$1" -a -n "$2" ] ; then + + method="$1" + shift + kpath="$1" + shift + if [ -n "$1" ] ; then + kcmdline="$1" + shift + fi + kexec_image= + need_umount=0 + do_kexec=0 + + mount -t proc proc /proc + + case "$method" in + + flash ) + echo "Loading kexec kernel directly from \"$kpath\"..." + kexec_image="$kpath" + ;; + + wget ) + if /boot/network ; then + echo "mounting tmpfs partition..." + if mount -t tmpfs tmpfs /mnt ; then + need_umount=1 + echo "Loading kexec kernel using wget \"$kpath\"..." + wget -P /mnt "$kpath" + t=`basename "$kpath"` + kexec_image="/mnt/$t" + fi + fi + ;; + + nfs ) + if /boot/network ; then + echo "Loading kexec kernel using nfs \"$kpath\"..." + echo "mounting nfs partition..." + loadnfsmods + if mount -o ro,nolock -t nfs `dirname "$kpath"` /mnt ; then + need_umount=1 + t=`basename "$kpath"` + kexec_image="/mnt/$t" + fi + fi + ;; + + /dev/* ) + echo "Loading kexec kernel using disk \"$kpath\"..." + loaddiskmods + sleep "$sleep" + echo "mounting partition \"$method\"..." + if mount -o ro "$method" /mnt ; then + need_umount=1 + kexec_image="/mnt/$kpath" + fi + ;; + + UUID ) + echo "Loading kexec kernel using disk UUID \"$kpath\"..." + loaddiskmods + sleep "$sleep" + if [ -n "$UUID" ] ; then + echo "mounting partition UUID \"$UUID\"..." + if mount -o ro UUID="$UUID" /mnt ; then + need_umount=1 + kexec_image="/mnt/$kpath" + fi + fi + ;; + + tftp ) + if /boot/network ; then + echo "mounting tmpfs partition..." + if mount -t tmpfs tmpfs /mnt ; then + need_umount=1 + t=`basename "$kpath"` + kexec_image="/mnt/$t" + echo "Loading kexec kernel using tftp \"$kpath\"..." + tftp -g -l "$kexec_image" -r "${kpath#*:}" "${kpath%%:*}" + fi + fi + ;; + + * ) + echo "Unrecognized method: \"$method\"" + ;; + + esac + + if [ -n "$kexec_image" -a -f "$kexec_image" ] ; then + if kexec -l "$kexec_image" ; then + do_kexec=1 + fi + else + echo "Unable to load \"$kexec_image\"" + fi + + if [ $do_kexec -eq 1 -a -n "$kcmdline" ] ; then + echo "Attempting to mount /sys (sysfs)..." + if mount -t sysfs sysfs /sys ; then + echo "Setting command line:" + echo " \"$kcmdline\"" + echo "$kcmdline" > /sys/kernel/kexec_cmdline + echo "unmounting /sys..." + umount /sys + else + do_kexec=0 + fi + fi + + if [ $need_umount -eq 1 ] ; then + echo "unmounting /mnt..." + umount /mnt + fi + + if [ $do_kexec -eq 1 ] ; then + echo "Remounting root as read-only..." + mount -o remount,ro / + echo "Invoking \"kexec -f -e\" ..." + kexec -f -e + echo "ERROR!" + # We should never return here! At this point, things are not + # too well. Remount the root as rw, and fallback. + echo "Remounting root as read-write..." + mount -o remount,rw / + fi +else + echo "Usage: $0 flash|nfs|wget|UUID|/dev/<partition> <path-or-URL> [cmdline]" +fi + +# fallback - use the flash boot +echo "Falling back to flash boot..." +leds beep -f 1000 -r 2 +exec /boot/flash + +# fallback to the fallback +leds boot system panic +exec <>/dev/console >&0 2>&0 +test -x /bin/sh && exec /bin/sh +exit 1
\ No newline at end of file diff --git a/recipes/slugos-init/files/boot/network b/recipes/slugos-init/files/boot/network new file mode 100644 index 0000000000..b8054a0056 --- /dev/null +++ b/recipes/slugos-init/files/boot/network @@ -0,0 +1,41 @@ +#!/bin/sh +# bring up the network before boot, used to allow +# netconsole logging and NFS boot. This runs out +# of flash, but that's ok because the script doesn't +# leave any process running. + +# NOTE: /etc/default/functions defines ifup as a shell +# function! +. /etc/default/functions + +# We may need to load the network driver modules here +. /etc/default/modulefunctions +loadnetmods + +# Now all the information for booting should be in the configuration +# file. Config the loopback and network interfaces. +ifconfig lo 127.0.0.1 up +iface="$(config iface)" +test -z "$iface" && exit 1 + +# Fire up a process in the background to load the firmware if necessary. +# If this system doesn't require the NPE-B firmware, no problem, the +# background process will simply go away in two seconds. If it requires +# some other firmware, then modification will be required. We probably +# should replace this with mdev or some other hotplug-based technique... +sysf="/sys/class/firmware/$iface" +( + # Wait for the firware to be requested, if required + [ -f $sysf/loading ] || sleep 1 + [ -f $sysf/loading ] || sleep 1 + if [ -f $sysf/loading ] ; then + echo "1" >$sysf/loading + cat /lib/firmware/NPE-B >$sysf/data + echo "0" >$sysf/loading + fi +) & +# Trigger the firmware load proactively +ifconfig "$iface" up + +ifup "$iface" +# exit code is true only if the interface config has succeeded diff --git a/recipes/slugos-init/files/boot/nfs b/recipes/slugos-init/files/boot/nfs new file mode 100644 index 0000000000..7f91889315 --- /dev/null +++ b/recipes/slugos-init/files/boot/nfs @@ -0,0 +1,31 @@ +#!/bin/sh +# boot from the nfs partition "$1" (which +# must be given) using options from the rest of +# the command line. + +# Use the standard init path (see /etc/init.d/rcS) +export PATH=/sbin:/bin:/usr/sbin:/usr/bin + +# Mount required fileystems if necessary +[ -e /proc/cpuinfo ] || mount -t proc proc /proc +[ -e /sys/class ] || mount -t sysfs sysfs /sys + +# Load the helper functions +. /etc/default/functions +. /etc/default/modulefunctions + +leds boot system + +if /boot/network +then + # load the nfs kernel module + loadnfsmods + + # network is up and running, the NFS mount will + # now succeed (possibly), use /boot/disk + exec /boot/disk "$@" +fi + +# fallback - use the flash boot +leds beep -f 1000 -r 2 +exec /boot/flash diff --git a/recipes/slugos-init/files/boot/ram b/recipes/slugos-init/files/boot/ram new file mode 100644 index 0000000000..0a8fe1d25d --- /dev/null +++ b/recipes/slugos-init/files/boot/ram @@ -0,0 +1,64 @@ +#!/bin/sh +# boot from the hard disk partition "$1" (which +# must be given) using options from the rest of +# the command line. + +# Use the standard init path (see /etc/init.d/rcS) +export PATH=/sbin:/bin:/usr/sbin:/usr/bin + +# Mount required fileystems if necessary +[ -e /proc/cpuinfo ] || mount -t proc proc /proc +[ -e /sys/class ] || mount -t sysfs sysfs /sys + +# Load the helper functions +. /etc/default/functions + +leds beep -r 2 +leds boot system + +if test -n "$1" +then + device="$1" + shift + echo "boot: rootfs: mount $* $device" + + # prepare the device. This uses tmpfs to avoid dependency + # on non-built-in file systems and because tmpfs can expand + # to bigger than the 10MByte ram0 partition used before. + # The 'device' is currently unused. + if mount -t tmpfs "$@" tmpfs /mnt + then + cd / + # filter out boot (with zimage), linuxrc and anything + # below /var, keep dev or the boot will fail. Take + # care that nothing is mounted at this point! + umount /proc + umount /sys + find . -xdev -print | + sed '\@^./boot/@d;\@^./boot$@d;\@^./linuxrc@d;\@^./var/@d' | + cpio -p -d -m -u /mnt + # busybox find with -xdev will not print the name of the + # mountpoint, so create the empty dir manually if required. + test -d /mnt/mnt || mkdir /mnt/mnt + # checkmount checks for sh, chroot, init, /dev + # and /mnt (i.e. /mnt/mnt in this case). + # minimaldevnodes checks (and creates if required) + # a few mandatory /dev nodes we may need. + if checkmount /mnt && minimaldevnodes /mnt + then + # pivot to /mnt + cd / + swivel mnt mnt + # swivel failed + fi + # Failure: unmount the partition + umount /mnt + # Remount /proc and /sys if necessary + [ -e /proc/cpuinfo ] || mount -t proc proc /proc + [ -e /sys/class ] || mount -t sysfs sysfs /sys + fi +fi + +# fallback - use the flash boot +leds beep -f 1000 -r 2 +exec /boot/flash diff --git a/recipes/slugos-init/files/boot/udhcpc.script b/recipes/slugos-init/files/boot/udhcpc.script new file mode 100644 index 0000000000..3f437e3143 --- /dev/null +++ b/recipes/slugos-init/files/boot/udhcpc.script @@ -0,0 +1,17 @@ +#!/bin/sh +# executed by udhcpc to do the real work of configuring an interface +# writes the result (if any) to file descriptor 9 +case "$1" in +deconfig) # ignored + :;; +renew|bound) # this gives the real information + test -n "$ip" && { + echo "ip='$ip'" + echo "subnet='$subnet'" + echo "broadcast='$broadcast'" + echo "router='$router'" + } >&9;; +leasefail) # ignore - probably no dhcp server + :;; +*) echo "udhcpc: $*: command not recognised" >&2;; +esac diff --git a/recipes/slugos-init/files/conffiles b/recipes/slugos-init/files/conffiles new file mode 100644 index 0000000000..668f7467a8 --- /dev/null +++ b/recipes/slugos-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/opkg/*.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/recipes/slugos-init/files/functions b/recipes/slugos-init/files/functions new file mode 100644 index 0000000000..38a3b4d166 --- /dev/null +++ b/recipes/slugos-init/files/functions @@ -0,0 +1,427 @@ +#!/bin/sh +# . this file to load the following utility functions +# +# hardware +# the 'Hardware' string from cpuinfo +hardware(){ + sed -n 's!^Hardware *: !!p' /proc/cpuinfo +} +# +# 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;; + *DSM?G600*) echo dsmg600;; + *NSLU2*) echo nslu2;; + *FSG?3*) echo fsg3;; + *) 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(){ + sed -n 's!^\(mtd[0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/\1!p' /proc/mtd +} +# +# mtblockdev "name" +# as mtdev but output the name of the block (not character) device +mtblockdev(){ + sed -n 's!^mtd\([0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/mtdblock\1!p' /proc/mtd +} +# +# 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 "brokenslug" + 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.77 + 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 \ + \( -d "$1/dev" \) -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" \) +} +# +# minimaldevnodes "mountpoint" +# tests an already mounted mountpoint to see if a very minimal +# set of devices exists or can be created in dev, and returns +# failure if not. This is required for booting to an nfsroot +# with an empty dev directory, as commonly occurs when the rootfs +# is created from a tar.gz image. This is also required for mdev. +minimaldevnodes(){ + [ -c "$1/dev/console" ] || mknod -m 600 "$1/dev/console" c 5 1 || return 1 |
