summaryrefslogtreecommitdiffstats
path: root/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'hooks')
-rwxr-xr-xhooks/fsck110
-rwxr-xr-xhooks/keymap40
-rwxr-xr-xhooks/resume117
-rwxr-xr-xhooks/thermal71
4 files changed, 338 insertions, 0 deletions
diff --git a/hooks/fsck b/hooks/fsck
new file mode 100755
index 0000000..000ce4e
--- /dev/null
+++ b/hooks/fsck
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+PREREQ=""
+
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+# Find a specific fstab entry
+# $1=mountpoint
+# $2=fstype (optional)
+_read_fstab_entry () {
+ # Not found by default.
+ echo "MNT_FSNAME="
+ echo "MNT_DIR="
+ echo "MNT_TYPE="
+
+ for file in /etc/fstab /etc/fstab.d/*.fstab; do
+ if [ -f "$file" ]; then
+ # shellcheck disable=SC2034
+ while read -r MNT_FSNAME MNT_DIR MNT_TYPE MNT_OPTS MNT_FREQ MNT_PASS MNT_JUNK; do
+ case "$MNT_FSNAME" in
+ ""|\#*)
+ continue;
+ ;;
+ esac
+ if [ "$MNT_DIR" = "$1" ]; then
+ if [ -n "$2" ]; then
+ [ "$MNT_TYPE" = "$2" ] || continue;
+ fi
+ echo "MNT_FSNAME=$MNT_FSNAME"
+ echo "MNT_DIR=$MNT_DIR"
+ echo "MNT_TYPE=$MNT_TYPE"
+ echo "MNT_PASS=$MNT_PASS"
+ break 2
+ fi
+ MNT_DIR=""
+ done < "$file"
+ fi
+ done
+}
+
+# Find a specific fstab entry and print its type (if found, and pass != 0)
+# $1=mountpoint
+get_fsck_type_fstab () {
+ eval "$(_read_fstab_entry "$1")"
+
+ # Not found by default.
+ if [ "$1" = "$MNT_DIR" ]; then
+ # Ignore filesystem type for /, as it is not available and
+ # therefore never used at boot time
+ if [ "${MNT_DIR}" = "/" ] || [ "${MNT_TYPE}" = "auto" ]; then
+ MNT_FSNAME="$(resolve_device "${MNT_FSNAME}")"
+ fstype() { "/usr/lib/klibc/bin/fstype" "$@"; }
+ if ! get_fstype "${MNT_FSNAME}"; then
+ echo "W: Couldn't identify type of $2 file system for fsck hook" >&2
+ fi
+ unset -f fstype
+ else
+ echo "${MNT_TYPE}"
+ fi
+ fi
+}
+
+get_fsck_types() {
+ if [ "${FSTYPE:-auto}" = auto ]; then
+ get_fsck_type_fstab / root
+ get_fsck_type_fstab /usr usr
+ else
+ local IFS=,
+ local fstype
+ set -f
+ for fstype in $FSTYPE; do
+ echo "$fstype"
+ done
+ set +f
+ fi
+}
+
+case $1 in
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+if [ ! -x /sbin/fsck ]; then
+ exit 0
+fi
+
+. /usr/share/initramfs-tools/scripts/functions
+. /usr/share/initramfs-tools/hook-functions
+
+fsck_types="$(get_fsck_types | sort | uniq)"
+
+if [ -z "$fsck_types" ]; then
+ exit 0
+fi
+
+copy_exec /sbin/fsck
+copy_exec /sbin/logsave
+
+for type in $fsck_types; do
+ if prog="$(command -v "fsck.${type}")"; then
+ copy_exec "$prog"
+ else
+ echo "W: /sbin/fsck.${type} doesn't exist, can't install to initramfs" >&2
+ fi
+done
diff --git a/hooks/keymap b/hooks/keymap
new file mode 100755
index 0000000..64f8e6d
--- /dev/null
+++ b/hooks/keymap
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+PREREQ=""
+
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case $1 in
+# get pre-requisites
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+# Hook to load keymaps into the initramfs if requested by KEYMAP="y"
+if [ "$KEYMAP" != "y" ] && [ "$KEYMAP" != "Y" ]; then
+ exit 0
+fi
+
+if [ ! -x /bin/setupcon ]; then
+ echo "setupcon is missing. Please install the 'console-setup' package."
+ exit 0
+fi
+
+. /usr/share/initramfs-tools/hook-functions
+
+# Tell setupcon to copy/create the files it needs.
+setupcon --setup-dir "$DESTDIR"
+
+# Copy additional files that setupcon needs. We assume they are
+# executables.
+while read -r file; do
+ copy_exec "$file"
+done < "$DESTDIR/morefiles"
+rm -f "$DESTDIR/morefiles"
+
+exit 0
diff --git a/hooks/resume b/hooks/resume
new file mode 100755
index 0000000..8ff84dd
--- /dev/null
+++ b/hooks/resume
@@ -0,0 +1,117 @@
+#!/bin/sh
+
+PREREQ=""
+
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case $1 in
+# get pre-requisites
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /usr/share/initramfs-tools/scripts/functions
+
+# First check if a location is set and is a valid swap partition.
+# If so, the config file will be copied in and there is nothing to do.
+if [ -n "$RESUME" ] && [ "$RESUME" != auto ]; then
+ if [ "$RESUME" = none ]; then
+ exit 0
+ fi
+ if resume_dev_node="$(resolve_device "$RESUME")" && \
+ blkid -p -n swap "$resume_dev_node" >/dev/null 2>&1; then
+ exit 0
+ fi
+
+ echo >&2 "W: initramfs-tools configuration sets RESUME=$RESUME"
+ echo >&2 "W: but no matching swap device is available."
+fi
+
+# If we were not explicitly requested to select a device, or the -v
+# option is used, report that we are doing so
+report_auto()
+{
+ test "${verbose?}" != y && test "$RESUME" = auto || echo "I: $*"
+}
+
+# Report in excruciating detail if the -v option is used
+report_verbose()
+{
+ test "${verbose?}" != y || echo "I: $*"
+}
+
+report_verbose "Configuration sets RESUME=$RESUME"
+
+# Try to autodetect the RESUME partition, using biggest swap device that
+# is not ephemeral. We need to be able to read the listed swap partitions.
+resume_auto=
+if ! ischroot && [ -r /proc/swaps ]; then
+ # shellcheck disable=SC2013
+ for resume_auto in $(grep ^/dev/ /proc/swaps | sort -rnk3 | cut -d " " -f 1); do
+ report_verbose "Checking swap device $resume_auto"
+ ephemeral=false
+ dm_name="$(dmsetup info -c --noheadings -o name "$resume_auto" 2>/dev/null)"
+
+ # dm-crypt is ephemeral if the key file is /dev/urandom
+ if [ -n "$dm_name" ] && [ -e /etc/crypttab ]; then
+ report_verbose "$resume_auto has device-mapper name $dm_name; checking crypttab"
+ # shellcheck disable=SC2034
+ while read -r cryptdev srcdev keyfile junk; do
+ report_verbose "Found cryptdev=$cryptdev keyfile=$keyfile"
+ if [ "$cryptdev" = "$dm_name" ] && [ "$keyfile" = /dev/urandom ]; then
+ report_verbose "Rejecting $resume_auto since it has no permanent key"
+ ephemeral=true
+ fi
+ done < /etc/crypttab
+ fi
+
+ # zram is ephemeral
+ case "$resume_auto" in
+ /dev/zram*)
+ report_verbose "Rejecting $resume_auto since it is zram"
+ ephemeral=true
+ ;;
+
+ /dev/zd[0-9]*)
+ report_verbose "Rejecting $resume_auto since it is zvol"
+ ephemeral=true
+ ;;
+ esac
+
+ $ephemeral || break
+ done
+
+ if $ephemeral; then
+ resume_auto=
+ fi
+ if [ -n "$resume_auto" ]; then
+ if [ -n "$dm_name" ]; then
+ resume_auto_canon="/dev/mapper/$dm_name"
+ elif UUID=$(blkid -s UUID -o value "$resume_auto"); then
+ resume_auto_canon="UUID=$UUID"
+ else
+ resume_auto_canon=
+ fi
+ report_auto "The initramfs will attempt to resume from $resume_auto"
+ if [ -n "$resume_auto_canon" ]; then
+ report_auto "($resume_auto_canon)"
+ resume_auto="$resume_auto_canon"
+ fi
+ report_auto "Set the RESUME variable to override this."
+ fi
+fi
+
+# Write selected resume device to intramfs conf.d
+if [ "$RESUME" = auto ] || [ -n "$resume_auto" ]; then
+ # If we were explicitly requested to select a device, and we failed,
+ # report that
+ if [ -z "$resume_auto" ]; then
+ echo >&2 "W: initramfs-tools failed to select a resume device"
+ fi
+ echo "RESUME=${resume_auto}" > "${DESTDIR}/conf/conf.d/zz-resume-auto"
+fi
diff --git a/hooks/thermal b/hooks/thermal
new file mode 100755
index 0000000..0a42c12
--- /dev/null
+++ b/hooks/thermal
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+PREREQ=""
+
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case $1 in
+# get pre-requisites
+prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+# Hooks for loading thermal bits into the initramfs
+
+. /usr/share/initramfs-tools/hook-functions
+
+case "$DPKG_ARCH" in
+# copy the right modules
+powerpc|ppc64)
+
+ # Only G5 Mac machines need to load
+ # windfarm_core or one of the windfarm_pm* modules.
+
+ [ -r /proc/cpuinfo ] || exit 0
+
+ MODEL="$(grep model /proc/cpuinfo)"
+ MODEL="${MODEL##*: }"
+
+ case "$MODEL" in
+ RackMac3,1)
+ force_load windfarm_rm31
+ ;;
+ PowerMac7,2|PowerMac7,3)
+ force_load windfarm_pm72
+ ;;
+ PowerMac8,1|PowerMac8,2)
+ force_load windfarm_pm81
+ ;;
+ PowerMac9,1)
+ force_load windfarm_pm91
+ ;;
+ PowerMac11,2)
+ force_load windfarm_pm112
+ ;;
+ PowerMac12,1)
+ force_load windfarm_pm121
+ ;;
+ *)
+ # No other machine needs windfarm_* modules on initrd.
+ exit 0
+ ;;
+ esac
+ manual_add_modules windfarm_core
+ manual_add_modules windfarm_cpufreq_clamp
+ manual_add_modules windfarm_lm75_sensor
+ manual_add_modules windfarm_max6690_sensor
+ manual_add_modules windfarm_pid
+ manual_add_modules windfarm_smu_controls
+ manual_add_modules windfarm_smu_sat
+ manual_add_modules windfarm_smu_sensors
+ ;;
+i386|amd64|ia64)
+ manual_add_modules fan
+ manual_add_modules thermal
+ ;;
+esac