diff options
20 files changed, 1290 insertions, 1162 deletions
diff --git a/packages/slugos-init/files/boot/disk b/packages/slugos-init/files/boot/disk index ede33a3ee6..e8d1f5245b 100755 --- a/packages/slugos-init/files/boot/disk +++ b/packages/slugos-init/files/boot/disk @@ -3,14 +3,14 @@ # must be given) using options from the rest of # the command line. # -/sbin/leds -A '!gr' -# # Use the standard init path (see /etc/init.d/rcS) export PATH=/sbin:/bin:/usr/sbin:/usr/bin # # Load the helper functions . /etc/default/functions # +leds boot system +# if test -n "$1" then device="$1" diff --git a/packages/slugos-init/files/boot/flash b/packages/slugos-init/files/boot/flash index e0bcebc9b8..12729d7b5d 100755 --- a/packages/slugos-init/files/boot/flash +++ b/packages/slugos-init/files/boot/flash @@ -1,14 +1,14 @@ #!/bin/sh # boot from the current (flash) root partition -# nothing need be done, make the power led flash -# amber to indicate runlevel S -/sbin/leds -A '!gr' -exec /sbin/init +# nothing need be done apart from setting the +# system LED status correctly +. /etc/default/functions +leds beep +leds boot system +test -x /sbin/init && exec /sbin/init # fallback if /sbin/init has been deleted (bad!) -# flashing amber/red - failed early boot -# disk lights flashing: failed in flash boot! -/sbin/leds +A '!g12' +leds boot system panic exec <>/dev/console >&0 2>&0 -exec /sbin/sulogin -exec /bin/sh +test -x /sbin/sulogin && exec /sbin/sulogin +test -x /bin/sh && exec /bin/sh exit 1 diff --git a/packages/slugos-init/files/boot/network b/packages/slugos-init/files/boot/network index 02b226d1f3..599250e744 100755 --- a/packages/slugos-init/files/boot/network +++ b/packages/slugos-init/files/boot/network @@ -11,15 +11,6 @@ # 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 -mac="$(config mac)" iface="$(config iface)" -if test -n "$mac" -a -n "$iface" -a "$mac" != "00:00:00:00:00:00" -a "$mac" != "FF:FF:FF:FF:FF:FF" -then - if ifconfig "$iface" hw ether "$mac" && - ifup "$iface" - then - exit 0 - fi -fi +test -n "$iface" && ifup "$iface" # exit code is true only if the interface config has succeeded -exit 1 diff --git a/packages/slugos-init/files/boot/nfs b/packages/slugos-init/files/boot/nfs index 534d8b7cb0..5f1cbbe323 100755 --- a/packages/slugos-init/files/boot/nfs +++ b/packages/slugos-init/files/boot/nfs @@ -3,7 +3,8 @@ # must be given) using options from the rest of # the command line. # -/sbin/leds -A '!gr' +. /etc/default/functions +leds boot system # # Use the standard init path (see /etc/init.d/rcS) export PATH=/sbin:/bin:/usr/sbin:/usr/bin diff --git a/packages/slugos-init/files/boot/ram b/packages/slugos-init/files/boot/ram index 66d46a7089..42ff8329f9 100755 --- a/packages/slugos-init/files/boot/ram +++ b/packages/slugos-init/files/boot/ram @@ -3,14 +3,15 @@ # must be given) using options from the rest of # the command line. # -/sbin/leds -A '!gr' -# # Use the standard init path (see /etc/init.d/rcS) export PATH=/sbin:/bin:/usr/sbin:/usr/bin # # Load the helper functions . /etc/default/functions # +leds beep double +leds boot system +# if test -n "$1" then device="$1" diff --git a/packages/slugos-init/files/conffiles b/packages/slugos-init/files/conffiles index 51a8091b1e..68dd26d897 100644 --- a/packages/slugos-init/files/conffiles +++ b/packages/slugos-init/files/conffiles @@ -25,7 +25,7 @@ preserve etc/.configured preserve etc/TZ diff etc/default/conffiles diff etc/default/devpts -diff etc/default/rcS +preserve etc/default/rcS preserve etc/default/sysconf diff etc/default/usbd preserve etc/defaultdomain diff --git a/packages/slugos-init/files/functions b/packages/slugos-init/files/functions index e90f03aead..d7e5c9905a 100755 --- a/packages/slugos-init/files/functions +++ b/packages/slugos-init/files/functions @@ -1,5 +1,41 @@ +#!/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;; + *NSLU2*) echo nslu2;; + *) echo unknown;; + 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: @@ -27,90 +63,81 @@ mtsize(){ # sysvalof "section" "name" "configuration file" # sysval "section" "name" # outputs the value of the SysConf variable 'name' from section 'section', -# this is a bit gross, when it gets a match it copies the value to the -# hold space, if no match it jumps over the copy, at the end ($) it copies -# the hold space to the pattern space and prints the result, thus it only -# ever prints the last match -# BUG FIX: busybox sed doesn't initialise the hold space and crashes if it -# is used before initialisation, so temporarily this script does it's own -# tail by hand. +# 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 and in the -# recovering case (zero or absent SysConf) /etc/default/sysconf only contains -# the hw_addr entry! +# below if necessary. This is because 'config' does the defaulting. sysvalmatch(){ - # sed -n '/^\['"$1"'\]$/,/^\[.*\]$/s/^'"$2"'=\('"$3"'\)$/\1/;tH;bE;:H;h;:E;$g;$p' "$4" sed -n '/^\['"$1"'\]$/,/^\[.*\]$/s/^'"$2"'=\('"$3"'\)$/\1/p' "$4" | sed -n '$p' } sysvalof(){ sysvalmatch "$1" "$2" '.*' "$3" } sysval(){ - sysvalof "$1" "$2" /etc/default/sysconf + 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! Validity -# of the sysconf file is determined by the presence of the all important -# hw_addr. +# 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 /etc/default/sysconf && - mac="$(sysvalmatch network hw_addr '[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]' /etc/default/sysconf)" - if test -n "$mac" - then - case "$1" in - 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 - else - echo "$mac" | sed -n 's/^..:..:..:\(..\):\(..\):\(..\)$/LKG\1\2\3/p' - 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) return 0;; - *) return 1;; - esac - else - # These are the defaults for an invalid mac address, use the compiled - # in hardware address. - case "$1" in - mac) echo "00:02:B3:02:02:01";; - host) echo "brokenslug";; - iface) echo eth0;; - ip) echo 192.168.1.77;; - boot) echo dhcp;; - *) return 1;; - esac - fi + 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" @@ -130,11 +157,13 @@ checkmount(){ # basic test for init (the kernel will try to load this) # but require a shell in bin/sh and no .recovery too test \( ! -f "$1/.recovery" \) -a \ - \( -d "$1/initrd" -o -d "$1/mnt" \) -a \ + \( -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" \) + -x "$1/etc/init" -o -h "$1/etc/init" -o \ + -x "$1/bin/init" -o -h "$1/bin/init" \) } # # swivel "new root" "old root" @@ -147,7 +176,7 @@ checkmount(){ # Normally this function never returns! # On return 0,1,2 are connected to /dev/console - this may not # have been true before! -swivel() { +swivel(){ cd "$1" exec <&- >&- 2>&- # This is just-in-case the called mounted /proc and was @@ -169,11 +198,26 @@ swivel() { # 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. - exec usr/sbin/chroot . bin/sh -c "\ + 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 - leds -A +gr1 '!g1' + mount -t sysfs sysfs /mnt + echo -n timer >/mnt/class/leds/ready/trigger + echo -n timer >/mnt/class/leds/status/trigger + echo -n 80 >/mnt/class/leds/ready/frequency + echo -n 80 >/mnt/class/leds/status/frequency + umount /mnt sleep 10 >/.recovery sync;sync;sync exit 1" @@ -245,7 +289,7 @@ ifdown(){ # # mountflash "flash device" "flash root directory" {mount options} # Finds and mounts the flash file system on the given directory -mountflash() { +mountflash(){ local ffsdev ffsdir ffsdev="$1" @@ -272,7 +316,7 @@ mountflash() { # 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() { +umountflash(){ local rootok ffsno ffsdev rootok=1 case "$1" in @@ -324,7 +368,7 @@ umountflash() { } # ffs_umount </proc/mounts || { - echo "$0: umount $ffsdev from all mount points then re-run reflash" >&2 + echo "$0: umount $ffsdev from all mount points then re-run $0" >&2 return 1 } diff --git a/packages/slugos-init/files/initscripts/sysconfsetup b/packages/slugos-init/files/initscripts/sysconfsetup index 4111633a2b..a4f9074d9c 100644 --- a/packages/slugos-init/files/initscripts/sysconfsetup +++ b/packages/slugos-init/files/initscripts/sysconfsetup @@ -7,225 +7,40 @@ # point at which the rootfs will be mounted rw even if the kernel # booted with it ro. # -# rm or mv the file to run this again. If this is done the -# following configuration files will be rewritten: +# rm or mv the file (/etc/default/sysconf) to recreate it, run this +# script with the reload option to overwrite the system files. The +# configuration files described in sysconf_reload (in +# /sbin/sysconf) will be overwritten on reload. # -# /etc/default/sysconf -# /etc/hostname -# /etc/defaultdomain -# /etc/network/interfaces -# /etc/resolv.conf +# start: standard startup, do a complete (auto) restore if necessary +# reinit: always do a complete auto restore +# reload: just reload sysconf (no config files!) # # /etc/default/functions contains useful utility functions - it's # in a separate file so that it can be loaded by any script . /etc/default/functions +load_functions sysconf || exit 1 # -config valid && test "$1" != reload && exit 0 -# -# Utility to deal with absence of DNS configuration -echodns(){ - local dns - if test $# -gt 0 - then - for dns in "$@" - do - echo "nameserver $dns" - done - fi -} -# -# The SysConf device must exist in /dev at this point for this script -# to work. -# -# It is important not to hard-wire the name of the device because of -# the posibility of changing the flash partition layout. -# -# The block device is used here because at present udev does not -# show the character devices -sysdev= -config valid || sysdev="$(mtblockdev SysConf)" -if test -n "$sysdev" -a -b "$sysdev" -then - # Read the defined part of SysConf into /etc/default/sysconf. - # SysConf has lines of two forms: - # - # [section] - # name=value - # - # In practice SysConf 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 - # 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) - devio "<<$sysdev" cpb fb1,10 | sed -n '/^\[[^][]*\]$/p; - s/^lan_interface=ixp0$/lan_interface=eth0/; - /^ip_addr=192\.168\.1\.77$/,/^bootproto/s/^bootproto=static$/bootproto=dhcp/; - /^[-a-zA-Z0-9_][-a-zA-Z0-9_]*=/p' >/etc/default/sysconf - # - # The SysConf must have a hardware id, if it doesn't it has - # probably been erased or never set in the first place and the - # hardware id is retrieved from the RedBoot partition. This is - # the only thing which cannot be defaulted. -fi -# -# Error recovery: no SysConf or invalid SysConf. Make a new one from the -# RedBoot hardware ID information. -# NOTE: this block of code overwrites the shell script arguments. -config valid || { - reddev="$(mtblockdev RedBoot)" - initmac= - if test -n "$reddev" -a -b "$reddev" - then - # The hardware id starts 80 bytes before the end of the - # block, the block ends (or should end) with the signature - # <4 bytes> sErCoMm <bytes> sErCoMm. Note that devio 'pf' - # empties the stack. - set -- $(devio "<<$reddev" ' - <= $80- - .= @ - pf %02X - A= 5 - $( 1 - A= @,A1- - pf :%02X - $) A - pn - <=f4+;cp7;pn - <=$7-;cp7;pn') - if test $# -eq 3 -a "$2" = sErCoMm -a "$3" = sErCoMm +case "$1" in +start) test -s /etc/default/sysconf || { + if sysconf_read then - initmac="$1" - fi - fi - # - # APEX: may need extra code to set initmac here. - # - if test -n "$initmac" - then - # - # Generate a complete /etc/default/sysconf based on just - # one number ;-) - { echo '[network]' - echo "hw_addr=$initmac" - } >/etc/default/sysconf - # - # See /etc/default/functions (the config function) for - # the derivation of the rest of the information. - fi -} -# -# The config function will now return the correct values - even if sysconf -# is still missing. 'config valid' says if valid configuration information -# is available. -# -# Set up the 'standard' files in the root file system (these couldn't be set -# up before because they depend on stuff which RedBoot puts into SysConf from -# the ID info on the specific machine - in particular the hardware address of -# eth0, which must be the one assigned for *this* box!) -# -# HOSTNAME: defaults to LGK<mac> i.e. something derived from -# the ethernet hardware. LinkSys documentation explains how -# to determine this. Set by the user in linksys setup software. -# DOMAINNAME: LinkSys puts this in w_d_name. -test -n "$(config host)" && config host >/etc/hostname -domain="$(config domain)" -test -n "$domain" && echo "$domain" >/etc/defaultdomain -# -# 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. The -# lan_interface config value must exist for the file to be -# overwritten here. -iface="$(config iface)" -if test -n "$iface" -then - 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 - # - mac="$(config mac)" - 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 NSLU2 built-in ethernet" - echo "auto $iface" - echo "# Automatically generated from /etc/default/sysconf" - if config valid - then - echo "# The pre-up option must always be supplied, regardless" - echo "# of configuration, to set the hardware correctly." - echo "# Severe network problems may result if this option is" - echo "# removed." - c= + if sysconf_valid + then + sysconf_restore auto + else + sysconf_reload + fi else - echo "# WARNING: improperly configured network interface." - echo "# WARNING: the pre-up line must be corrected or severe" - echo "# WARNING: network problems may result." - c='#' - mac='<WARNING: unknown hardware address>' + sysconf_default + sysconf_reload fi - echo "iface $iface inet $boot" - echo "${c} pre-up ifconfig $iface hw ether $mac" - # 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" - } >/etc/network/interfaces -fi -# -# The DNS server information gives up to three nameservers, but this -# currently only binds in the first. -{ - test -n "$domain" && echo "search $domain" - echodns $(config dns) $(config dns1) $(config dns2) -} >/etc/resolv.conf -# -# Invalid config must be handled, do this by hacking /etc/motd. -if config valid -then - echo "Host name: $(config host)" - echo "Host ID: $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 disk|nfs -i <device> options to initialise a non-flash root" - echo "Use 'turnup help' for more information" -else - echo "+=====================================================================+" - echo "| +-----------------------+ |" - echo "| | INITIALISATION FAILED | |" - echo "| +-----------------------+ |" - echo "| |" - echo "| This machine has been booted with a temporary ethernet id |" - echo "| The initialisation failed because the machine id was not available |" - echo "| within the flash memory of the NSLU2. You must run: |" - echo "| |" - echo "| turnup init |" - echo "| |" - echo "| To correct this problem. Severe network problems may occur if this |" - echo "| is not done. |" - echo "+=====================================================================+" -fi >/etc/motd + };; + +reload) test -s /etc/default/sysconf || sysconf_read || sysconf_default + sysconf_reload;; + +reinit) sysconf_restore auto;; -exit 0 +*) ;; +esac diff --git a/packages/slugos-init/files/initscripts/umountinitrd.sh b/packages/slugos-init/files/initscripts/umountinitrd.sh index da39b425f8..9cb1f7a25d 100644 --- a/packages/slugos-init/files/initscripts/umountinitrd.sh +++ b/packages/slugos-init/files/initscripts/umountinitrd.sh @@ -4,15 +4,21 @@ # if the directory /initrd is not present, if this fails # then the /initrd is mounted and we want to remount that # ro - this works round the shutdown -r hang problem -umount /mnt 2>/dev/null || { - # need the device for a remount - . /etc/default/functions - ffspart=Flashdisk - ffsdev="$(mtblockdev $ffspart)" - if test -n "$ffsdev" -a -b "$ffsdev" - then - mount -o remount,ro "$ffsdev" /initrd - else - echo "Flashdisk: $ffsdev: flash device not found" >&2 - fi -} +. /etc/default/functions +while read device directory remainder +do + case "$directory" in + /mnt) echo "InitRD: unmount initrd on /mnt" >&2 + umount /mnt;; + /initrd)# need the device for a remount + ffspart=Flashdisk + ffsdev="$(mtblockdev $ffspart)" + echo "InitRD: remount $ffdev read-only on /initrd" >&2 + if test -n "$ffsdev" -a -b "$ffsdev" + then + mount -o remount,ro "$ffsdev" /initrd + else + echo "Flashdisk: $ffsdev: flash device not found" >&2 + fi;; + esac +done </proc/mounts diff --git a/packages/slugos-init/files/initscripts/zleds b/packages/slugos-init/files/initscripts/zleds index b6d2f1600b..f5bd703b65 100644 --- a/packages/slugos-init/files/initscripts/zleds +++ b/packages/slugos-init/files/initscripts/zleds @@ -4,76 +4,25 @@ # transition. It is the first 'stop' script and the last 'start' # script. # -# 'stop' sets the correct colour power LED to flash between the -# two colours of the previous and next runlevel. -# 'start' sets the LED to steady +# 'stop' indicates the start of a runlevel change +# 'start' at the end of the runlevel change - we are in the new +# runlevel. # -# The 'ready' led is used for the indication of state, except that -# if a 'status' led is used ready+status is set in place of !ready. -# -# For NSLU2: -# -# 'amber' is used for run levels S (from /linuxrc), 0 (halt), -# 1 (single user) and 6 (reboot). halt and reboot do not -# terminate therefore the LED remains flashing until the -# kernel terminates. -# -# 'green' is used for run levels 2-5 - the normal user run levels. -# -# state outputs 's' (for 'system') or 'u' (for user) to distinguish -# the required colours. -# -# NOTE: this will change +# state outputs 'system', 'user' etc according the the nature of +# the runlevel it is passed (the *new* runlevel is used). state(){ case "$1" in - S|0|1|6) echo s;; - 2|3|4|5) echo u;; - N) echo s;; + S|N) echo system;; + 0|6) echo shutdown;; + 1) echo singleuser;; + 2|3|4|5) echo user;; *) echo "led change: $runlevel: runlevel unknown" >&2 - echo s;; + echo system;; esac } -# Make the named LED do something -flash(){ - echo timer >/sys/class/leds/"$1"/trigger - echo 200 >/sys/class/leds/"$1"/frequency -} -on(){ - echo none >/sys/class/leds/"$1"/trigger - echo 100 >/sys/class/leds/"$1"/brightness -} -off(){ - echo none >/sys/class/leds/"$1"/trigger - echo 0 >/sys/class/leds/"$1"/brightness -} - -test -d /sys/class/leds/ready && case "$1" in -start) if test -d /sys/class/leds/status - then - case "$(state "$runlevel")" in - s) on status - on ready;; - u) off status - on ready;; - esac - else - on ready - fi;; -stop) if test -d /sys/class/leds/status - then - case "$(state "$previous")$(state "$runlevel")" in - ss) flash status - flash ready;; - su|us) flash status - on ready;; - uu) off status - flash ready;; - esac - else - flash ready - fi;; +case "$1" in +start) leds "$(state "$runlevel")";; +stop) leds boot "$(state "$runlevel")";; *) echo "led change: $1: command ignored" >&2;; esac - -exit 0 diff --git a/packages/slugos-init/files/kern_header.c b/packages/slugos-init/files/kern_header.c deleted file mode 100644 index 73b46eec0c..0000000000 --- a/packages/slugos-init/files/kern_header.c +++ /dev/null @@ -1,47 +0,0 @@ - -#include <stdio.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> - - -int main(int argc, char **argv) -{ - struct stat sbuf; - char *devtype; - FILE *headerfile; - unsigned int header[4]; - - - if (argc != 3) { - fprintf(stderr, "usage: %s NSLU2_kernel_file_name prepend_header_filename\nThis program builds a 16 byte header which can be prepended to a NSLU2 Kernel for reflashing\n", argv[0]); - exit (1); - } - - if (stat(argv[1], &sbuf) < 0) { - fprintf(stderr, "%s: stat: %s\n", argv[1], strerror(errno)); - exit (1); - } - - /* printf ("File %s is %d bytes long\n", argv[1], sbuf.st_size); */ - if ((headerfile=fopen(argv[2],"wb"))==NULL) - { - fprintf(stderr,"Error opening file\n"); - exit (1); - } - - if ((sbuf.st_size + 16) > 0x100000) { - fprintf(stderr,"Error Kernel + Header is > 1 MB\n"); - exit (1); - } - - header[0] = (unsigned int)sbuf.st_size + 16; - header[1] = 0; - header[2] = 0; - header[3] = 0; - if (!fwrite(&header, sizeof(unsigned int), 4, headerfile)) - fprintf(stderr,"Error write to headerfile: %s\n", strerror(errno)); - - fclose(headerfile); -} - diff --git a/packages/slugos-init/files/leds b/packages/slugos-init/files/leds new file mode 100644 index 0000000000..8132a22046 --- /dev/null +++ b/packages/slugos-init/files/leds @@ -0,0 +1,214 @@ +#!/bin/sh +# leds +# +# utilities to manipulate the settings of the system leds +# +# load the utility functions unless this script is being called +# just to load its own functions. +test "$1" != leds && { + . /etc/default/rcS + . /etc/default/functions +} + +# +# led_set led-dir off|on|slow|fast|panic|blink|flash|user|* +# set the given LED (expressed as a directory) to the +# given status. USER_LED may be set to indicate how to +# handle the 'user' setting. +led_user_default(){ + case "$(machine)" in + nslu2) echo -n "cpu-idle";; + *) echo -n "cpu-activity";; + esac +} +# +led_set(){ + local setting + # expect led-dir state + if test -d "$1" + then + setting="$2" + case "$setting" in + user) if test -n "$USER_LED" + then + setting="$USER_LED" + else + setting="$(led_user_default)" + fi;; + esac + + case "$setting" in + off|on) echo -n none + + case "$setting" in + on) echo -n 100;; + off) echo -n 0;; + esac >"$1/brightness";; + + slow|fast|panic|blink|flash) + echo -n timer + + case "$setting" in + flash) echo -n 727;; + blink) echo -n 72;; + slow) echo -n 400;; + fast) echo -n 100;; + panic) echo -n 50;; + esac >"$1/frequency" + + case "$setting" in + flash) echo -n 10;; + blink) echo -n 1000;; + *) echo -n 100;; + esac >"$1/duty_cycle";; + + cpu-idle) echo -n cpu-idle + # these settings work well on NSLU2 + echo -n 80 >"$1/frequency" + echo -n 10 >"$1/duty_cycle";; + + *) echo -n "$setting";; + esac >"$1/trigger" + else + echo "leds: $1: no such directory" >&2 + return 1 + fi +} + +# +# sysled [boot] system|user|singleuser|shutdown [error|panic|*] +# set the system LEDs to indicate the given boot state, the function +# will temporarily mount sysfs is necessary (using /mnt) +# +# the cases for two LEDs (rea |
