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