From 153d299a41b9be4e15dab1ca29bb93a74bd2445d Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Fri, 29 Apr 2016 14:36:26 -0400 Subject: fix paths (in progress) --- src/initrd/common.sh | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/initrd/common.sh (limited to 'src/initrd/common.sh') diff --git a/src/initrd/common.sh b/src/initrd/common.sh new file mode 100644 index 0000000..4aa8528 --- /dev/null +++ b/src/initrd/common.sh @@ -0,0 +1,143 @@ +#!/bin/sh +REQUIRED_MB=250 # minimum megabytes available to offer install +MENUFIFO=/menu.fifo +DEBUG=y +LOGBASE=/var/log + +debug_log() +{ + if [ -n "$DEBUG" ]; then + if [ -n "$1" ]; then + DEBUG_LOG=$LOGBASE/"$1".$$.log + else + DEBUG_LOG=$LOGBASE/$(basename $0).$$.log + fi + mkdir -p $LOGBASE + 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 +} +bootmenu() +{ + local do_trigger="$1" no_panic="$2" + OpenVT -f -c 7 -- dynmenu "$MENUFIFO" && + chvt 7 && + 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" + if [ $? != 0 -a ! "$no_panic" ]; then + panic "error loading boot menu! the system won't be usable :(" + fi + if [ "$do_trigger" ]; then + udevadm trigger --subsystem-match=block --action=add + fi +} +find_squashfs_root() +{ + # TODO: "make" puts the correct location in $iso_squashfs_dir. Get + # information into this function! + + bootwait samizdat-cdrom + for dir in /cdrom/live /cdrom/liveos /cdrom/aptosid /cdrom/* + do + [ -d "$dir" ] || continue; + if [ -f "$dir"/filesystem.module ]; then + while read fs; do + [ -f "$dir"/"$fs" ] && echo "$dir" "$fs" + done < "$dir"/filesystem.module + return + fi + done + for fs in /cdrom/live/filesystem.squashfs /cdrom/live/grml-small.squashfs /cdrom/liveos/squashfs.img /cdrom/aptosid/aptosid.* /cdrom/*/*.squashfs + do + if [ -f "$fs" ]; then + echo "${fs%/*}" "${fs##*/}" + break + fi + done +} +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 "$@" +} + +# This runs before way before NTP and on a LiveCD we have no +# reason to trust the system clock. +gpg2_nobatch() { GPG_TTY=$(tty) command gpg2 --ignore-time-conflict --ignore-valid-from "$@"; } +gpg2() { gpg2_nobatch --batch "$@"; } + +xcp() { if [ -f "$1" -a ! -f "$2" ]; then cp "$1" "$2"; fi; } + +mountsquashes() +{ + local name dirname basename + while read dirname basename && [ -d "$dirname" -a -f "$dirname/$basename" ]; do + name=${basename%.squashfs} + mkdir -p "/squashes/$name" || return 1 + xcp "$dirname"/filesystem.module /squashes/filesystem.module || return 1 + mountpoint -q "/squashes/$name" || + mount -o ro,loop "$dirname/$basename" "/squashes/$name" || return 1 + done +} + -- cgit v1.2.3