diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index 2a125a4..9783829 --- a/build.sh +++ b/build.sh @@ -1,9 +1,13 @@ #! /usr/bin/env bash +[ "${2}" ] || exit 1 FILE="$(realpath "${BASH_SOURCE[0]}")" -DIRECTORY="$(dirname "${FILE}")" -ROOT="$(dirname "${DIRECTORY}")" -[ -d "${ROOT}" ] || exit 1 -PROJECT="$(basename "${DIRECTORY}")" +SCRIPT="$(basename "${FILE}")" +ROOT="$(dirname "${FILE}")" +PROJECT="$(basename "${ROOT}")" + +PGP_PUB="${1}" +ESP_ROOT="${2}" +DATA_ROOT="${3}" function get_path_mount { stat --format '%m' "${1}" @@ -12,17 +16,16 @@ function get_mount_uuid { findmnt --noheadings --output 'UUID' "${1}" } function get_path_uuid { - local tmp="$(get_path_mount "${1}")" + local tmp="$(get_path_mount "${1}/")" get_mount_uuid "${tmp}" } -ESP="$(get_path_uuid "${ROOT}")" -if [ "${1}" ] ; then - DATA="$(get_path_uuid "${1}")" +ESP="$(get_path_uuid "${ESP_ROOT}")" +if [ "${DATA_ROOT}" ] ; then + DATA="$(get_path_uuid "${DATA_ROOT}")" else DATA="${ESP}" fi -PGP_PUB='312ACDF9BB03C81ADE95B9C09C7613450C80C24F' function sign { if [ -d "${1}" ] ; then local file @@ -48,54 +51,62 @@ function sign { fi } -NAME="$(basename "${FILE}")" -PREVIOUS="${PWD}" -cd "${DIRECTORY}" - # imports ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ -source "${NAME%.*}.mod" +source "${ROOT}/${SCRIPT%.*}.mod" + +# constants ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ + +BIOS_BOOT='/usr/lib/grub/i386-pc/boot.img' +COMPRESSION='xz' +GRUB_HEAD='# GRUB Environment Block' +SIGNED_GRUB='/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed' +SIGNED_SHIM='/usr/lib/shim/shimx64.efi.signed' # variables ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ -MEMDISK_ROOT='boot' -MEMDISK_DIRECTORY="${MEMDISK_ROOT}/grub" +MEMDISK_ROOT="${ESP_ROOT}/memdisk" +MEMDISK_DIRECTORY="${MEMDISK_ROOT}/boot/grub" MEMDISK_FILE="${MEMDISK_DIRECTORY}/grub.cfg" -MEMDISK_ARCHIVE="${MEMDISK_ROOT}.tar" -UEFI_ROOT="${ROOT}/efi" +MEMDISK_ARCHIVE="${MEMDISK_ROOT}/boot.tar" + +UEFI_ROOT="${ESP_ROOT}/efi" UEFI_DIRECTORY="${UEFI_ROOT}/boot" UEFI_CORE="${UEFI_DIRECTORY}/core.efi" UEFI_FILE="${UEFI_DIRECTORY}/bootx64.efi" UEFI_GRUB="${UEFI_DIRECTORY}/grubx64.efi" -SIGNED_GRUB='/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed' -SIGNED_SHIM='/usr/lib/shim/shimx64.efi.signed' -BIOS_BOOT='/usr/lib/grub/i386-pc/boot.img' -BIOS_DIRECTORY="${ROOT}/bios" -BIOS_FILE="${BIOS_DIRECTORY}/core.img" -BIOS_SETUP="${BIOS_DIRECTORY}/setup.sh" -COMPRESSION='xz' -BOOT_ROOT="${ROOT}/boot" + +BIOS_ROOT="${ESP_ROOT}/bios" +BIOS_FILE="${BIOS_ROOT}/core.img" +BIOS_SETUP="${BIOS_ROOT}/setup.sh" + +BOOT_ROOT="${ESP_ROOT}/boot" + +GRUB_CFG_SH="${ROOT}/grub.cfg.sh" +GRUB_SHIGNED="${ROOT}/grubx64.efi.signed.sh" + GRUB_ROOT="${BOOT_ROOT}/grub" GRUB_CFG="${GRUB_ROOT}/grub.cfg" -GRUB_CFG_SH="${DIRECTORY}/grub.cfg.sh" GRUBENV="${GRUB_ROOT}/grubenv" -GRUB_ENV="${ROOT}/grub.env" GRUB_FONTS="${GRUB_ROOT}/fonts" -GRUB_HEAD='# GRUB Environment Block' GRUB_LOCALES="${GRUB_ROOT}/locale" GRUB_PUB="${GRUB_ROOT}/grub.pgp" -GRUB_SHIGNED="${DIRECTORY}/grubx64.efi.signed.sh" GRUB_THEMES="${GRUB_ROOT}/themes" +GRUB_ENV="${ESP_ROOT}/grub.env" + +LIVE_ROOT="${BOOT_ROOT}/${PROJECT}" + # wipe ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ echo -n " +→ ${BOOT_ROOT} → ${MEMDISK_ROOT} → ${UEFI_ROOT} -→ ${BIOS_DIRECTORY} +→ ${BIOS_ROOT} " rm --force --recursive \ -"${MEMDISK_ROOT}" "${UEFI_ROOT}" "${BIOS_DIRECTORY}" +"${BOOT_ROOT}" "${MEMDISK_ROOT}" "${UEFI_ROOT}" "${BIOS_ROOT}" # memdisk ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ @@ -123,8 +134,10 @@ echo -n " ↙ ${MEMDISK_ROOT} ↘ ${MEMDISK_ARCHIVE} " +cd "${MEMDISK_ROOT}" tar --create --auto-compress \ ---file "${MEMDISK_ARCHIVE}" "${MEMDISK_ROOT}" +--file "${MEMDISK_ARCHIVE}" 'boot' +cd - # uefi ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ @@ -171,15 +184,15 @@ fi # bios ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ echo -n " -→ ${BIOS_DIRECTORY} +→ ${BIOS_ROOT} " -mkdir "${BIOS_DIRECTORY}" +mkdir "${BIOS_ROOT}" echo -n " ↙ ${BIOS_BOOT} -↘ ${BIOS_DIRECTORY} +↘ ${BIOS_ROOT} " -cp "${BIOS_BOOT}" "${BIOS_DIRECTORY}" +cp "${BIOS_BOOT}" "${BIOS_ROOT}" echo -n " ↙ ${MEMDISK_ARCHIVE} @@ -209,7 +222,6 @@ DIRECTORY="$(dirname "${FILE}")" echo -n " → ${GRUB_ROOT} " -rm --force --recursive "${GRUB_ROOT}" mkdir --parents "${GRUB_ROOT}" # grub / cfg ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ @@ -269,8 +281,8 @@ if cd '/usr/share/grub/themes' ; then cp --recursive "${theme}" "${GRUB_THEMES}" fi done + cd - fi -cd "${DIRECTORY}" # grub / locales ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ @@ -278,14 +290,15 @@ echo -n " → ${GRUB_LOCALES} " mkdir --parents "${GRUB_LOCALES}" -cd '/usr/share/locale' -for locale in * ; do - file="${locale}/LC_MESSAGES/grub.mo" - if [ -f "${file}" ] ; then - cp "${file}" "${GRUB_LOCALES}/${locale}.mo" - fi -done -cd "${DIRECTORY}" +if cd '/usr/share/locale' ; then + for locale in * ; do + file="${locale}/LC_MESSAGES/grub.mo" + if [ -f "${file}" ] ; then + cp "${file}" "${GRUB_LOCALES}/${locale}.mo" + fi + done + cd - +fi # grub / pubkey ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ @@ -302,39 +315,40 @@ for target in 'x86_64-efi' 'i386-pc' ; do ↙ /usr/lib/grub/${target} ↘ ${GRUB_ROOT}/${target} " - mkdir --parents "${GRUB_ROOT}/${target}" - cd "/usr/lib/grub/${target}" - for module in *.lst *.mod ; do - cp "${module}" "${GRUB_ROOT}/${target}" - done + if cd "/usr/lib/grub/${target}" ; then + mkdir --parents "${GRUB_ROOT}/${target}" + for module in *.lst *.mod ; do + cp "${module}" "${GRUB_ROOT}/${target}" + done + cd - + fi done -cd "${DIRECTORY}" + +# project ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ + +cp --recursive "${ROOT}/live" "${LIVE_ROOT}" # sign ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ -sign "${BIOS_DIRECTORY}" -sign "${UEFI_DIRECTORY}" -sign "${ROOT}/${PROJECT}/live" +sign "${BIOS_ROOT}" +sign "${UEFI_ROOT}" +sign "${LIVE_ROOT}" sign "${GRUB_ROOT}" # display ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ echo du --human-readable --summarize \ -"${BIOS_DIRECTORY}" \ +"${BIOS_ROOT}" \ "${UEFI_ROOT}" \ -"${BOOT_ROOT}" \ -"${ROOT}" -echo -echo "ESP: ${ESP}" -echo "DATA: ${DATA}" +"${LIVE_ROOT}" \ +"${GRUB_ROOT}" \ +"${ESP_ROOT}/" +echo -n " + ESP: ${ESP} +DATA: ${DATA} +" # clean ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ -rm --force --recursive \ -"${MEMDISK_ARCHIVE}" \ -"${MEMDISK_ROOT}" - -# back ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ - -cd "${PREVIOUS}" +rm --force --recursive "${MEMDISK_ROOT}" diff --git a/grub.cfg.sh b/grub.cfg.sh index 473493e..ae0fb18 100644 --- a/grub.cfg.sh +++ b/grub.cfg.sh @@ -27,7 +27,7 @@ function grub_init { --file "${env}" \ 'grub_sleep' # - live="(${esp})/${live_name}/live" + live="(${esp})/boot/${live_name}" # search --no-floppy --set data \ --fs-uuid "${data_uuid}" diff --git a/readme.md b/readme.md index 9d60274..fa3bc48 100644 --- a/readme.md +++ b/readme.md @@ -59,11 +59,10 @@ Build an ESP File System including: ## Tasks * bash - * args/pgp - * args/esp & lsgm/cp * mimic grubx64.efi.signed * efi * bios + * auto setup bios device * --prefix '(memdisk)' * live * check squashfs option