#!/bin/sh REQUIRED_MB=250 # minimum megabytes available to offer install MENUFIFO=/menu.fifo DEBUG=y SAMIZDAT_LOG_DIR=/run/initramfs/samizdat/log debug_log() { if [ -n "$DEBUG" ]; then if [ -n "$1" ]; then DEBUG_LOG=$SAMIZDAT_LOG_DIR/"$1".$$.log else DEBUG_LOG=$SAMIZDAT_LOG_DIR/$(basename $0).$$.log fi mkdir -p $SAMIZDAT_LOG_DIR exec >>$DEBUG_LOG 2>&1 set -x fi } addmenu() { cat <>$MENUFIFO # mind the tabs setItem "$1" "dummy" "$2" "$3" END } menutitle() { printf 'setTitle "%s"\n' "$1" >>$MENUFIFO printf 'setWelcomeText "%s"\n' "$2" >>$MENUFIFO } force_grok_block() { udevadm trigger --subsystem-match=block --action=add } samizdat_install_udev_rules() { local target=/etc/udev/rules.d/z00_blockdev_mountroot.rules [ -e "$target" ] && return mkdir -p /etc/udev/rules.d echo 'ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/grok-block $env{DEVNAME}"' \ > "$target" # 'udevadm trigger --action=add' does not work here; need to restard udevd # first. not sure why samizdat_restart_udev udevadm trigger -s block --action add } bootmenu() { local do_trigger="$1" no_panic="$2" killall dynmenu || true clear >/dev/tty7 || true if [ "$do_trigger" ] then echo -n 'Attempting to restart menu after failed boot...' >/dev/tty7 chvt 7 && sleep 1 || true fi if TERM=linux OpenVT -f -c 7 -s -- dynmenu "$MENUFIFO" then menutitle 'Samizdat\n\nAs the Internet develops there are\ntransitions in the management arrangements.\nThe time has come to take\na small step in one of those transitions.' 'Choose an installation target.' # menutitle 'Samizdat\nfreedom from surveillance\nno trusted authorities' 'Choose an installation target.' addmenu "ramdisk" "[ Boot to RAM without installing anything ]" "menu-select boot-ram" addmenu "poweroff" "[ Shut down the system immediately ]" "poweroff -f" fi if [ $? != 0 -a ! "$no_panic" ] then panic "error loading boot menu! the system won't be usable :(" fi if [ "$do_trigger" ]; then force_grok_block fi } netbooting() { [ "$nbdroot" ] } xtrace() { case "$-" in *x*) "$@" ;; *) set -x; "$@"; set +x ;; esac } sleepcmd() { local t=$1 shift echo "about to run '$*' (in $t)" sleep $t "$@" } sleep_forever_verbose() { sleep 4294967295 & local sleep=$! warn "sleeping until you kill $sleep..." wait $sleep } warn() { [ -z "$warnings" ] || echo "$@" >&2; } panic() { set +x exec /dev/tty1 2>&1 reset echo "[p$$] initramfs /init: fatal error: $@" echo "[p$$] will now exec emergency shell" export PS1="[p$$ \\w]# " chvt 1 exec /bin/sh -i } bootwait() { mkdir -p /bootwait local i=$#; while [ $i -gt 0 ]; do i=$((i-1)) local f="$1"; shift; set -- "$@" "/bootwait/$f" done wait_for_files "$@" } bootdone() { mkdir -p /bootwait local i=$#; while [ $i -gt 0 ]; do i=$((i-1)) local f="$1"; shift; set -- "$@" "/bootwait/$f" done touch "$@" } my_openvt() { /bin/openvt -c "$@" } xcp() { if [ -f "$1" -a ! -f "$2" ]; then cp "$1" "$2"; fi; }