diff --git a/update-initrd/update-initrd b/update-initrd/update-initrd index 83db81a2..2e516e3e 100755 --- a/update-initrd/update-initrd +++ b/update-initrd/update-initrd @@ -1,5 +1,5 @@ -#!/bin/sh -e -# Copyright (c) 2015 Jonas 'Sortie' Termansen. +#!/bin/sh +# Copyright (c) 2015, 2016 Jonas 'Sortie' Termansen. # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -16,27 +16,7 @@ # update-initrd # Generate a mkinitrd that locates and chain boots the real root filesystem. -show_version() { - cat << EOF -$0 (Sortix) -EOF - exit 0 -} - - -show_help() { - cat << EOF -Usage: $0 [OPTION]... - -Generate a mkinitrd that locates and chain boots the real root filesystem. - -Configuration: - --help display this help and exit - --version display version information and exit - --sysroot=DIR operate on this root filesystem [/] -EOF - exit 0 -} +set -e sysroot= @@ -66,16 +46,22 @@ for argument do esac done -if [ ! -e "$sysroot/etc/fstab" ]; then - echo "$0: $sysroot/etc/fstab: Need a filesystem table to make an initrd" >&2 - exit 1 -fi sysmerge=false exec_prefix="$sysroot" if [ -d "$sysroot/sysmerge" ]; then + # If an upgrade is pending, invoke the update-initrd of the new system, if + # we're not already it. + if [ "$(realpath -- "$(which -- "$0")")" != \ + "$(realpath -- "$sysroot/sysmerge/sbin/update-initrd")" ]; then + exec "$sysroot/sysmerge/sbin/update-initrd" "$@" + fi sysmerge=true exec_prefix="$sysroot/sysmerge" fi +if [ ! -e "$sysroot/etc/fstab" ]; then + echo "$0: $sysroot/etc/fstab: Need a filesystem table to make an initrd" >&2 + exit 1 +fi tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT HUP INT QUIT TERM mkdir "$tmp/bin" diff --git a/update-initrd/update-initrd.8 b/update-initrd/update-initrd.8 index b62bb16e..f1c5e34e 100644 --- a/update-initrd/update-initrd.8 +++ b/update-initrd/update-initrd.8 @@ -30,6 +30,18 @@ If any of those files are updated then the should be regenerated by invoking .Nm . .Pp +.Nm +is aware of +.Xr sysmerge 8 +pending upgrades and will instead invoke the new +.Nm +in +.Pa /sysmerge +if an upgrade is pending. +.Nm +is written as a script so the initrd of the new system can produced even +across incompatible ABI changes. +.Pp The options are as follows: .Bl -tag -width "12345678" .It Fl \-sysroot Ns "=" Ns Ar sysroot @@ -58,4 +70,5 @@ will exit 0 on success and non-zero otherwise. .Xr init 8 , .Xr initrdfs 8 , .Xr mkinitrd 8 , +.Xr sysmerge 8 , .Xr update-grub 8