From c4bdd84957af4623727d3384c0afff792d716b08 Mon Sep 17 00:00:00 2001 From: Graham Gower Date: Mon, 13 Sep 2010 18:15:45 +0000 Subject: foonas-init: remove broken and unused recipe. This recipe has references to non existant files in its SRC_URI, I could not find them in the git logs either. A grep -r foonas-init shows no in tree users. Signed-off-by: Graham Gower Verified with Tim Ellis and Oyvind Repvik that this can be deleted Signed-off-by: Frans Meulenbroeks --- recipes/foonas-init/files/conffiles | 55 -- recipes/foonas-init/files/functions | 413 -------------- recipes/foonas-init/files/links.conf | 6 - recipes/foonas-init/files/modulefunctions | 39 -- recipes/foonas-init/files/reflash | 163 ------ recipes/foonas-init/files/sysconf | 793 --------------------------- recipes/foonas-init/files/turnup | 861 ------------------------------ recipes/foonas-init/foonas-init_0.10.bb | 121 ----- 8 files changed, 2451 deletions(-) delete mode 100644 recipes/foonas-init/files/conffiles delete mode 100644 recipes/foonas-init/files/functions delete mode 100644 recipes/foonas-init/files/links.conf delete mode 100644 recipes/foonas-init/files/modulefunctions delete mode 100644 recipes/foonas-init/files/reflash delete mode 100644 recipes/foonas-init/files/sysconf delete mode 100644 recipes/foonas-init/files/turnup delete mode 100644 recipes/foonas-init/foonas-init_0.10.bb diff --git a/recipes/foonas-init/files/conffiles b/recipes/foonas-init/files/conffiles deleted file mode 100644 index e1408a3227..0000000000 --- a/recipes/foonas-init/files/conffiles +++ /dev/null @@ -1,55 +0,0 @@ -# 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/recipes/foonas-init/files/functions b/recipes/foonas-init/files/functions deleted file mode 100644 index 2108288ab5..0000000000 --- a/recipes/foonas-init/files/functions +++ /dev/null @@ -1,413 +0,0 @@ -#!/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 "<&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 &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/recipes/foonas-init/files/links.conf b/recipes/foonas-init/files/links.conf deleted file mode 100644 index fdd1f3ce23..0000000000 --- a/recipes/foonas-init/files/links.conf +++ /dev/null @@ -1,6 +0,0 @@ -# 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/recipes/foonas-init/files/modulefunctions b/recipes/foonas-init/files/modulefunctions deleted file mode 100644 index 430e376ad8..0000000000 --- a/recipes/foonas-init/files/modulefunctions +++ /dev/null @@ -1,39 +0,0 @@ -#!/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/recipes/foonas-init/files/reflash b/recipes/foonas-init/files/reflash deleted file mode 100644 index f2947822f6..0000000000 --- a/recipes/foonas-init/files/reflash +++ /dev/null @@ -1,163 +0,0 @@ -#!/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 " - 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/recipes/foonas-init/files/sysconf b/recipes/foonas-init/files/sysconf deleted file mode 100644 index 8866c076b8..0000000000 --- a/recipes/foonas-init/files/sysconf +++ /dev/null @@ -1,793 +0,0 @@ -#!/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 '</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 options to initialise a non-flash root" - echo "Use 'turnup help' for more information" - } >"$config_root/etc/motd" -} - -# -# sysconf_save_conffiles -# preserve the configuration files in a directory or in a CPIO archive -# (which is *not* compressed). If is a directory the files are -# copied, otherwise a CPIO archive is made with that name. 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 " >&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," - echo "two character abbreviations may be used:" - echo - echo " keep: retain the old file, overwrite the new flash image file" - echo " upgrade: retain the new file, the old (saved) file is not used" - echo " diff: display the differences between the old and the new using diff -u" - echo " shell: temporarily start an interactive shell (sh -i), exit to continue" - echo " skip: ignore this file for the moment. The file is left in the directory" - echo " $saved and many be handled after this script has completed" -} -# -sysconf_verify() { - local command file - - # return 1 here causes the file not to be overwritten, - # control should never get here! - test -n "$sysconf_noninteractive" && { - echo "$0: $*: changed file cannot be handled non-interactively" >&2 - return 1 - } - - file="$1" - echo "$0: $file: configuration file changed." - sysconf_verify_help "$file" - while : - do - echo -n "option: " - read command - case "$command" in - ke*) return 0;; - up*) rm "$saved/$file" - return 1;; - di*) echo "DIFF OLD($saved) NEW($ffsdir)" - diff -u "$saved/$file" "$ffsdir/$file";; - sh*) PS1="$file: " sh -i;; - sk*) return 1;; - *) sysconf_verify_help "$file";; - esac - done -} -# the same, but for a link -sysconf_verify_link() { - local command link - - # return 1 here causes the file not to be overwritten, - # control should never get here! - test -n "$sysconf_noninteractive" && { - echo "$0: $*: changed link cannot be handled non-interactively" >&2 - return 1 - } - - link="$1" - echo "reflash: $link: configuration link changed." - sysconf_verify_help "$link" - while : - do - echo -n "option: " - read command - case "$command" in - ke*) return 0;; - up*) rm "$saved/$link" - return 1;; - di*) echo "DIFF:" - echo "OLD($saved): $link -> $(readlink "$saved/$link")" - echo "NEW($ffsdir): $link -> $(readlink "$ffsdir/$link")";; - sh*) PS1="$link: " sh -i;; - sk*) return 1;; - *) sysconf_verify_help "$link";; - esac - done -} - -# -# sysconf_restore_conffiles -# restore the configuration files from a directory. 'source-dir' -# If is a directory of files from sysconf_save_conffiles. The -# list of files restored is written to the third argument (restore), -# but is not required (/dev/null would be ok). -# -# the list of files to restore is read from stdin, along with the -# processing option for each file (the format is as produced by -# sysconf_save_conffiles in the 'list' output). -sysconf_restore_conffiles(){ - local ffsdir saved restore - # these are the globals used by the above function - ffsdir="$1" - saved="$2" - restore="$3" - test -n "$ffsdir" -a -r "$ffsdir/etc/default/conffiles" -a -d "$saved" -a -n "$restore" || { - echo "restore_conffiles: invalid arguments: '$*'" >&2 - echo " usage sysconf_restore_conffiles " >&2 - return 1 - } - # - # read the list and process each given file - while read op file - do - # handle .configured specially (to preserve the original datestamp) - if test "$file" = "etc/.configured" - then - # this should definately not fail because of the test above! - if cp -a "$saved/$file" "$ffsdir/$file" - then - echo "$file" >&3 - else - echo "sysconf_restore_conffiles: $file: timestamp copy failed (ignored)" >&2 - fi - elif test -h "$saved/file" -o -h "$ffsdir/$file" - then - # new or old symbolic link - if test -h "$saved/$file" -a -h "$ffsdir/$file" && - test "$(readlink "$saved/$file")" = "$(readlink "$ffsdir/$file")" - then - # no change - echo "$file" >&3 - else - # assume a change regardless - case "$op" in - preserve) - echo "$file" - echo "$file" >&3;; - diff) # need user input - if sysconf_verify_link "$file" <>/dev/tty >&0 2>&0 - then - echo "$file" - echo "$file" >&3 - fi;; - esac - fi - else - # only overwrite if necessary - if test -e "$ffsdir/$file" && cmp -s "$saved/$file" "$ffsdir/$file" - then - # do not overwrite - echo "$file" >&3 - elif test ! -e "$ffsdir/$file" - then - # always preserve - echo "$file" - echo "$file" >&3 - else - case "$op" in - preserve) - echo "$file" - echo "$file" >&3;; - diff) # the files are different, get user input - if sysconf_verify "$file" <>/dev/tty >&0 2>&0 - then - echo "$file" - echo "$file" >&3 - fi;; - esac - fi - fi - done 3>"$restore" | (cd "$saved"; exec cpio -p -d -u "$ffsdir") -} - -# -# sysconf_test_restore -# return true only if the restore does not need to do an interactive -# compare -sysconf_test_restore(){ - local ffsdir saved - # these are the globals used by the above function - ffsdir="$1" - saved="$2" - # this is an error case, but return 0 so that the error is - # detected later - test -n "$ffsdir" -a -r "$ffsdir/etc/default/conffiles" -a -d "$saved" || - return 0 - # - # read the list and check each diff file (this is just a copy of the - # logic above with all the work removed!) - while read op file - do - # handle .configured specially (to preserve the original datestamp) - if test "$op" != diff - then - : # no diff required - elif test "$file" = "etc/.configured" - then - : # special handling - elif test -h "$saved/file" -o -h "$ffsdir/$file" - then - # new or old symbolic link - if test -h "$saved/$file" -a -h "$ffsdir/$file" && - test "$(readlink "$saved/$file")" = "$(readlink "$ffsdir/$file")" - then - : # no change - else - # assume a change regardless - return 1 - fi - else - # only overwrite if necessary - if test -e "$ffsdir/$file" && cmp -s "$saved/$file" "$ffsdir/$file" - then - : # do not overwrite - elif test ! -e "$ffsdir/$file" - then - : # always preserve - else - # a change - return 1 - fi - fi - done - - return 0 -} - -# -# sysconf_save -# save the system configuration to $syspart - $syspart must exist and -# there must be a writeable device for it. -sysconf_save(){ - local sysdev ffsdev ffsdir saved list size status - ffsdev="$(mtblockdev $ffspart)" - sysdev="$(mtblockdev $syspart)" - status=1 - if test -n "$sysdev" -a -b "$sysdev" -a -n "$ffsdev" -a -b "$ffsdev" - then - # this will succeed silently if the flash device is on / - umountflash "$ffsdev" || exit 1 - # - # Everything is umounted, now remount on a temporary directory. - ffsdir="/tmp/flashdisk.$$" - mkdir "$ffsdir" || { - echo "$0: $ffsdir: failed to create temporary directory" >&2 - exit 1 - } - # - mountflash "$ffsdev" "$ffsdir" -o ro || { - rmdir "$ffsdir" - exit 1 - } - # need temporary files for the cpio output and the listing - saved=/tmp/cpio.$$ - list=/tmp/preserve.$$ - rm -rf "$saved" "$list" - sysconf_save_conffiles "$ffsdir" "$saved" "$list" || { - echo "$0: $saved: archive of saved configuration files failed" >&2 - rm -rf "$saved" - rm "$list" - umount "$ffsdir" && rmdir "$ffsdir" || - echo "$0: $ffsdir: temporary directory cleanup failed" >&2 - return 1 - } - # ignore the error in this case: - umount "$ffsdir" && rmdir "$ffsdir" || - echo "$0: $ffsdir: temporary directory cleanup failed" >&2 - # - # we now have: - # /etc/default/sysconf the basic config - # /tmp/preserve.$$ the list of saved files - # /tmp/cpio.$$ the CPIO archive of those files - # - # make one big file with the sysconf data followed by the - # compressed archive in /tmp/sysconf.$$ - { { cat /etc/default/sysconf - echo '[preserve]' - } | sed -n '1,/^\[preserve\]^/p' - while read op file - do - echo "$op"="$file" - done <"$list" - } >/tmp/sysconf.$$ - size="$(devio "<>/tmp/sysconf.$$ - # - # more cleanup, then try to write the new sysconf to $syspart - # the format is a 4 byte big-endian length then the text data - # if the data won't fit exit with error code 7 - rm "$saved" "$list" - devio -p "<>$sysdev" ' - $( $4+ # > - !! 7 - $) 0 - wb '"$size"',4 - cp $' - case $? in - 0) echo " done" >&2 - status=0;; - 1) echo " failed" >&2 - echo " $syspart could not be written (no changes made)" >&2;; - 3) echo " failed" >&2 - echo " $syspart partially written, you may want to reset it" >&2;; - 7) echo " failed" >&2 - echo " $syspart is too small: $size bytes required" >&2 - echo " No change made" >&2;; - *) echo " failed" >&2 - echo " Internal error writing $syspart" >&2;; - esac - # - rm -f /tmp/sysconf.$$ - else - echo "sysconf save: $syspart or $ffspart partition not found" >&2 - echo " A RedBoot partition named '$syspart' must exist in the system" >&2 - echo " flash memory for this command to work, and there must be a" >&2 - echo " block device to access this partition (udev will normally" >&2 - echo " create this automatically. The flash partition contents must" >&2 - echo " also be accessible in a partition called '$ffspart'" >&2 - echo - echo " To create the $syspart partition use the 'fis create' command" >&2 - echo " in the RedBoot boot loader, it is sufficient to make the" >&2 - echo " partition one erase block in size unless you have substantially" >&2 - echo " increased the size of the files listed in /etc/default/conffiles" >&2 - fi - - return $status -} - -# -# sysconf_restore [auto] -# restore previously saved configuration information from $syspart -sysconf_restore_error(){ - local root - root="$1" - shift - # ------------------------------------------------------------------------------- - { echo " WARNING: saved configuration files not restored" - test -n "$1" && echo "$*" - echo - echo "The configuration of this machine has been reinitialised using the values" - echo "from /etc/default/sysconf, however configuration files saved in the $syspart" - echo "partition have not been restored." - echo - echo "You can restore these files by correcting any reported errors then running" - echo - echo " sysconf restore" - echo - echo "from the command line. This will completely reinitialise the configuration" - echo "using the information in the $syspart partition." - } >"$root/etc/motd" - cat "$root/etc/motd" >&2 -} -# -sysconf_restore(){ - local sysdev ffsdev ffsdir saved restore size status sysconf_noninteractive config_root - - # if set this means 'do no diff' - this avoids the code above which - # would open /dev/tty and therefore allows this stuff to be done from - # an init script - sysconf_noninteractive= - test "$1" = auto && sysconf_noninteractive=1 - - ffsdev="$(mtblockdev $ffspart)" - sysdev="$(mtblockdev $syspart)" - status=1 - if test -n "$sysdev" -a -b "$sysdev" -a -n "$ffsdev" -a -b "$ffsdev" && - sysconf_valid - then - # this will succeed silently if the flash device is on / - umountflash "$ffsdev" || exit 1 - # - # Everything is umounted, now remount on a temporary directory. - ffsdir="/tmp/flashdisk.$$" - config_root="$ffsdir" - mkdir "$ffsdir" || { - echo "$0: $ffsdir: failed to create temporary directory" >&2 - exit 1 - } - # - mountflash "$ffsdev" "$ffsdir" || { - rmdir "$ffsdir" - exit 1 - } - # - # first restore the $syspart section - sysconf_read "$ffsdir" || sysconf_default "$ffsdir" - # - # now use this to regenerate the system files - sysconf_reload "$ffsdir" - # - # now examine the [preserve] section, if it is there restore - # it if possible. - if test -n "$(syssection preserve)" - then - # 'saved' is a directory, 'restore' is a file (which is - # used to detect unrestored files). The directory needs - # to be populated with files. - saved=/tmp/cpio.$$ - restore=/tmp/restore.$$ - rm -rf "$saved" "$restore" - # - mkdir "$saved" || { - sysconf_restore_error "$ffsdir" "$saved: failed to create temporary directory" - return 1 - } - # - # the CPIO archive is gzip compressed after the text part - # of sysconf, gzip will handle the LZ stream termination - # correctly (and break the pipe) so we don't need to know - # the real length of the data - devio "<<$sysdev" '<=b4+.' 'cp $s-' | gunzip | ( - cd "$saved" - exec cpio -i -d -m -u - ) || { - rm -rf "$saved" - sysconf_restore_error "$ffsdir" "$saved: cpio -i failed" - return 1 - } - # either there must be no 'diff' files or it must - # be possible to interact with a real user. - if test -z "$sysconf_noninteractive" || - syssection preserve | sysconf_test_restore "$ffsdir" "$saved" - then - # - # remove the 'init' motd from sysconf_reload - rm "$ffsdir/etc/motd" - # - # now restore from the directory, using the information in - # the preserve section, if this fails in a non-interactive - # setting the system might not reboot - syssection preserve | - sysconf_restore_conffiles "$ffsdir" "$saved" "$restore" || { - # there is a chance of the user cleaning this up -#------------------------------------------------------------------------------ - sysconf_restore_error "$ffsdir" \ -"$0: $saved: restore of saved configuration files failed. - The flash file system is mounted on $ffsdir. - The saved files are in $saved and the list of files selected for - restore is in $restore. - You should restore any required configuration from $saved, then umount - $ffsdir and reboot." - # this prevents cleanup/umount - return 1 - } - # - # remove the copied files (i.e. the ones which were preserved) - ( cd "$saved" - exec rm $(cat "$restore") - ) - rm "$restore" - # - # clean up, files left in $saved need to be handled by the user - files="$(find "$saved" ! -type d -print)" - if test -n "$files" - then -#------------------------------------------------------------------------------ - sysconf_restore_error "$ffsdir" \ -"$0: some saved configuration files have not been handled: - -$files - -These files can be examined in $saved and restored to -$ffsdir if required. The saved files are in a temporary -directory and will not be retained across a reboot - copy then elsewhere if -you are unsure whether they are needed." - return 1 - fi - # - # so this is safe now (no files, links etc) - rm -rf "$saved" - else - rm -rf "$saved" - # non-interactive and some changed diff files - sysconf_restore_error "$ffsdir" \ -"$0: some of the saved configuration files must be -examined before restoration" - # but continue to the umount - fi - fi - # - # ignore the error in this case: - umount "$ffsdir" && rmdir "$ffsdir" || - echo "$0: $ffsdir: temporary directory cleanup failed" >&2 - status=0 - else - echo "sysconf restore: $syspart or $ffspart partition not found" >&2 - echo " You must have used 'sysconf save' to save configuration data" >&2 - echo " into the $syspart partition before using this command. The command" >&2 - echo " will restore the configuration data to the flash root partition" >&2 - echo " named '$ffspart' - this must also be accessible." >&2 - fi - - return $status -} - -# -# sysconf_help -# help text -sysconf_help(){ - # ------------------------------------------------------------------------------- - echo "sysconf: usage: sysconf read|default|reload|save|restore" >&2 - echo " read: the current $syspart partition is read into /etc/default/sysconf" >&2 - echo " default: a default /etc/default/sysconf is created" >&2 - echo " reload: system configuration files are recreated from /etc/default/sysconf" >&2 - echo " save: /etc/default/sysconf and the files listed in /etc/default/conffiles" >&2 - echo " are written to the $syspart partition" >&2 - echo " restore: the configuration information in the $syspart partition saved by" >&2 - echo " 'sysconf save' is restored" >&2 -} - -# -# the real commands -#if [ "$(machine)" = "storcenter" ]; then -# echo "sysconf not (yet) supported on storcenter" -# exit 0 -#fi -sysconf_command="$1" -test $# -gt 0 && shift -case "$sysconf_command" in -read) sysconf_read "$@";; -default)sysconf_default "$@";; -reload) sysconf_reload "$@";; -save) sysconf_save "$@";; -restore)sysconf_restore "$@";; -valid) sysconf_valid "$@";; - -sysconf)# just load the functions - ;; - -*) # help text - sysconf_help "$@";; -esac diff --git a/recipes/foonas-init/files/turnup b/recipes/foonas-init/files/turnup deleted file mode 100644 index 73befd26c9..0000000000 --- a/recipes/foonas-init/files/turnup +++ /dev/null @@ -1,861 +0,0 @@ -#!/bin/sh -# turnup -# See the help block at the end for documentation. -# -. /etc/default/functions - -# -# configuration -# The following variables control which directories in /var end -# up on the rootfs and which end up in a temporary file system. -INRAM_MEMSTICK="/var/cache /var/lock /var/log /var/run /var/tmp /var/lib/ipkg" -INRAM_NFS="/var/cache /var/lock /var/run /var/tmp" -INRAM_DISK="" - -# -# force: override certain checks -force= - -# -# pfile: the uuid/partition file -pfile=/etc/uuid_by_partition - -# -# fstype new -# The type of the file system mounted on "new" Outputs the last -# piece of information found, which should be the one for the -# currently visible mount! -fstype() { - local cwd dev mp type options pass freq result - cwd="$(cd "$1"; /bin/pwd)" - result= - while read dev mp type options pass freq - do - case "$mp" in - "$cwd") result="$type";; - esac - done {mount options} -# mount the flash device, writeable, on the given directory -get_flash() { - local ffsdir ffsdev - - ffsdir="$1" - shift - test -n "$ffsdir" -a -d "$ffsdir" || { - echo "$0: $ffsdir: internal error, flash mount point not a directory" >&2 - return 1 - } - - case "$(machine)" in - nslu2) ffsdev="$(mtblockdev Flashdisk)";; - *) ffsdev="$(mtblockdev filesystem)";; - esac - umountflash "$ffsdev" && - mountflash "$ffsdev" "$ffsdir" "$@" -} - -# -# check_rootfs [-i] -# Make sure the candidate rootfs is empty -# Environment: rootdev=device or NFS root path -check_rootfs() { - local fcount - - case "$1" in - -i) shift - case "$force" in - -f) return 0;; - esac - - fcount="$(find "$1" ! -type d -print | wc -l)" - test "$fcount" -eq 0 && return 0 - - echo "turnup: $rootdev: partition contains existing files, specify -f to overwrite" >&2 - return 1;; - *) checkmount "$1" && return 0 - - echo "turnup: $rootdev: partition does not seem to be a valid root partition" >&2 - echo " The partition must contain a full operating system. To ensure that" >&2 - echo " this is the case it is checked for the following, all of which must" >&2 - echo " exist for the bootstrap to work:" >&2 - echo - echo " 1) A directory /mnt." >&2 - echo " 2) A command line interpreter program in /bin/sh." >&2 - echo " 3) The program chroot in /sbin or /usr/sbin." >&2 - echo " 4) The program init in /sbin, /etc or /bin." >&2 - echo - echo " One or more of these items is missing. Mount $rootdev on /mnt" >&2 - echo " and examine its contents. You can use turnup disk|nfs -i -f" >&2 - echo " to copy this operating system onto the disk, but it may overwrite" >&2 - echo " files on the disk." >&2 - return 1;; - esac -} - -# -# copy_rootfs old new -# Make a copy of the given root file system, copying only the -# directories needed. The root must be the flash file system -copy_rootfs() { - local old new - old="$1" - new="$2" - test -d "$old" -a -d "$new" || { - echo "turnup: rootfs: copy $old $new: not a directory" >&2 - return 1 - } - # - # There are no problem file names in the flash file system, so - # it is possible to use -print, not -print0. The following - # files and directories are not copied: - # - # /dev/* - # /boot, /boot/* - # /linuxrc* - # /var/* - echo "turnup: copying root file system" >&2 - ( cd "$1" - find . -mount -print | - sed '\@^./dev/@d;\@^./boot/@d;\@^./boot$@d;\@^./linuxrc@d;\@^./var/@d' | - cpio -p -d -m -u "$2" - ) || { - echo "turnup: rootfs: cpio $old $new failed" >&2 - return 1 - } - echo "done" >&2 -} - -# -# setup_dev new device_table -# In flash file systems /dev is in ramfs, in disk systems /dev -# can be populated permanently. This is done by creating a -# single entry '.noram' in /dev - the devices init script will -# then populate the directory without overmounting it. The -# devices in the passed in device table are also created, but -# note that this is insufficient, /etc/init.d/devices must -# also run. -setup_dev() { - test -n "$1" -a -d "$1"/dev -a -r "$2" || { - echo "turnup: setup_dev($1,$2): expected a directory and a file" >&2 - return 1 - } - echo "turnup: initialising dev file system" >&2 - # init tries to open the following devices: - # /dev/console - # /dev/tty0 - # /dev/null - # syslog, and maybe other things, only work if fd 1 is valid, therefore - # we must create these devices here... - makedevs --root="$1" --devtable="$2" - :>"$1"/dev/.noram - return 0 -} - -# -# setup_bootdev new device_table -# As above but actually uses the supplied device table - this is possible if -# the table is just used for boot because the extra setup is not required. -setup_bootdev() { - test -n "$1" -a -d "$1"/dev -a -r "$2" || { - echo "turnup: setup_bootdev($1,$2): expected a directory and a file" >&2 - return 1 - } - # NOTE: this fails silently with 0 return code(!) when a directory - # does not exist yet things are created within it. - makedevs -r "$1" -D "$2" -} - -# -# setup_var new type -# Populates /var. -# Removes the /var tmpfs entry from /etc/fstab. -# Creates links from /var into /media/ram for NFS and Memstick. -setup_var() { - local ram_targets directory - - test -n "$1" -a -d "$1"/var || { - echo "turnup: setup_var($1,$2): expected a directory" >&2 - return 1 - } - case "$2" in - disk|nfs|memstick);; - *) echo "turnup: setup_var($1,$2): expected 'disk', 'nfs' or 'memstick'" >&2 - return 1;; - esac - # - # populate /var, there is a shell script to do this, but it uses - # absolute path names - chroot "$1" /bin/busybox sh /etc/init.d/populate-volatile.sh || { - echo "turnup: /var: could not populate directory" >&2 - return 1 - } - - case "$2" in - disk) ram_targets="$INRAM_DISK";; - nfs) ram_targets="$INRAM_NFS";; - memstick) - ram_targets="$INRAM_MEMSTICK";; - esac - - for directory in $ram_targets - do - rm -rf "$1/$directory" - ln -s "/media/ram/$directory" "$1/$directory" - done - # the startup link is left for the moment, this seems safer - #rm "$1"/etc/rc?.d/[KS]??populate-var.sh - # remove the /var tmpfs entry from the new /etc/fstab - sed -i '\@[ ]/var[ ][ ]*tmpfs[ ]@d' "$1"/etc/fstab - echo "turnup: tmpfs will no longer be mounted on /var" >&2 - # - # Previous versions of turnup removed populate-var.sh from the - # startup links, this one doesn't, so /var can be made back into - # a tmpfs just by a change to /etc/fstab. - return 0 -} - -# -# setup_syslog new -# Moves the syslog to a file - appropriate for disk and nfs types, not -# otherwise. -setup_syslog() { - test -n "$1" -a -d "$1"/etc || { - echo "turnup: setup_syslog($1): expected a directory" >&2 - return 1 - } - # - # if the syslog is to the buffer redirect it to a file - if egrep -q '^DESTINATION="buffer"' "$1"/etc/syslog.conf - then - if cp "$1"/etc/syslog.conf "$1"/etc/syslog.conf.sav - then - # the busybox syslog will fail with ROTATESIZE and ROTATEGENS - sed -i 's!DESTINATION="buffer"!DESTINATION="file"! - /^ROTATESIZE=/d - /^ROTATEGENS=/d' "$1"/etc/syslog.conf - echo "turnup: /etc/syslog.conf: changed to file buffering" >&2 - echo " Old (buffer) version in /etc/syslog.conf.sav" >&2 - echo " Log messages will be in /var/log/messages" >&2 - else - echo "turnup: /etc/syslog.conf: failed to make a copy" >&2 - echo " syslog will log to a buffer" >&2 - fi - fi - return 0 -} - -# -# setup_rootfs type new device_table -# Populates the /dev and /var directories, alters the startup to -# not mount or populate them further. Does the right thing according -# to the given $type -setup_rootfs() { - local type new table - type="$1" - new="$2" - table="$3" - - test -n "$new" -a -d "$new" -a -f "$table" || { - echo "turnup: setup_rootfs($type,$new,$table): expected a directory and a file" >&2 - return 1 - } - - case "$type" in - flash) return 0;; - disk) setup_dev "$new" "$table" && - setup_var "$new" "$type" && - setup_syslog "$new";; - memstick) - setup_bootdev "$new" "$table" && - setup_var "$new" "$type" ;; - nfs) setup_dev "$new" "$table" && - setup_var "$new" "$type" && - setup_syslog "$new";; - *) echo "turnup: setup_rootfs: $type: unknown rootfs type" >&2 - return 1;; - esac - # return code of last setup function -} - -# -# setup_fstab new fsdev fstype fsoptions -# Alters the /etc/fstab entry for / to refer to the correct device and -# have the correct type and options. Essential for checkroot to remount -# / with the correct options. Writes the initial uuid file. -# bad, since sed won't fail even if it changes nothing. -setup_fstab() { - sed -i '\@^[^ ]*[ ][ ]*/[ ]@s@^.*$@'"$2 / $3 $4 1 1"'@' "$1"/etc/fstab - egrep -q "^$2 / $3 $4 1 1\$" "$1"/etc/fstab || { - echo "turnup: /etc/fstab: root(/) entry not changed" >&2 - echo " you probably need to check the options in /etc/fstab" >&2 - echo " to ensure that the root partition is mounted correctly" >&2 - return 1 - } - # - # build $pfile - uuid_by_partition >"$1""$pfile" || - echo "turnup: $pfile: blkid failed (ignored)" >&2 - return 0 -} - -# -# boot_rootfs ( |) [options] -# Change the flash partition (not the current root!) to boot off -# the new root file system -boot_rootfs() { - local type ffs sleep device uuid opt - - type="$1" - ffs="$2" - sleep="$3" - device="$4" - uuid= - - # test this first as the test does not depend on the correctness - # of the other arguments - test -n "$ffs" -a -d "$ffs" || { - echo "turnup: boot_rootfs($type, $ffs, $device): expected directory" >&2 - return 1 - } - test -x "$ffs"/boot/"$type" || { - echo "turnup: boot_rootfs($type, $ffs, $device): invalid boot type $type" >&2 - return 1 - } - shift - shift - - case "$type" in - disk) test -n "$device" -a -b "$device" || { - echo "turnup: boot_rootfs($ffs, $type, $device): expected block device" >&2 - return 1 - } - uuid="$3" - shift 3;; - nfs) shift 2;; - flash) ;; - ram) ;; - *) echo "turnup: boot_rootfs($type, $ffs, $device): unknown type" >&2 - return 1;; - esac - - # - # The /linuxrc records the correct options to mount the device, - # since we have already mounted if correctly with these options - # we can be sure (maybe) that the boot will work. If not /boot/disk - # falls back to flash. - # - # This modifies the boot process, until this point no harm has been - # done to the system, but at this point the boot rootfs will change - rm -f "$ffs"/linuxrc.new || { - echo "turnup: boot_rootfs: failed to remove $ffs/linuxrc.new" >&2 - return 1 - } - case "$type" in - flash) ln -s "boot/flash" "$ffs"/linuxrc.new || { - echo "turnup: boot_rootfs: failed to create $ffs/linuxrc.new" >&2 - return 1 - };; - ram) { echo '#!/bin/sh' - echo 'rm -f /linuxrc.new' - echo 'ln -s boot/flash /linuxrc.new' - echo 'mv /linuxrc.new /linuxrc' - echo 'exec /boot/ram /dev/ram0' - echo 'exec /boot/flash' - } >"$ffs"/linuxrc.new && - chmod 744 "$ffs"/linuxrc.new || { - echo "turnup: boot_rootfs: failed to write $ffs/linuxrc.new" >&2 - return 1 - };; - *) { echo '#!/bin/sh' - test "$sleep" -gt 0 && echo -n "sleep='$sleep' " - test -n "$uuid" && echo -n "UUID='$uuid' " - echo -n "exec '/boot/$type' '$device'" - for opt in "$@" - do - echo -n " '$opt'" - done - echo - echo 'exec /boot/flash' - } >"$ffs"/linuxrc.new && - chmod 744 "$ffs"/linuxrc.new || { - echo "turnup: boot_rootfs: failed to write $ffs/linuxrc.new" >&2 - return 1 - };; - esac - rm -f "$ffs"/linuxrc.sav || { - echo "turnup: boot_rootfs: failed to remove $ffs/linuxrc.sav" >&2 - return 1 - } - ln "$ffs"/linuxrc "$ffs"/linuxrc.sav || { - echo "turnup: boot_rootfs: failed to save /linuxrc.sav" >&2 - return 1 - } - mv -f "$ffs"/linuxrc.new "$ffs"/linuxrc || { - echo "turnup: boot_rootfs: failed to install new /linuxrc" >&2 - return 1 - } - return 0 -} - -# -# disk [-m] [-i] [-s