#!/bin/sh # Paranoia. case "$ZSH_VERSION" in ?*) alias -g '${1+"$@"}'='"$@"';; esac s_=; try_=; x_= unset s_ try_ x_ # Do something, and spawn an interactive shell if it fails. try_() { echo "$@" "$@" s_="$?" case "$s_" in 0) return 0;; esac echo "This command: $* returned $s_. Please fix it. After you exit this shell, I'll continue booting, but I won't retry that command." while :; do s_="$s_" /bin/sh && return 0 done sync } SUPERVISE_ENV=/package/admin/svclean-conf/supervise-env init_step_0_() { try_ umask 022 # Load the global $PATH value. try_ eval 'read PATH < "$SUPERVISE_ENV"/PATH' try_ export PATH # We booted with a disk filesystem as root, but we're going to switch to # tmpfs as root. Mount the tmpfs filesystem. try_ fsmount temp # /fs has to be copied onto tmpfs, because it's the configuration of all # other filesystems. Everything else can be symlinked. try_ tar --one-file-system -cf fs/temp/mount/fs.tar fs # Unpack the copy and remove the tarball. try_ cd fs/temp/mount try_ tar xf fs.tar try_ rm -f fs.tar # Move the symlinks for top-level directories into place. try_ mv -f fs/temp/root/* . try_ rmdir fs/temp/root # Adjust the tmpfs copy of the filesystem configurations: tmpfs is going to # be the new root, and pkgs is going to be a non-root filesystem. try_ rmdir fs/temp/mount try_ ln -s /. fs/temp/mount try_ rm -f fs/std-root try_ ln -s temp fs/std-root try_ rm -f fs/pkgs/mount try_ mkdir fs/pkgs/mount # Set the current-version symlink for the kernel so we can find modules. try_ eval 'x_=`dirname "$BOOT_FILE"`' try_ eval 'x_=`dirname "$x_"`' try_ ln -s "$x_" /fs/temp/mount/tmp/linux # Shuffle filesystems, set UID/GID, set environment, and do the next step. exec \ pivotchroot . fs/pkgs/mount \ setuidgid root \ envdir "$SUPERVISE_ENV" \ env init_step_=1 \ "$0" ${1+"$@"} } init_step_1_() { try_ unset init_step_ fsck=${fsck-y} intervene=${intervene-n} # Check the disk filesystem that was the original root. [ "$fsck" = n ] || try_ fscheck pkgs try_ fsmount pkgs remount # Set up the console keymap. try_ eval 'loadkeys /etc/console.kmap > /dev/tty1' try_ setfont lat1-08 # Set up important /proc stuff early. try_ fsmount proc try_ eval 'echo 0 > /proc/sys/kernel/ctrl-alt-del' try_ eval 'echo 0 > /proc/sys/kernel/sysrq || :' try_ eval 'echo "$HOSTNAME" > /proc/sys/kernel/hostname' try_ eval 'cat /etc/domainname > /proc/sys/kernel/domainname' # Check and mount other filesystems. try_ fsmount ptys try_ fsmount sysf [ "$fsck" = n ] || try_ fscheck logs try_ fsmount logs [ "$fsck" = n ] || try_ fscheck home try_ fsmount home # Another way to measure uptime. try_ touch /var/lastboot # Set the kernel's log verbosity. try_ dmesg -n 1 # Adjust the date. hwclock doesn't grok TAI clocks. try_ hwclock --hctosys --utc case $TZ in right/*) try_ eval 'dt=`date "+%Y-%m-%d %H:%M:%S"`' try_ eval 't0=`TZ=America/New_York date -d "$dt" +%s`' try_ eval 't1=`TZ=right/America/New_York date -d "$dt" +%s`' try_ eval 'tdiff=`expr "$t1" - "$t0"`' try_ date -s "+$tdiff seconds";; *) :;; esac # Activate swap areas. for x_ in /package/host/code.dogmap.org/foreign/linux-data/swap-*; do try_ minswapon "$x_" done # Now that we have swap, disable memory overcommitment. try_ eval 'echo 2 > /proc/sys/vm/overcommit_memory' try_ eval 'echo 0 > /proc/sys/vm/overcommit_ratio' # Initialize the login records. try_ eval ': > /var/run/utmp' try_ touch /var/log/wtmp # Set up networking parameters. #ry_ eval 'echo 1 > /proc/sys/net/ipv4/ip_forward' try_ eval 'echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter' try_ eval 'echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter' try_ eval 'echo 1 > /proc/sys/net/ipv4/tcp_syncookies' try_ modprobe /dev/mouse # Set up sound. try_ modprobe /dev/mixer try_ aumix -v83 -w100 -p75 -c100 # Load and then save the entropy pool. try_ dd if=/package/host/code.dogmap.org/foreign/linux-data/entropy-pool \ of=/dev/urandom try_ dd if=/dev/urandom \ of=/package/host/code.dogmap.org/foreign/linux-data/entropy-pool \ bs=4096 count=1 # Set up the loopback network. try_ ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255 try_ route add -net 127.0.0.0 netmask 255.0.0.0 dev lo # Make sure services will come up. try_ rm -f /service/*/svclean/shutdown /service/*/log/svclean/shutdown # If there's something to be done before the system comes completely up, # this is the last chance. if [ "$intervene" = y ]; then echo 'Exiting this shell will resume booting.' /bin/sh fi # Make a copy of svscan so that if we delete the original (e.g., to # recompile) we can still remount that filesystem read-only. try_ rm -rf /tmp/svscan try_ cp -p /command/svscan /tmp/ (sleep 5 && rm -f /tmp/svscan) & exec < /dev/null \ env - SUPERVISE_ENV="$SUPERVISE_ENV" PATH="$PATH" \ svclean-svscan \ /tmp/svscan /service } init_step_"${init_step_-0}"_ ${1+"$@"}