root/floppyfw-3.0/scripts/rc.initrd

Revision 273, 7.9 KB (checked in by root, 10 months ago)

Various fixes I should have synced earlier and one new feature (!).

Now it will attept to save and then use the last address it got from the DHCP server through reboots.

Line 
1#!/bin/sh
2
3# $Id: rc.initrd,v 1.16 2005/10/15 23:58:12 thomasez Exp $
4
5#
6# floppyfw initfile
7#
8
9. /etc/functions.inc
10
11echo "Init started OK." 
12
13PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
14TERM=linux
15export PATH TERM
16umask 022
17
18COMMAND_LINE=`cat /proc/cmdline`
19
20ROOTDEV=`echo $COMMAND_LINE |sed -e 's/$/ /' -e 's/.*source=\([^ ]*\) .*/\1/' -e 's/,/ /g' -e 's:/dev/nfs:/dev/fd0:'`
21
22set -- $ROOTDEV
23# Backward compatibility with a single device argument
24if [ $# -eq 1 ]
25then
26       set -- $1 vfat
27fi
28while [ "$1" -a "$2" ]
29do
30       SOURCE_DEV=$1
31       SOURCE_FS=$2
32       echo "Attempting to mount $SOURCE_DEV ($SOURCE_FS)"
33       load_fsmod $SOURCE_DEV $SOURCE_FS
34       if mount -t $SOURCE_FS $SOURCE_DEV /mnt/tmp
35        then
36         echo "Mounted $SOURCE_DEV on /mnt/tmp"
37         break
38       else
39         echo "Mount failed"
40       fi
41       shift; shift
42done
43
44
45#
46# Getting rid of old mounts.
47#
48
49echo "Unmounting old root"
50umount /initrd
51freeramdisk /dev/rd/0
52
53cd /
54echo 
55
56echo "Extracting filesystem: "
57[ -f /mnt/tmp/add.bz2 ] && tar -xjf /mnt/tmp/add.bz2
58[ -f /mnt/tmp/add.ffw ] && lzmacat /mnt/tmp/add.ffw | tar -x
59
60echo -n "Extracting module packages: "
61for i in /mnt/tmp/modules/*.bz2; do
62        if test -f $i
63        then
64                echo "  $i "
65                tar -xjf $i
66        fi
67done
68echo
69
70for i in /mnt/tmp/modules/*.ffw; do
71        if test -f $i
72        then
73                echo "  $i "
74                lzmacat $i | tar -x
75        fi
76done
77echo
78
79
80#Modules.
81[ -f  /mnt/tmp/modules/*.o ] && cp  /mnt/tmp/modules/*.o /lib/modules 2> /dev/null
82# cp  /mnt/tmp/modules/*.o /lib/modules 2> /dev/null
83
84
85#
86# If the ROOT device is a read-only device we might have a second
87# device where the config flies reside:
88# (The configdevice option in the append line.)
89#
90# The reason for having this as late as this is that we may have some modules
91# available that we could use (like USB-storage)
92#
93
94case $COMMAND_LINE in
95 *configdevice* ) 
96  CONFDEV=`echo $COMMAND_LINE | sed -e 's/$/ /' -e 's/.*configdevice=\([^ ]*\) .*/\1/' -e 's/,/ /g' -e 's:/dev/nfs:/dev/fd0:'`
97  echo $CONFDEV > /etc/configdevice
98  echo "You have some of your configuration on a separate medium, using it."
99  CONFDEV=`cat /etc/configdevice` 
100  mkdir /mnt/config
101  set -- $CONFDEV
102  # Backward compatibility with a single device argument
103  if [ $# -eq 1 ]
104   then
105    set -- $1 vfat
106  fi
107  while [ "$1" -a "$2" ]
108  do
109       echo "Attempting to mount $1 ($2)"
110       load_fsmod $1 $2
111       if mount -t $2 $1 /mnt/config
112        then
113         echo "Mounted $1 on /mnt/config"
114         break
115       else
116         echo "Mount failed"
117         rm -r /mnt/config
118       fi
119       shift; shift
120  done
121esac
122
123#
124# We need to do this one file at a time (could be traversing a list but then
125# we'd have to not rename it on it's way.
126# (and I'm lazy and just testing if this works at all anyway)
127#
128# The best would be to trust the user and just copy all the files on the
129# device.
130#
131
132# echo "Her er vi"
133# set -x
134# set -e
135# exec >/tmp/${0##*/}.log
136
137CONFIG_FILES="config ethers hosts modules.lst firewall.ini network.ini"
138
139for cf in $CONFIG_FILES 
140  do
141    if [ -f /mnt/config/$cf ]
142   then
143    stripcr /mnt/config/$cf /etc/$cf
144  else
145    stripcr /mnt/tmp/$cf /etc/$cf
146echo "Stripped $cf"
147  fi
148done
149
150# I want real nice names.
151mv /etc/network.ini /etc/network.init
152chmod 755 /etc/network.init
153mv /etc/firewall.ini /etc/firewall.init
154chmod 755 /etc/firewall.init
155stripcr /mnt/tmp/floppyfw.msg /etc/issue 644
156
157# I also want to add the source device and file system so that I can remount.
158echo "SOURCE_DEV=$SOURCE_DEV" >> /etc/config
159echo "SOURCE_FS=$SOURCE_FS" >> /etc/config
160
161#
162# Before I source it I want to fix the password. It's in the config but
163# I do not want it in clear text and available to the running scripts.
164#
165# So, login.ini will make the /etc/config, without PASSWORD
166#
167# The login.ini
168#
169/etc/login.ini
170
171. /etc/config
172
173
174#
175# Packages (contributed by: t'Sade)
176#
177echo -n "Looking for extra packages: "
178for i in /mnt/tmp/packages/*.bz2; do
179        if test -f $i
180        then
181                echo "  $i "
182                tar -xjf $i
183        fi
184done
185
186for i in /mnt/tmp/packages/*.ffw; do
187        if test -f $i
188        then
189                echo "  $i "
190                lzmacat $i | tar -x
191        fi
192done
193echo
194
195#
196# Since we have to assume that the live filesystem is on a read-only
197# file system we'd do this (and probably "overwrite") after modules
198# and packages are unpacked.
199#
200if [ -d /mnt/tmp/live ]
201 then
202  echo "We got ourselves a (part of a) live filesystem."
203  if [ -d /mnt/tmp/live/modules ]
204   then
205    LIVE_SYSTEM="y"
206#    ln -s /mnt/tmp/modules /lib/modules
207
208    for i in /mnt/tmp/live/modules/*; do
209      if test -d $i
210       then
211        echo $i
212        F=`basename $i`
213        echo "BASE:$F"
214        # We don't need the original directory when we are putting a symbolic
215        # link there.
216        rm -rf /lib/modules/$F
217        ln -s $i /lib/modules/$F
218    fi
219  done
220  fi # /if [ -d /mnt/tmp/modules ]
221fi # /if [ -d /mnt/tmp/live ]
222
223echo
224
225if [ ${SECOND_DEVICE} != 'n' ];
226 then
227  mkdir /mnt/second
228  mount -t $SECOND_DEVICE_FS ${SECOND_DEVICE} /mnt/second
229  echo "Unpacking packages from secondary device \"${SECOND_DEVICE}\" "
230  for i in /mnt/second/packages/*.bz2; do
231    if test -f $i
232    then
233       echo -n "$i "
234        tar -xjf $i
235    fi
236  done
237  for i in /mnt/second/packages/*.ffw; do
238        if test -f $i
239        then
240                echo "  $i "
241                lzmacat $i | tar -x
242        fi
243  done
244echo
245  umount /mnt/second
246  echo
247fi
248
249echo "Looking for pre- scripts..."
250
251for i in /mnt/tmp/packages/pre-*.ini; do
252        if test -f $i
253        then
254                PRE=${i#/mnt/tmp/packages/}
255                stripcr $i /etc/$PRE 755
256                fi
257done
258for i in /etc/pre-*.ini; do
259        if test -f $i
260        then
261                echo "Running $i"
262                chmod 755 $i
263                $i
264        fi
265done
266echo "...scripts done." 
267
268# Need to create a modules.conf file for the options:
269echo "Creating modules.conf."
270#grep -v "[#|^\s]" /etc/modules.lst | grep "\w \w" > /tmp/modc.tmp
271#while read cline
272# do
273#  echo "options $cline" >> /etc/modules.conf
274# done < /tmp/modc.tmp
275#rm /tmp/modc.tmp
276     
277# This one didn't work :=(
278# grep -v "[#|^\s]" modules.lst | grep "\w \w" | sed -r -e 's/(.*)/options $1/
279
280# Grygory Farkas suggested this one:
281grep "\w \w" /etc/modules.lst | sed '/^#/d;s/^/options /' >> /etc/modules.conf
282
283echo "Inserting modules."
284while read myline
285 do
286  case o${myline} in
287   o\#*|o)
288    ;;
289   oinsmod*)
290    ${myline} >> $DEBUG_LOG 2>&1
291    ;;
292   o*)
293    # insmod ${myline} >> $DEBUG_LOG 2>&1
294    modprobe ${myline} >> $DEBUG_LOG 2>&1
295    if [ $? -eq  0 ]
296      then
297       echo -n "${myline}  "
298    fi
299    ;;
300  esac
301 done < /etc/modules.lst
302
303#
304# This used to be where the time zone file was copied.
305# Now, it's only a variable and a file.
306#
307if [ $TIMEZONE ] 
308 then
309  echo $TIMEZONE > /etc/TZ
310fi
311
312
313if [ -f /mnt/tmp/packages/keymap ]
314 then
315  echo "Loading keymap."
316  cp  /mnt/tmp/packages/keymap /etc/default.kmap
317  loadkmap < /etc/default.kmap
318fi
319
320echo
321echo "Initializing network: "
322/etc/network.init
323echo
324
325if [ ${USE_SYSLOG} = 'y' ];
326then
327       echo "Starting klogd and syslogd"
328       echo -n "klogd "
329       /sbin/klogd
330       echo "syslogd"
331       /sbin/syslogd ${SYSLOG_FLAGS}
332fi
333
334if [ ${FAKEIDENT} ];
335then
336  echo "running fakeidentd with ${FAKEIDENT} as the ident answer."
337  echo "(You are taking a risk by running this application.)"
338  fakeidentd ${FAKEIDENT}
339fi
340
341echo "Looking for post- scripts..."
342for i in /mnt/tmp/packages/post-*.ini; do
343        if test -f $i
344        then
345                POST=${i#/mnt/tmp/packages/}
346                stripcr $i /etc/$POST 755
347        fi
348done
349for i in /etc/post-*.ini; do
350        if test -f $i
351        then
352                echo "Running $i"
353                chmod 755 $i
354                $i
355        fi
356done
357echo "...scripts done." 
358
359#
360# Ok, this is not used, will not be documented and is commented out.
361# It's just too darn cute not to have here:
362# Ken Yap posted this on the floppyfw.general news group.
363#
364# FILE=/zelow/floppyfw/index.html
365# SERVER=www.zelow.no
366# DEST=test.html
367# echo -e "GET $FILE HTTP/1.0\n" | nc $SERVER 80 | sed '1,/^.$/d' > $DEST
368# And yes, you have to unpack the packages and run scripts.
369
370if [ $LIVE_SYSTEM ]
371 then
372  echo "Not unmounting the main media, we have a live file system on it."
373 else
374  umount /mnt/tmp
375  rm -r /mnt/tmp
376fi
377
378#
379# To be possible again in some future..:
380#
381# if [ ${OPEN_SHELL} = 'y' ];
382# then
383# fi
Note: See TracBrowser for help on using the browser.