2 # This script is run once when the system first boots. Its sole
3 # purpose is to create /etc/default/sysconf (the overall system
4 # configuration file) and other files derived from this.
6 # The script runs immediately after S10checkroot.sh - this is the
7 # point at which the rootfs will be mounted rw even if the kernel
10 # rm or mv the file to run this again. If this is done the
11 # following configuration files will be rewritten:
13 # /etc/default/sysconf
16 # /etc/network/interfaces
19 # /etc/default/functions contains useful utility functions - it's
20 # in a separate file so that it can be loaded by any script
21 . /etc/default/functions
23 config valid && test "$1" != reload && exit 0
25 # Utility to deal with absence of DNS configuration
32 echo "nameserver $dns"
37 # The SysConf device must exist in /dev at this point for this script
40 # It is important not to hard-wire the name of the device because of
41 # the posibility of changing the flash partition layout.
43 # The block device is used here because at present udev does not
44 # show the character devices
46 config valid || sysdev="$(mtblockdev SysConf)"
47 if test -n "$sysdev" -a -b "$sysdev"
49 # Read the defined part of SysConf into /etc/default/sysconf.
50 # SysConf has lines of two forms:
55 # In practice SysConf also contains other stuff, use the command:
57 # devio '<</dev/mtd1;cpb'
59 # to examine the current settings. The badly formatted stuff
60 # is removed (to be exact, the sed script selects only lines
61 # which match one of the two above). The lan interface, which
62 # defaults to ixp0, is changed to the correct value for openslug,
63 # eth0. The bootproto, which LinkSys sets to static in manufacturing,
64 # is reset to dhcp if the IP is still the original (192.168.1.77)
65 devio "<<$sysdev" cpb fb1,10 | sed -n '/^\[[^][]*\]$/p;
66 s/^lan_interface=ixp0$/lan_interface=eth0/;
67 /^ip_addr=192\.168\.1\.77$/,/^bootproto/s/^bootproto=static$/bootproto=dhcp/;
68 /^[-a-zA-Z0-9_][-a-zA-Z0-9_]*=/p' >/etc/default/sysconf
70 # The SysConf must have a hardware id, if it doesn't it has
71 # probably been erased or never set in the first place and the
72 # hardware id is retrieved from the RedBoot partition. This is
73 # the only thing which cannot be defaulted.
76 # Error recovery: no SysConf or invalid SysConf. Make a new one from the
77 # RedBoot hardware ID information.
78 # NOTE: this block of code overwrites the shell script arguments.
80 reddev="$(mtblockdev RedBoot)"
82 if test -n "$reddev" -a -b "$reddev"
84 # The hardware id starts 80 bytes before the end of the
85 # block, the block ends (or should end) with the signature
86 # <4 bytes> sErCoMm <bytes> sErCoMm. Note that devio 'pf'
88 set -- $(devio "<<$reddev" '
100 if test $# -eq 3 -a "$2" = sErCoMm -a "$3" = sErCoMm
106 # APEX: may need extra code to set initmac here.
108 if test -n "$initmac"
111 # Generate a complete /etc/default/sysconf based on just
114 echo "hw_addr=$initmac"
115 } >/etc/default/sysconf
117 # See /etc/default/functions (the config function) for
118 # the derivation of the rest of the information.
122 # The config function will now return the correct values - even if sysconf
123 # is still missing. 'config valid' says if valid configuration information
126 # Set up the 'standard' files in the root file system (these couldn't be set
127 # up before because they depend on stuff which RedBoot puts into SysConf from
128 # the ID info on the specific machine - in particular the hardware address of
129 # eth0, which must be the one assigned for *this* box!)
131 # HOSTNAME: defaults to LGK<mac> i.e. something derived from
132 # the ethernet hardware. LinkSys documentation explains how
133 # to determine this. Set by the user in linksys setup software.
134 # DOMAINNAME: LinkSys puts this in w_d_name.
135 test -n "$(config host)" && config host >/etc/hostname
136 domain="$(config domain)"
137 test -n "$domain" && echo "$domain" >/etc/defaultdomain
139 # Ethernet information. This goes into /etc/network/interfaces,
140 # however this is only used for static setup (and this is not
141 # the default). With dhcp the openslug udhcp script,
142 # /etc/udhcpc.d/50default, loads the values from sysconf. The
143 # lan_interface config value must exist for the file to be
145 iface="$(config iface)"
148 boot="$(config boot)"
149 # Only dhcp and static are supported at present - bootp
150 # support requires installation of appropriate packages
151 # dhcp is the fail-safe
159 netmask="$(config netmask)"
160 gateway="$(config gateway)"
162 echo "# /etc/network/interfaces"
163 echo "# configuration file for ifup(8), ifdown(8)"
165 echo "# The loopback interface"
167 echo "iface lo inet loopback"
169 echo "# The NSLU2 built-in ethernet"
171 echo "# Automatically generated from /etc/default/sysconf"
174 echo "# The pre-up option must always be supplied, regardless"
175 echo "# of configuration, to set the hardware correctly."
176 echo "# Severe network problems may result if this option is"
180 echo "# WARNING: improperly configured network interface."
181 echo "# WARNING: the pre-up line must be corrected or severe"
182 echo "# WARNING: network problems may result."
184 mac='<WARNING: unknown hardware address>'
186 echo "iface $iface inet $boot"
187 echo "${c} pre-up ifconfig $iface hw ether $mac"
188 # The following are ignored for DHCP but are harmless
189 test -n "$ip" && echo " address $ip"
190 test -n "$netmask" && echo " netmask $netmask"
191 test -n "$gateway" && echo " gateway $gateway"
192 } >/etc/network/interfaces
195 # The DNS server information gives up to three nameservers, but this
196 # currently only binds in the first.
198 test -n "$domain" && echo "search $domain"
199 echodns $(config dns) $(config dns1) $(config dns2)
202 # Invalid config must be handled, do this by hacking /etc/motd.
205 echo "Host name: $(config host)"
207 echo "Network boot method: $boot"
209 static) echo "Host IP address: $ip";;
211 echo "Use 'turnup init' to reset the configuration"
212 echo "Use 'turnup disk|nfs -i <device> options to initialise a non-flash root"
213 echo "Use 'turnup help' for more information"
215 echo "+=====================================================================+"
216 echo "| +-----------------------+ |"
217 echo "| | INITIALISATION FAILED | |"
218 echo "| +-----------------------+ |"
220 echo "| This machine has been booted with a temporary ethernet id |"
221 echo "| The initialisation failed because the machine id was not available |"
222 echo "| within the flash memory of the NSLU2. You must run: |"
224 echo "| turnup init |"
226 echo "| To correct this problem. Severe network problems may occur if this |"
227 echo "| is not done. |"
228 echo "+=====================================================================+"