aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
Diffstat (limited to 'init')
-rwxr-xr-xinit103
1 files changed, 96 insertions, 7 deletions
diff --git a/init b/init
index a725372..80bab77 100755
--- a/init
+++ b/init
@@ -11,9 +11,23 @@ set -o errtrace # Trap in functions.
# Note: diagnostics goes to stdout.
#
function info () { echo "$*"; }
-function error () { info "$*"; exit 1; }
+function error ()
+{
+ if [ "$#" -gt 0 ]; then
+ info "$*";
+ fi
-export PATH=/sbin:/usr/sbin:/bin:/usr/bin
+ # The setsid voodoo (take from Debian init's panic()) is to enable job
+ # control.
+ #
+ info "type Ctrl-D to exit shell and reboot"
+ setsid /bin/bash -c "exec /bin/bash -i <>/dev/tty1 1>&0 2>&1"
+ reboot
+}
+
+# Some pre-systemd utilities (like reboot) come from klibc-utils.
+#
+export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/klibc/bin/
# One would expect rootflags=size=1g to work but it doesn't (perhaps init
# is expected to interpret it)?
@@ -100,6 +114,7 @@ eth_all="$(cd /sys/class/net && ls -d en?*)"
if [ -z "$eth_all" ]; then
info "no ethernet interfaces found among:"
ip link show
+ error
fi
eth=
@@ -152,13 +167,15 @@ for s in 1 2 4 8; do
done
if [ -z "$eth_up" ]; then
- error "no ethernet interfaces with carrier among:"
+ info "no ethernet interfaces with carrier among:"
ip link show
+ error
fi
if [ -z "$eth" ]; then
- error "no ethernet interfaces with DHCP among:"
+ info "no ethernet interfaces with DHCP among:"
ip link show
+ error
fi
mac="$(cat "/sys/class/net/$eth/address")"
@@ -182,7 +199,7 @@ info "hostname $hname"
# based on what we have discovered and then let the systemd networking bringup
# to configure everything (at which point we will hopefully reuse the lease).
#
-dhclient -q -x
+dhclient -x 2>/dev/null
# @@ Need to be make configurable.
#
@@ -236,15 +253,85 @@ sed -r -i \
-e "s%^(relayhost).*%\1 = $smtp_relay%" \
/etc/postfix/main.cf
-# Make admin alias for buildos.admin_email, redirect root to admin.
+# Make admin alias for buildos.admin_email, alias root as admin.
#
cat <<EOF >>/etc/aliases
admin: $admin_email
root: admin
EOF
-
newaliases
+# Figure out disk configuration and generate the corresponding /etc/fstab.
+#
+fstab=/etc/fstab
+#fstab=/dev/stdout
+
+echo -n '' >$fstab
+
+l=
+machines=
+while read l || [ -n "$l" ]; do
+ d="$(sed -re 's/.*NAME=\"([^\"]+)\".*/\1/' <<<"$l")"
+ t="$(sed -re 's/.*FSTYPE=\"([^\"]*)\".*/\1/' <<<"$l")"
+ l="$(sed -re 's/.*LABEL=\"([^\"]*)\".*/\1/' <<<"$l")"
+
+ # Strip the buildos. prefix from the label. If the result is empty then
+ # this disk/patition hasn't been labeled for use by buildos.
+ #
+ l="$(sed -n -re 's/^buildos\.([^ ]+)$/\1/p' <<<"$l")"
+
+ if [ -z "$l" ]; then
+ continue
+ fi
+
+ # Handle buildos.machines and buildos.machines.* mounts.
+ #
+ if [[ "$l" == "machines" ]] || [[ "$l" =~ "machines.".+ ]]; then
+
+ if [ "$t" != "btrfs" ]; then
+ error "non-btrfs filesystem on $d labeled with buildos.machines"
+ fi
+
+ if [ "$l" = "machines" ]; then
+ # Single mount.
+ #
+ if [ -n "$machines" ]; then
+ error "multiple disks labeled with buildos.machines/machines.*"
+ fi
+
+ m=/build/machines
+ machines="single"
+ else
+ # Multiple mounts.
+ #
+ if [ "$machines" = "single" ]; then
+ error "multiple disks labeled with buildos.machines/machines.*"
+ fi
+
+ n="$(sed -n -re 's/^machines\.([^ ]+)$/\1/p' <<<"$l")"
+ m="/build/machines/$n"
+ machines="multiple"
+ fi
+
+ info "mounting $d (buildos.$l) on $m"
+
+ echo mkdir -p "$m"
+ o="defaults,noatime,nodiratime,user_subvol_rm_allowed"
+ echo "$d $m btrfs $o 0 0" >>$fstab
+ fi
+done < <(lsblk --pairs --paths --output NAME,FSTYPE,LABEL)
+#done <<EOF
+#NAME="/dev/sda" FSTYPE="btrfs" LABEL="buildos.machines.vol1"
+#NAME="/dev/sdb" FSTYPE="btrfs" LABEL="buildos.machines.vol2"
+#EOF
+
+if [ -z "$machines" ]; then
+ info "no disks labaled with buildos.machines* among:"
+ lsblk --paths --output NAME,TYPE,FSTYPE,SIZE,LABEL,UUID
+ info "consider formatting and/or labelling a suitable disk"
+ error
+fi
+
/bin/bash
# Hand off to systemd. But first arrange to keep console output (which
@@ -256,6 +343,8 @@ cat <<EOF >/etc/systemd/system/getty@tty1.service.d/noclear.conf
TTYVTDisallocate=no
EOF
+export PATH=/sbin:/usr/sbin:/bin:/usr/bin
+
exec /lib/systemd/systemd \
--show-status=1 \
--machine-id="00000000000000000000$mid" \