#!/bin/sh # $Id: rc.initrd,v 1.16 2005/10/15 23:58:12 thomasez Exp $ # # floppyfw initfile # . /etc/functions.inc echo "Init started OK." PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" TERM=linux export PATH TERM umask 022 COMMAND_LINE=`cat /proc/cmdline` ROOTDEV=`echo $COMMAND_LINE |sed -e 's/$/ /' -e 's/.*source=\([^ ]*\) .*/\1/' -e 's/,/ /g' -e 's:/dev/nfs:/dev/fd0:'` set -- $ROOTDEV # Backward compatibility with a single device argument if [ $# -eq 1 ] then set -- $1 vfat fi while [ "$1" -a "$2" ] do SOURCE_DEV=$1 SOURCE_FS=$2 echo "Attempting to mount $SOURCE_DEV ($SOURCE_FS)" load_fsmod $SOURCE_DEV $SOURCE_FS if mount -t $SOURCE_FS $SOURCE_DEV /mnt/tmp then echo "Mounted $SOURCE_DEV on /mnt/tmp" break else echo "Mount failed" fi shift; shift done # # Getting rid of old mounts. # echo "Unmounting old root" umount /initrd freeramdisk /dev/rd/0 cd / echo echo "Extracting filesystem: " [ -f /mnt/tmp/add.bz2 ] && tar -xjf /mnt/tmp/add.bz2 [ -f /mnt/tmp/add.ffw ] && lzmacat /mnt/tmp/add.ffw | tar -x echo -n "Extracting module packages: " for i in /mnt/tmp/modules/*.bz2; do if test -f $i then echo " $i " tar -xjf $i fi done echo for i in /mnt/tmp/modules/*.ffw; do if test -f $i then echo " $i " lzmacat $i | tar -x fi done echo #Modules. [ -f /mnt/tmp/modules/*.o ] && cp /mnt/tmp/modules/*.o /lib/modules 2> /dev/null # cp /mnt/tmp/modules/*.o /lib/modules 2> /dev/null # # If the ROOT device is a read-only device we might have a second # device where the config flies reside: # (The configdevice option in the append line.) # # The reason for having this as late as this is that we may have some modules # available that we could use (like USB-storage) # case $COMMAND_LINE in *configdevice* ) CONFDEV=`echo $COMMAND_LINE | sed -e 's/$/ /' -e 's/.*configdevice=\([^ ]*\) .*/\1/' -e 's/,/ /g' -e 's:/dev/nfs:/dev/fd0:'` echo $CONFDEV > /etc/configdevice echo "You have some of your configuration on a separate medium, using it." CONFDEV=`cat /etc/configdevice` mkdir /mnt/config set -- $CONFDEV # Backward compatibility with a single device argument if [ $# -eq 1 ] then set -- $1 vfat fi while [ "$1" -a "$2" ] do echo "Attempting to mount $1 ($2)" load_fsmod $1 $2 if mount -t $2 $1 /mnt/config then echo "Mounted $1 on /mnt/config" break else echo "Mount failed" rm -r /mnt/config fi shift; shift done esac # # We need to do this one file at a time (could be traversing a list but then # we'd have to not rename it on it's way. # (and I'm lazy and just testing if this works at all anyway) # # The best would be to trust the user and just copy all the files on the # device. # # echo "Her er vi" # set -x # set -e # exec >/tmp/${0##*/}.log CONFIG_FILES="config ethers hosts modules.lst firewall.ini network.ini" for cf in $CONFIG_FILES do if [ -f /mnt/config/$cf ] then stripcr /mnt/config/$cf /etc/$cf else stripcr /mnt/tmp/$cf /etc/$cf echo "Stripped $cf" fi done # I want real nice names. mv /etc/network.ini /etc/network.init chmod 755 /etc/network.init mv /etc/firewall.ini /etc/firewall.init chmod 755 /etc/firewall.init stripcr /mnt/tmp/floppyfw.msg /etc/issue 644 # I also want to add the source device and file system so that I can remount. echo "SOURCE_DEV=$SOURCE_DEV" >> /etc/config echo "SOURCE_FS=$SOURCE_FS" >> /etc/config # # Before I source it I want to fix the password. It's in the config but # I do not want it in clear text and available to the running scripts. # # So, login.ini will make the /etc/config, without PASSWORD # # The login.ini # /etc/login.ini . /etc/config # # Packages (contributed by: t'Sade) # echo -n "Looking for extra packages: " for i in /mnt/tmp/packages/*.bz2; do if test -f $i then echo " $i " tar -xjf $i fi done for i in /mnt/tmp/packages/*.ffw; do if test -f $i then echo " $i " lzmacat $i | tar -x fi done echo # # Since we have to assume that the live filesystem is on a read-only # file system we'd do this (and probably "overwrite") after modules # and packages are unpacked. # if [ -d /mnt/tmp/live ] then echo "We got ourselves a (part of a) live filesystem." if [ -d /mnt/tmp/live/modules ] then LIVE_SYSTEM="y" # ln -s /mnt/tmp/modules /lib/modules for i in /mnt/tmp/live/modules/*; do if test -d $i then echo $i F=`basename $i` echo "BASE:$F" # We don't need the original directory when we are putting a symbolic # link there. rm -rf /lib/modules/$F ln -s $i /lib/modules/$F fi done fi # /if [ -d /mnt/tmp/modules ] fi # /if [ -d /mnt/tmp/live ] echo if [ ${SECOND_DEVICE} != 'n' ]; then mkdir /mnt/second mount -t $SECOND_DEVICE_FS ${SECOND_DEVICE} /mnt/second echo "Unpacking packages from secondary device \"${SECOND_DEVICE}\" " for i in /mnt/second/packages/*.bz2; do if test -f $i then echo -n "$i " tar -xjf $i fi done for i in /mnt/second/packages/*.ffw; do if test -f $i then echo " $i " lzmacat $i | tar -x fi done echo umount /mnt/second echo fi echo "Looking for pre- scripts..." for i in /mnt/tmp/packages/pre-*.ini; do if test -f $i then PRE=${i#/mnt/tmp/packages/} stripcr $i /etc/$PRE 755 fi done for i in /etc/pre-*.ini; do if test -f $i then echo "Running $i" chmod 755 $i $i fi done echo "...scripts done." # Need to create a modules.conf file for the options: echo "Creating modules.conf." #grep -v "[#|^\s]" /etc/modules.lst | grep "\w \w" > /tmp/modc.tmp #while read cline # do # echo "options $cline" >> /etc/modules.conf # done < /tmp/modc.tmp #rm /tmp/modc.tmp # This one didn't work :=( # grep -v "[#|^\s]" modules.lst | grep "\w \w" | sed -r -e 's/(.*)/options $1/ # Grygory Farkas suggested this one: grep "\w \w" /etc/modules.lst | sed '/^#/d;s/^/options /' >> /etc/modules.conf echo "Inserting modules." while read myline do case o${myline} in o\#*|o) ;; oinsmod*) ${myline} >> $DEBUG_LOG 2>&1 ;; o*) # insmod ${myline} >> $DEBUG_LOG 2>&1 modprobe ${myline} >> $DEBUG_LOG 2>&1 if [ $? -eq 0 ] then echo -n "${myline} " fi ;; esac done < /etc/modules.lst # # This used to be where the time zone file was copied. # Now, it's only a variable and a file. # if [ $TIMEZONE ] then echo $TIMEZONE > /etc/TZ fi if [ -f /mnt/tmp/packages/keymap ] then echo "Loading keymap." cp /mnt/tmp/packages/keymap /etc/default.kmap loadkmap < /etc/default.kmap fi echo echo "Initializing network: " /etc/network.init echo if [ ${USE_SYSLOG} = 'y' ]; then echo "Starting klogd and syslogd" echo -n "klogd " /sbin/klogd echo "syslogd" /sbin/syslogd ${SYSLOG_FLAGS} fi if [ ${FAKEIDENT} ]; then echo "running fakeidentd with ${FAKEIDENT} as the ident answer." echo "(You are taking a risk by running this application.)" fakeidentd ${FAKEIDENT} fi echo "Looking for post- scripts..." for i in /mnt/tmp/packages/post-*.ini; do if test -f $i then POST=${i#/mnt/tmp/packages/} stripcr $i /etc/$POST 755 fi done for i in /etc/post-*.ini; do if test -f $i then echo "Running $i" chmod 755 $i $i fi done echo "...scripts done." # # Ok, this is not used, will not be documented and is commented out. # It's just too darn cute not to have here: # Ken Yap posted this on the floppyfw.general news group. # # FILE=/zelow/floppyfw/index.html # SERVER=www.zelow.no # DEST=test.html # echo -e "GET $FILE HTTP/1.0\n" | nc $SERVER 80 | sed '1,/^.$/d' > $DEST # And yes, you have to unpack the packages and run scripts. if [ $LIVE_SYSTEM ] then echo "Not unmounting the main media, we have a live file system on it." else umount /mnt/tmp rm -r /mnt/tmp fi # # To be possible again in some future..: # # if [ ${OPEN_SHELL} = 'y' ]; # then # fi