root/floppyfw/files/rc.initrd

Revision 3, 7.6 KB (checked in by root, 6 years ago)

First compile with subversion version.

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