From 8fb6b2d3d410ad2badf0c99ed7a66b698aafaa17 Mon Sep 17 00:00:00 2001 From: Rod Whitby Date: Sat, 7 Jan 2006 08:58:44 +0000 Subject: slugos: Major rename of common SlugOS files and directories from openslug to slugos. --- .../slugos-init/files/initscripts/.mtn2git_empty | 0 .../slugos-init/files/initscripts/leds_startup | 11 + packages/slugos-init/files/initscripts/rmrecovery | 4 + .../slugos-init/files/initscripts/sysconfsetup | 231 +++++++++++++++++++++ .../slugos-init/files/initscripts/syslog.buffer | 23 ++ packages/slugos-init/files/initscripts/syslog.file | 23 ++ .../slugos-init/files/initscripts/syslog.network | 28 +++ .../slugos-init/files/initscripts/umountinitrd.sh | 18 ++ packages/slugos-init/files/initscripts/zleds | 38 ++++ 9 files changed, 376 insertions(+) create mode 100644 packages/slugos-init/files/initscripts/.mtn2git_empty create mode 100644 packages/slugos-init/files/initscripts/leds_startup create mode 100644 packages/slugos-init/files/initscripts/rmrecovery create mode 100644 packages/slugos-init/files/initscripts/sysconfsetup create mode 100644 packages/slugos-init/files/initscripts/syslog.buffer create mode 100644 packages/slugos-init/files/initscripts/syslog.file create mode 100644 packages/slugos-init/files/initscripts/syslog.network create mode 100644 packages/slugos-init/files/initscripts/umountinitrd.sh create mode 100644 packages/slugos-init/files/initscripts/zleds (limited to 'packages/slugos-init/files/initscripts') diff --git a/packages/slugos-init/files/initscripts/.mtn2git_empty b/packages/slugos-init/files/initscripts/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/slugos-init/files/initscripts/leds_startup b/packages/slugos-init/files/initscripts/leds_startup new file mode 100644 index 0000000000..945d75bd02 --- /dev/null +++ b/packages/slugos-init/files/initscripts/leds_startup @@ -0,0 +1,11 @@ +#!/bin/sh +# Bug fix: during the initial boot sysvinit sets PREVLEVEL to +# nothing in rcS and to 'N' in the transition from rcS to the +# user state. This script runs on that transition and, if +# the PREVLEVEL is 'N', sets 'previous' (as in /etc/init.d/rc) +# to 'S' +if test "$PREVLEVEL" = N +then + previous=S exec /etc/init.d/zleds stop +fi +exit 0 diff --git a/packages/slugos-init/files/initscripts/rmrecovery b/packages/slugos-init/files/initscripts/rmrecovery new file mode 100644 index 0000000000..eec822b154 --- /dev/null +++ b/packages/slugos-init/files/initscripts/rmrecovery @@ -0,0 +1,4 @@ +#!/bin/sh +# Run to remove /.recovery if the boot seems to have succeeded +test -e /.recovery && rm -f /.recovery +exit 0 diff --git a/packages/slugos-init/files/initscripts/sysconfsetup b/packages/slugos-init/files/initscripts/sysconfsetup new file mode 100644 index 0000000000..31ff38d7ee --- /dev/null +++ b/packages/slugos-init/files/initscripts/sysconfsetup @@ -0,0 +1,231 @@ +#!/bin/sh +# This script is run once when the system first boots. Its sole +# purpose is to create /etc/default/sysconf (the overall system +# configuration file) and other files derived from this. +# +# The script runs immediately after S10checkroot.sh - this is the +# 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: +# +# /etc/default/sysconf +# /etc/hostname +# /etc/defaultdomain +# /etc/network/interfaces +# /etc/resolv.conf +# +# /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 +# +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 '</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 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 + 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 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 openslug 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= + 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='' + 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 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 + +exit 0 diff --git a/packages/slugos-init/files/initscripts/syslog.buffer b/packages/slugos-init/files/initscripts/syslog.buffer new file mode 100644 index 0000000000..9285c02946 --- /dev/null +++ b/packages/slugos-init/files/initscripts/syslog.buffer @@ -0,0 +1,23 @@ +#!/bin/sh +# +# Invoke the syslog startup if the configuration +# uses (only) 'buffer' as the DESTINATION +DESTINATION= +test -f /etc/syslog.conf && . /etc/syslog.conf +doit= + +for d in $DESTINATION +do + case "$d" in + buffer) doit=1;; + file) exit 0;; + remote) exit 0;; + *) echo "/etc/syslog.conf: $d: unknown destination" >&2 + exit 1;; + esac +done + +test -n "$doit" -a -x /etc/init.d/syslog && + exec /etc/init.d/syslog "$@" + +exit 0 diff --git a/packages/slugos-init/files/initscripts/syslog.file b/packages/slugos-init/files/initscripts/syslog.file new file mode 100644 index 0000000000..80ee5f0174 --- /dev/null +++ b/packages/slugos-init/files/initscripts/syslog.file @@ -0,0 +1,23 @@ +#!/bin/sh +# +# Invoke the syslog startup if the configuration +# uses 'file' (and, optionally, buffer) as the DESTINATION +DESTINATION= +test -f /etc/syslog.conf && . /etc/syslog.conf +doit= + +for d in $DESTINATION +do + case "$d" in + buffer) :;; + file) doit=1;; + remote) exit 0;; + *) echo "/etc/syslog.conf: $d: unknown destination" >&2 + exit 1;; + esac +done + +test -n "$doit" -a -x /etc/init.d/syslog && + exec /etc/init.d/syslog "$@" + +exit 0 diff --git a/packages/slugos-init/files/initscripts/syslog.network b/packages/slugos-init/files/initscripts/syslog.network new file mode 100644 index 0000000000..3d7f4ab8e6 --- /dev/null +++ b/packages/slugos-init/files/initscripts/syslog.network @@ -0,0 +1,28 @@ +#!/bin/sh +# +# Invoke the syslog startup if the configuration +# uses 'remote', or doesn't use 'buffer' or 'file' +DESTINATION= +test -f /etc/syslog.conf && . /etc/syslog.conf +doit= +doneit= + +for d in $DESTINATION +do + case "$d" in + buffer) doneit=1;; + file) doneit=1;; + remote) doit=1;; + *) doit=1 + echo "/etc/syslog.conf: $d: unknown destination" >&2 + exit 1;; + esac +done + +# One of doneit or doit is set unless the DESTINATION value +# is empty (which is probably an error), let syslog handle +# the error. +test \( -n "$doit" -o -z "$doneit" \) -a -x /etc/init.d/syslog && + exec /etc/init.d/syslog "$@" + +exit 0 diff --git a/packages/slugos-init/files/initscripts/umountinitrd.sh b/packages/slugos-init/files/initscripts/umountinitrd.sh new file mode 100644 index 0000000000..da39b425f8 --- /dev/null +++ b/packages/slugos-init/files/initscripts/umountinitrd.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# +# umount /mnt, which is where the initrd ends up mounted +# 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 +} diff --git a/packages/slugos-init/files/initscripts/zleds b/packages/slugos-init/files/initscripts/zleds new file mode 100644 index 0000000000..c4e2b37219 --- /dev/null +++ b/packages/slugos-init/files/initscripts/zleds @@ -0,0 +1,38 @@ +#!/bin/sh +# +# This script is executed at the start and end of each run-level +# 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 +# +# 'red' is the initial setting on kernel boot +# +# '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. +# +# colours are 'g' (green), 'r' (red) or 'gr' (amber). +colour() { + case "$1" in + S|0|1|6) echo gr;; + 2|3|4|5) echo g;; + N) echo r;; + *) echo "led change: $runlevel: runlevel unknown" >&2 + echo r;; + esac +} + +# leds syntax is -A + / +case "$1" in +start) leds -gr +"$(colour "$runlevel")";; +stop) leds -gr +"$(colour "$previous")" /"$(colour "$runlevel")";; +*) echo "led change: $1: command ignored" >&2;; +esac + +exit 0 -- cgit v1.2.3