2023-09-30 12:46:03 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
FILE="$(realpath "${BASH_SOURCE[0]}")"
|
|
|
|
DIRECTORY="$(dirname "${FILE}")"
|
|
|
|
ROOT="$(dirname "${DIRECTORY}")"
|
|
|
|
[ -d "${ROOT}" ] || exit 1
|
|
|
|
PROJECT="$(basename "${DIRECTORY}")"
|
|
|
|
|
|
|
|
function get_path_mount {
|
|
|
|
stat --format '%m' "${1}"
|
|
|
|
}
|
|
|
|
function get_mount_uuid {
|
|
|
|
findmnt --noheadings --output 'UUID' "${1}"
|
|
|
|
}
|
|
|
|
function get_path_uuid {
|
|
|
|
local tmp="$(get_path_mount "${1}")"
|
|
|
|
get_mount_uuid "${tmp}"
|
|
|
|
}
|
|
|
|
ESP="$(get_path_uuid "${ROOT}")"
|
|
|
|
|
|
|
|
DATA='b0626dca-c6c2-45fc-9a02-31549680bbe5'
|
|
|
|
|
|
|
|
PGP_PUB='BADA5579'
|
|
|
|
|
|
|
|
NAME="$(basename "${FILE}")"
|
|
|
|
PREVIOUS="${PWD}"
|
|
|
|
cd "${DIRECTORY}"
|
|
|
|
|
|
|
|
# imports ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
source "${NAME%.*}.mod"
|
|
|
|
|
|
|
|
# variables ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
MEMDISK_ROOT='boot'
|
|
|
|
MEMDISK_DIRECTORY="${MEMDISK_ROOT}/grub"
|
|
|
|
MEMDISK_FILE="${MEMDISK_DIRECTORY}/grub.cfg"
|
|
|
|
MEMDISK_PUB="${MEMDISK_DIRECTORY}/grub.pub"
|
|
|
|
MEMDISK_ARCHIVE="${MEMDISK_ROOT}.tar"
|
|
|
|
UEFI_ROOT="${ROOT}/efi"
|
|
|
|
UEFI_DIRECTORY="${UEFI_ROOT}/boot"
|
|
|
|
UEFI_FILE="${UEFI_DIRECTORY}/bootx64.efi"
|
|
|
|
BIOS_DIRECTORY="${ROOT}/bios"
|
|
|
|
BIOS_FILE="${BIOS_DIRECTORY}/core.img"
|
|
|
|
BIOS_SETUP="${BIOS_DIRECTORY}/setup.sh"
|
|
|
|
COMPRESSION='xz'
|
|
|
|
GRUB_ROOT="${ROOT}/grub"
|
|
|
|
GRUB_ENV="${ROOT}/grub.env"
|
|
|
|
GRUB_PUB="${GRUB_ROOT}/grub.pub"
|
|
|
|
|
|
|
|
# wipe ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
rm --force --recursive \
|
|
|
|
"${MEMDISK_ROOT}" "${UEFI_ROOT}" "${BIOS_DIRECTORY}"
|
|
|
|
|
|
|
|
# memdisk ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
mkdir --parents "${MEMDISK_DIRECTORY}"
|
|
|
|
|
|
|
|
echo -n "\
|
2023-10-01 17:59:50 +00:00
|
|
|
function set_init {
|
|
|
|
search --no-floppy --set data \\
|
2023-09-30 12:46:03 +00:00
|
|
|
--fs-uuid '${DATA}'
|
|
|
|
#
|
2023-10-01 17:59:50 +00:00
|
|
|
search --no-floppy --set esp \\
|
2023-09-30 12:46:03 +00:00
|
|
|
--fs-uuid '${ESP}'
|
|
|
|
if [ \"\${esp}\" ] ; then
|
|
|
|
env=\"(\${esp})/grub.env\"
|
|
|
|
live=\"(\${esp})/${PROJECT}/live\"
|
|
|
|
#
|
2023-09-30 17:52:10 +00:00
|
|
|
for file in \${live}/source/*.sh ; do
|
2023-09-30 12:46:03 +00:00
|
|
|
source \"\${file}\"
|
|
|
|
done
|
|
|
|
unset file
|
2023-10-01 17:59:50 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function normal_init {
|
|
|
|
check_signatures='no'
|
|
|
|
pager=1
|
|
|
|
#
|
|
|
|
set_init
|
|
|
|
if [ \"\${esp}\" ] ; then
|
|
|
|
prefix=\"(\${esp})/grub\"
|
|
|
|
root=\"\${esp}\"
|
2023-09-30 12:46:03 +00:00
|
|
|
#
|
2023-10-01 17:59:50 +00:00
|
|
|
normal \"\${live}/normal.sh\"
|
2023-09-30 12:46:03 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-10-01 17:59:50 +00:00
|
|
|
normal_init
|
2023-09-30 12:46:03 +00:00
|
|
|
" > "${MEMDISK_FILE}"
|
|
|
|
# gpg --detach-sign "${MEMDISK_FILE}"
|
|
|
|
|
|
|
|
gpg --export "${PGP_PUB}" > "${MEMDISK_PUB}"
|
|
|
|
# gpg --detach-sign "${MEMDISK_PUB}"
|
|
|
|
|
|
|
|
tar --create --auto-compress \
|
|
|
|
--file "${MEMDISK_ARCHIVE}" "${MEMDISK_ROOT}"
|
|
|
|
|
|
|
|
# uefi ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
mkdir --parents "${UEFI_DIRECTORY}"
|
|
|
|
|
|
|
|
grub-mkimage \
|
|
|
|
--compress "${COMPRESSION}" \
|
|
|
|
--memdisk "${MEMDISK_ARCHIVE}" \
|
|
|
|
--format 'x86_64-efi' \
|
|
|
|
--output "${UEFI_FILE}" \
|
|
|
|
--pubkey "${MEMDISK_PUB}" \
|
|
|
|
"${MODULES[@]}"
|
|
|
|
# gpg --detach-sign "${UEFI_FILE}"
|
|
|
|
|
|
|
|
# bios ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
mkdir "${BIOS_DIRECTORY}"
|
|
|
|
|
|
|
|
cp '/usr/lib/grub/i386-pc/boot.img' "${BIOS_DIRECTORY}"
|
|
|
|
# gpg --detach-sign "${BIOS_DIRECTORY}/boot.img"
|
|
|
|
|
|
|
|
grub-mkimage \
|
|
|
|
--compress "${COMPRESSION}" \
|
|
|
|
--memdisk "${MEMDISK_ARCHIVE}" \
|
|
|
|
--format 'i386-pc' \
|
|
|
|
--output "${BIOS_FILE}" \
|
|
|
|
--pubkey "${MEMDISK_PUB}" \
|
|
|
|
"${MODULES[@]}" "${MODULES_BIOS[@]}"
|
|
|
|
# gpg --detach-sign "${BIOS_FILE}"
|
|
|
|
|
|
|
|
echo -n '#! /usr/bin/env bash
|
|
|
|
FILE="$(realpath "${BASH_SOURCE[0]}")"
|
|
|
|
DIRECTORY="$(dirname "${FILE}")"
|
|
|
|
|
|
|
|
/usr/lib/grub/i386-pc/grub-bios-setup \
|
|
|
|
--directory "${DIRECTORY}" \
|
|
|
|
"${1}"
|
|
|
|
' >> "${BIOS_SETUP}"
|
|
|
|
# gpg --detach-sign "${BIOS_SETUP}"
|
|
|
|
|
|
|
|
# grub ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
rm --force --recursive "${GRUB_ROOT}"
|
|
|
|
mkdir --parents "${GRUB_ROOT}"
|
|
|
|
|
|
|
|
# grub / env ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
echo -n "\
|
|
|
|
# GRUB Environment Block
|
|
|
|
#######################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
################################################################\
|
|
|
|
" > "${GRUB_ENV}"
|
|
|
|
|
|
|
|
# grub / fonts ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
mkdir --parents "${GRUB_ROOT}/fonts"
|
|
|
|
for font in $(find '/usr/share/grub' -type 'f' -name '*.pf2') ; do
|
|
|
|
cp "${font}" "${GRUB_ROOT}/fonts"
|
|
|
|
done
|
|
|
|
|
|
|
|
# grub / themes ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
if cd '/usr/share/grub/themes' ; then
|
|
|
|
mkdir --parents "${GRUB_ROOT}/themes"
|
|
|
|
for theme in * ; do
|
|
|
|
if [ -f "${theme}/theme.txt" ] ; then
|
|
|
|
cp --recursive "${theme}" "${GRUB_ROOT}/themes"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
cd "${DIRECTORY}"
|
|
|
|
|
|
|
|
# grub / locales ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
mkdir --parents "${GRUB_ROOT}/locale"
|
|
|
|
cd '/usr/share/locale'
|
|
|
|
for locale in * ; do
|
|
|
|
file="${locale}/LC_MESSAGES/grub.mo"
|
|
|
|
if [ -f "${file}" ] ; then
|
|
|
|
cp "${file}" "${GRUB_ROOT}/locale/${locale}.mo"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
cd "${DIRECTORY}"
|
|
|
|
|
|
|
|
# grub / pubkey ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
gpg --export "${PGP_PUB}" > "${GRUB_PUB}"
|
|
|
|
|
|
|
|
# grub / modules ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
for target in 'x86_64-efi' 'i386-pc' ; do
|
|
|
|
mkdir --parents "${GRUB_ROOT}/${target}"
|
|
|
|
cd "/usr/lib/grub/${target}"
|
|
|
|
for module in *.lst *.mod ; do
|
|
|
|
echo "${target}/${module}"
|
|
|
|
cp "${module}" "${GRUB_ROOT}/${target}"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
cd "${DIRECTORY}"
|
|
|
|
|
|
|
|
# sign ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
readarray -t files <<< "$(find "${GRUB_ROOT}" -type f | sort)"
|
|
|
|
for file in "${files[@]}" ; do
|
|
|
|
echo "${file}"
|
|
|
|
# gpg --detach-sign "${file}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# display ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
du --human-readable --summarize \
|
|
|
|
"${UEFI_ROOT}" \
|
|
|
|
"${BIOS_DIRECTORY}" \
|
|
|
|
"${ROOT}"
|
|
|
|
|
|
|
|
echo "ESP: ${ESP}"
|
|
|
|
|
|
|
|
# clean ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
rm --force --recursive \
|
|
|
|
"${MEMDISK_ARCHIVE}" \
|
|
|
|
"${MEMDISK_ROOT}"
|
|
|
|
|
|
|
|
# back ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
|
|
|
|
|
|
|
|
cd "${PREVIOUS}"
|