#!/bin/busybox sh #---------------------------------------------------------------------------- # /etc/rc - boot script # # Creation: 29.03.2000 fm # Last Update: $Id$ # # Copyright (c) 2000-2002 Frank Meyer #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # stop-function to be used instead of 'exit' to keep error-messages readable #---------------------------------------------------------------------------- stop() { log_error "$1" while true; do /bin/sh done } #---------------------------------------------------------------------------- # read_config - load configuration from rc.cfg #---------------------------------------------------------------------------- read_config() { file=$1 [ -f $file ] || stop "missing config file ('$file')" cp $file /tmp/rc.$$ dtou -s /tmp/rc.$$ . /tmp/rc.$$ # get fli4l config rm /tmp/rc.$$ # clean up } #---------------------------------------------------------------------------- # exec_scripts : executes all scripts in directory #---------------------------------------------------------------------------- rename_ln() { mv /bin/ln /bin/ln.real cat <<-EOF > /bin/ln #! /bin/sh param="\$*" . /etc/boot.d/base-helper case \$1 in -s) shift ;; esac case \$2 in /*) path=\$2 ;; *) path=\`pwd\`/\$2 ;; esac case \$path in /opt/*) SCRIPT=\$script log_error "trying to create link in wrong location (ln \$param), please fix this (maybe by removing /opt prefix)." ;; esac busybox ln \$param EOF chmod +x /bin/ln } exec_scripts() { dir=$1 if [ ! -d $dir ] then log_error "exec_scripts called for non existing directory $dir" return fi rename_ln for script in $dir/rc[0-9][0-9][0-9]*.* do if [ -f $script ] then echo "script=$script" > /var/run/rc.script . $script fi done rm -f /var/run/rc.script if [ -f /bin/ln.real ]; then mv /bin/ln.real /bin/ln fi } #----------------------------------------------------------------------------- # extract_opt # - fetch opt.tar from specified location and extract it #----------------------------------------------------------------------------- extract_opt() { file=$1 method=$2 message="$3" target_dir=$4 # wenn method to uncompress is diffrent from 'cat' set method based # on COMP_TYPE_OPT case $method in cat) ;; *) case $COMP_TYPE_OPT in lzma) method="unlzma -c" ;; esac ;; esac case x$target_dir in x) target_dir=/ ;; esac case x$file in x- | x ) # file comes from stdin file= ;; *) [ -f $file ] || stop "extract_opt: missing file $file" ;; esac log_info "extracting files from opt archive" cd $target_dir if ! $method $file 2>>/tmp/tar-error-$$ | pipe_progress | tar -xf - 2>>/tmp/tar-error-$$ then log_error "tar failed:" cat /tmp/tar-error-$$ stop "$message" fi rm -f /tmp/tar-error-$$ } do_mknod() { while read name typ major minor do mknod $tmp/dev/$name $typ $major $minor done } do_mkdev() { while read name typ major minor first last base do makedevs $name $typ $major $minor $first $last $base done } static_devices() { # create devices missed by mdev (see #16828 for # complete list) cd /dev echo "Creating static device nodes..." cat <> /etc/fstab ;; esac fi busybox --install mount -t sysfs sysfs /sys mount -t devpts devpts /dev/pts if [ -f /etc/rc.cfg ]; then grep -q "^DEBUG_MDEV='yes'" /etc/rc.cfg && > /var/log/mdev.log fi echo > /dev/mdev.seq echo /sbin/mdev > /proc/sys/kernel/hotplug static_devices mdev -s kernel_version=`cat /proc/version | cut -d' ' -f 3` kernel_major=2.6 kernel_minor=`echo $kernel_version | sed -e "s/2.6.\([0-9]\+\)\(\.[0-9]\+\)\?.*/\1/"` echo $kernel_version > /etc/kernel-version echo $kernel_major > /etc/kernel-major echo $kernel_minor > /etc/kernel-minor ln -sf /proc/mounts /etc/mtab # add alias names to modprobe.conf [ -f /lib/modules/$kernel_version/modules.alias ] && cat /lib/modules/$kernel_version/modules.alias >> /etc/modprobe.conf #---------------------------------------------------------------------------- # relocate core dumps #---------------------------------------------------------------------------- if [ -f /proc/sys/kernel/core_pattern ]; then mkdir /var/log/dumps chmod 1777 /var/log/dumps echo '/var/log/dumps/core.%e' > /proc/sys/kernel/core_pattern fi #---------------------------------------------------------------------------- # create necessary links #---------------------------------------------------------------------------- update_lib_links() { [ -d $1 ] || return cd $1 for i in lib*.so*; do [ -e "$i" ] || break name=$i case $name in libuClibc++-0.2.2.so) set `echo $i | sed -e 's/-0.2.2//;s/\(.*\)\.so\(\.\([0-9]\).*\)\?/\1 \3/'` ;; *) set `echo $i | sed -e 's/-0.9.30.3//;s/\(.*\)\.so\(\.\([0-9]\+\).*\)\?/\1 \3/'` ;; esac lib=$1.so major=.0 [ "$2" ] && major=.$2 [ -e $lib ] || ln -s $name $lib [ -e $lib$major ] || ln -s $name $lib$major done cd / } #----------------------------------------------------------------------------- # handle libraries present in root archive #----------------------------------------------------------------------------- update_lib_links /lib update_lib_links /usr/lib #----------------------------------------------------------------------------- # setup boot logging and startup debugging #----------------------------------------------------------------------------- [ -x /sbin/bootlogd ] && /sbin/bootlogd -c -l /var/tmp/boot.log case "$fli4ldebug" in yes) > /var/run/debugging set -x stack_0='yes' esac #---------------------------------------------------------------------------- # initialize some variables #---------------------------------------------------------------------------- unzip_method="bunzip2 -c" script=rc export script booting=yes # remove stale /files link rm -f /files #---------------------------------------------------------------------------- # mount devices, e.g. /proc #---------------------------------------------------------------------------- cd / # be in root directory mount -av # mount /proc mount #---------------------------------------------------------------------------- # check for recover-version activation by kernel APPEND #---------------------------------------------------------------------------- rc_name=rc.cfg opt_name=opt.img case "$fli4l_mode" in recover) rcfile=rc2.cfg opt_archive=opt2.img fli4l_ramdisk=yes log_info "booting recovery version ..." cy ;; test) rcfile=rc-test.cfg opt_archive=opt-test.img fli4l_ramdisk=yes log_info "booting test version ..." cy ;; *) rcfile=$rc_name opt_archive=$opt_name fli4l_ramdisk= ;; esac #---------------------------------------------------------------------------- # ?- == depends on boot method, !- == mandatory # ?- load drivers # ?- mount boot medium # !- read rc.cfg # ?- extract/mount opt files #---------------------------------------------------------------------------- . /etc/boot.d/base-helper # load speaker module for kernel 2.6 do_modprobe_if_exists kernel/drivers/input/misc pcspkr ( # use separate environment for boot scripts if [ -f /etc/rc.cfg ]; then read_config /etc/rc.cfg else log_error "Missing initial boot configuration file /etc/rc.cfg" fi log_info "running boot scripts" exec_scripts /etc/boot.d log_info "finished boot scripts" echo -e "boot_dev=$boot_dev\nboot_fs=$boot_fs\nhd_data=$hd_data" > /var/run/boot.cfg cat /var/run/boot.cfg ) #----------------------------------------------------------------------------- # handle libraries added by opt archive #----------------------------------------------------------------------------- update_lib_links /lib update_lib_links /usr/lib #----------------------------------------------------------------------------- # read rc.cfg #----------------------------------------------------------------------------- if [ -f /var/run/$rcfile ]; then read_config /var/run/$rcfile else read_config /boot/$rcfile fi . /var/run/boot.cfg grep -q /boot /proc/mounts && umount /boot #----------------------------------------------------------------------------- # exec rc scripts #----------------------------------------------------------------------------- exec_scripts /etc/rc.d # prevent dying deamons sleep 10