]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/openslug-init/openslug-init-0.10/initscripts/sysconfsetup
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / openslug-init / openslug-init-0.10 / initscripts / sysconfsetup
1 #!/bin/sh
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.
5 #
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
8 # booted with it ro.
9 #
10 # rm or mv the file to run this again.  If this is done the
11 # following configuration files will be rewritten:
12 #
13 # /etc/default/sysconf
14 # /etc/hostname
15 # /etc/defaultdomain
16 # /etc/network/interfaces
17 # /etc/resolv.conf
18 #
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
22 #
23 config valid && test "$1" != reload && exit 0
24 #
25 # Utility to deal with absence of DNS configuration
26 echodns(){
27         local dns
28         if test $# -gt 0
29         then
30                 for dns in "$@"
31                 do
32                         echo "nameserver $dns"
33                 done
34         fi
35 }
36 #
37 # The SysConf device must exist in /dev at this point for this script
38 # to work.
39 #
40 # It is important not to hard-wire the name of the device because of
41 # the posibility of changing the flash partition layout.
42 #
43 # The block device is used here because at present udev does not
44 # show the character devices
45 sysdev=
46 config valid || sysdev="$(mtblockdev SysConf)"
47 if test -n "$sysdev" -a -b "$sysdev"
48 then
49         # Read the defined part of SysConf into /etc/default/sysconf.
50         # SysConf has lines of two forms:
51         #
52         #  [section]
53         #  name=value
54         #
55         # In practice SysConf also contains other stuff, use the command:
56         #
57         #  devio '<</dev/mtd1;cpb'
58         #
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
69         #
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.
74 fi
75 #
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.
79 config valid || {
80         reddev="$(mtblockdev RedBoot)"
81         initmac=
82         if test -n "$reddev" -a -b "$reddev"
83         then
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'
87                 # empties the stack.
88                 set -- $(devio "<<$reddev" '
89                         <= $80-
90                         .= @
91                         pf %02X
92                         A= 5
93                         $( 1
94                                 A= @,A1-
95                                 pf :%02X
96                         $) A
97                         pn
98                         <=f4+;cp7;pn
99                         <=$7-;cp7;pn')
100                 if test $# -eq 3 -a "$2" = sErCoMm -a "$3" = sErCoMm
101                 then
102                         initmac="$1"
103                 fi
104         fi
105         #
106         # APEX: may need extra code to set initmac here.
107         #
108         if test -n "$initmac"
109         then
110                 #
111                 # Generate a complete /etc/default/sysconf based on just
112                 # one number ;-)
113                 {       echo '[network]'
114                         echo "hw_addr=$initmac"
115                 } >/etc/default/sysconf
116                 #
117                 # See /etc/default/functions (the config function) for
118                 # the derivation of the rest of the information.
119         fi
120 }
121 #
122 # The config function will now return the correct values - even if sysconf
123 # is still missing.  'config valid' says if valid configuration information
124 # is available.
125 #
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!)
130 #
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
138 #
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
144 # overwritten here.
145 iface="$(config iface)"
146 if test -n "$iface"
147 then
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
152         case "$boot" in
153         dhcp|static) ;;
154         *)    boot=dhcp;;
155         esac
156         #
157         mac="$(config mac)"
158         ip="$(config ip)"
159         netmask="$(config netmask)"
160         gateway="$(config gateway)"
161         {
162                 echo "# /etc/network/interfaces"
163                 echo "# configuration file for ifup(8), ifdown(8)"
164                 echo "#"
165                 echo "# The loopback interface"
166                 echo "auto lo"
167                 echo "iface lo inet loopback"
168                 echo "#"
169                 echo "# The NSLU2 built-in ethernet"
170                 echo "auto $iface"
171                 echo "# Automatically generated from /etc/default/sysconf"
172                 if config valid
173                 then
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"
177                         echo "# removed."
178                         c=
179                 else
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."
183                         c='#'
184                         mac='<WARNING: unknown hardware address>'
185                 fi
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
193 fi
194 #
195 # The DNS server information gives up to three nameservers, but this
196 # currently only binds in the first.
197 {
198         test -n "$domain" && echo "search $domain"
199         echodns $(config dns) $(config dns1) $(config dns2)
200 } >/etc/resolv.conf
201 #
202 # Invalid config must be handled, do this by hacking /etc/motd.
203 if config valid
204 then
205         echo "Host name:           $(config host)"
206         echo "Host ID:             $mac"
207         echo "Network boot method: $boot"
208         case "$boot" in
209         static) echo "Host IP address:     $ip";;
210         esac
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"
214 else
215         echo "+=====================================================================+"
216         echo "|                   +-----------------------+                         |"
217         echo "|                   | INITIALISATION FAILED |                         |"
218         echo "|                   +-----------------------+                         |"
219         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:                |"
223         echo "|                                                                     |"
224         echo "|       turnup init                                                   |"
225         echo "|                                                                     |"
226         echo "| To correct this problem.  Severe network problems may occur if this |"
227         echo "| is not done.                                                        |"
228         echo "+=====================================================================+"
229 fi >/etc/motd
230
231 exit 0