90-loaderentry.install revision 6fd2ccc957f21a423e1457c66e53b1697944d72a
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering#!/bin/bash
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering
84e51726a38e133ca42d2f30f0668d3921b210cbLennart PoetteringCOMMAND="$1"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart PoetteringKERNEL_VERSION="$2"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart PoetteringBOOT_DIR_ABS="$3"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart PoetteringKERNEL_IMAGE="$4"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poetteringif [[ -f /etc/machine-id ]]; then
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering read MACHINE_ID < /etc/machine-id
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poetteringfi
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poetteringif ! [[ $MACHINE_ID ]]; then
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering exit 1
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poetteringfi
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering
84e51726a38e133ca42d2f30f0668d3921b210cbLennart PoetteringBOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart PoetteringLOADER_ENTRY="/boot/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poetteringif [[ $COMMAND == remove ]]; then
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering exec rm -f "$LOADER_ENTRY"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poetteringfi
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poetteringif ! [[ $COMMAND == add ]]; then
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering exit 1
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringfi
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringif ! [[ $KERNEL_IMAGE ]]; then
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering exit 1
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringfi
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringif [[ -f /etc/os-release ]]; then
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering . /etc/os-release
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringelif [[ -f /usr/lib/os-release ]]; then
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering . /usr/lib/os-release
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringfi
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringif ! [[ $PRETTY_NAME ]]; then
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering PRETTY_NAME="Linux $KERNEL_VERSION"
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringfi
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringdeclare -a BOOT_OPTIONS
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringif [[ -f /etc/kernel/cmdline ]]; then
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringfi
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringif ! [[ ${BOOT_OPTIONS[*]} ]]; then
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering read -r -d '' -a line < /proc/cmdline
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering for i in "${line[@]}"; do
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering [[ "${i#initrd=*}" != "$i" ]] && continue
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering BOOT_OPTIONS+=("$i")
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering done
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringfi
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringif ! [[ ${BOOT_OPTIONS[*]} ]]; then
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering echo "Could not determine the kernel command line parameters." >&2
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering exit 1
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringfi
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poetteringcp "$KERNEL_IMAGE" "$BOOT_DIR_ABS/linux" &&
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering chown root:root "$BOOT_DIR_ABS/linux" &&
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering chmod 0644 "$BOOT_DIR_ABS/linux" || {
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering echo "Could not copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'." >&2
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering exit 1
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering}
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poetteringmkdir -p "${LOADER_ENTRY%/*}" || {
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering exit 1
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering}
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering{
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering echo "title $PRETTY_NAME"
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering echo "version $KERNEL_VERSION"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering echo "machine-id $MACHINE_ID"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering echo "options ${BOOT_OPTIONS[*]}"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering echo "linux $BOOT_DIR/linux"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering [[ -f $BOOT_DIR_ABS/initrd ]] && \
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering echo "initrd $BOOT_DIR/initrd"
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering :
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering} > "$LOADER_ENTRY" || {
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering echo "Could not create loader entry '$LOADER_ENTRY'." >&2
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering exit 1
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering}
12ca818ffddb77eb6a0fabe369a5bcbf6994ff8bLennart Poetteringexit 0
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering