Skip to content

Commit

Permalink
extensions: Add "Extension: ${EXTENSION}: " prefix to some extension …
Browse files Browse the repository at this point in the history
…logs

Establish some consistency with extension logging. Some extensions use another format:
display_alert "message" "${EXTENSION}" "info"

These were *not* adapted to this new schema.
  • Loading branch information
ColorfulRhino authored and igorpecovnik committed Jul 18, 2024
1 parent b6b8a89 commit cc59d8a
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 78 deletions.
2 changes: 1 addition & 1 deletion extensions/armbian-live-patch.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function post_family_tweaks_bsp__armbian-live-patch() {

display_alert "Installing Armbian Live Patch" "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Installing Armbian Live Patch" "${EXTENSION}" "info"

run_host_command_logged cat <<- 'armbian-live-patch' > "${destination}"/etc/systemd/system/armbian-live-patch.service
# Armbian simple patch system service
Expand Down
10 changes: 5 additions & 5 deletions extensions/bluetooth-hciattach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# To use, enable_extension bluetooth-hciattach, and set BLUETOOTH_HCIATTACH_PARAMS and BLUETOOTH_HCIATTACH_RKFILL_NUM.

function extension_prepare_config__bluetooth_hciattach() {
display_alert "${EXTENSION} ${BOARD}" "initializing config" "info"
display_alert "Extension: ${EXTENSION}: ${BOARD}" "initializing config" "info"

# Bomb if BLUETOOTH_HCIATTACH_PARAMS is not set.
if [[ -z "${BLUETOOTH_HCIATTACH_PARAMS}" ]]; then
exit_with_error "${EXTENSION} ${BOARD} - BLUETOOTH_HCIATTACH_PARAMS is not set - please set in the board file."
exit_with_error "Extension: ${EXTENSION}: ${BOARD} - BLUETOOTH_HCIATTACH_PARAMS is not set - please set in the board file."
fi

# Default BLUETOOTH_HCIATTACH_RKFILL_NUM to 0 if not set.
Expand All @@ -23,13 +23,13 @@ function extension_prepare_config__bluetooth_hciattach() {

# Add bluetooth packages to the image (not rootfs cache)
function post_family_config__bluetooth_hciattach_add_bluetooth_packages() {
display_alert "${EXTENSION} ${BOARD}" "adding bluetooth packages to image" "info"
display_alert "Extension: ${EXTENSION}: ${BOARD}" "adding bluetooth packages to image" "info"
add_packages_to_image rfkill bluetooth bluez bluez-tools
}

# Deploy the script and the systemd service in the BSP. It'll be enabled below in the image.
function post_family_tweaks_bsp__bluetooth_hciattach_add_systemd_service() {
display_alert "${EXTENSION} ${BOARD}" "adding bluetooth hciattach service to BSP" "info"
display_alert "Extension: ${EXTENSION}: ${BOARD}" "adding bluetooth hciattach service to BSP" "info"
: "${destination:?destination is not set}"

declare script_dir="/usr/local/sbin"
Expand Down Expand Up @@ -61,7 +61,7 @@ function post_family_tweaks_bsp__bluetooth_hciattach_add_systemd_service() {

# Enable the service created in the BSP above.
function post_family_tweaks__bluetooth_hciattach_enable_bt_service_in_image() {
display_alert "${EXTENSION} ${BOARD}" "enabling bluetooth hciattach service in the image" "info"
display_alert "Extension: ${EXTENSION}: ${BOARD}" "enabling bluetooth hciattach service in the image" "info"

chroot_sdcard systemctl --no-reload enable "bluetooth-hciattach.service"

Expand Down
2 changes: 1 addition & 1 deletion extensions/c-plus-plus-compiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Enable this extension if you need a C++ compiler during the build.

function add_host_dependencies__add_arm64_c_plus_plus_compiler() {
display_alert "Adding arm64 c++ compiler to host dependencies" "g++" "debug"
display_alert "Extension: ${EXTENSION}: Adding arm64 c++ compiler to host dependencies" "g++" "debug"
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} g++-aarch64-linux-gnu g++" # @TODO: convert to array later
}
6 changes: 3 additions & 3 deletions extensions/cleanup-space-final-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ function post_umount_final_image__200_zerofree() {
local partType
partType="$(file -s "${partDev}" | awk -F ': ' '{print $2}')"
if [[ "${partType}" == *"ext4"* ]]; then
display_alert "Zerofreeing ext4 partition ${partDev}" "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Zerofreeing ext4 partition ${partDev}" "${EXTENSION}" "info"
run_host_command_logged zerofree "${partDev}"
else
display_alert "Skipping zerofreeing partition ${partDev} of type '${partType}'" "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Skipping zerofreeing partition ${partDev} of type '${partType}'" "${EXTENSION}" "info"
fi
done
}

function pre_umount_final_image__999_show_space_usage() {
display_alert "Calculating used space in image" "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Calculating used space in image" "${EXTENSION}" "info"
run_host_command_logged "cd ${MOUNT} && " du -h -d 4 -x "." "| sort -h | tail -20"
}
11 changes: 6 additions & 5 deletions extensions/cloud-init/cloud-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,31 @@ function extension_prepare_config__ci_image_suffix() {

function extension_prepare_config__prepare_ci() {
# Cloud Init related packages selected from Ubuntu RPI distirbution
display_alert "Extension: ${EXTENSION}: Adding extra packages to image" "cloud-init cloud-initramfs-dyn-netconf" "info"
add_packages_to_image cloud-init cloud-initramfs-dyn-netconf
}

function extension_prepare_config__ci_compatibility_check() {
# We require fat boot partition, will change and if the user provided another type, will fail.
if [[ -z "${BOOTFS_TYPE}" ]]; then
declare -g BOOTFS_TYPE="fat"
display_alert "Changing BOOTFS_TYPE" "cloud_init requires a fat partition" "warn"
display_alert "Extension: ${EXTENSION}: Changing BOOTFS_TYPE" "cloud_init requires a fat partition" "warn"
fi

if [[ "${BOOTFS_TYPE}" != "fat" ]]; then
exit_with_error "BOOTFS_TYPE ${BOOTFS_TYPE} not compatible with cloud-init"
exit_with_error "Extension: ${EXTENSION}: BOOTFS_TYPE ${BOOTFS_TYPE} not compatible with cloud-init"
fi
}

function pre_customize_image__inject_cloud_init_config() {
# Copy the NoCLoud Cloud-Init Configuration
display_alert "Configuring" "cloud-init" "info"
display_alert "Extension: ${EXTENSION}: Configuring" "cloud-init" "info"
local config_src="${EXTENSION_DIR}/config"
local config_dst="${SDCARD}/etc/cloud/cloud.cfg.d"
run_host_command_logged cp ${config_src}/* $config_dst

# Provide default cloud-init files
display_alert "Defaults" "cloud-init" "info"
display_alert "Extension: ${EXTENSION}: Defaults" "cloud-init" "info"
local defaults_src="${EXTENSION_DIR}/defaults"
local defaults_dst="${SDCARD}/boot"
run_host_command_logged cp ${defaults_src}/* $defaults_dst
Expand All @@ -55,7 +56,7 @@ function pre_customize_image__inject_cloud_init_config() {

# @TODO: would be better to have "armbian first run" as an extension that can be disabled
function pre_customize_image__disable_armbian_first_run() {
display_alert "Disabling" "armbian first run" "info"
display_alert "Extension: ${EXTENSION}: Disabling" "armbian firstrun" "info"

# Clean up default profile and network
rm -f ${SDCARD}/etc/profile.d/armbian-check-first-*
Expand Down
4 changes: 2 additions & 2 deletions extensions/fake-vcgencmd.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

function pre_umount_final_image__install_fake_vcgencmd() {
display_alert "Installing fake vcgencmd" "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Installing fake vcgencmd" "${EXTENSION}" "info"

if [[ $BOARD != rpi4b ]]; then
run_host_command_logged curl -vo "${MOUNT}"/usr/bin/vcgencmd "https://raw.githubusercontent.com/clach04/fake_vcgencmd/0.0.2/vcgencmd"
Expand All @@ -11,6 +11,6 @@ function pre_umount_final_image__install_fake_vcgencmd() {
run_host_command_logged curl -vo "${MOUNT}"/usr/share/doc/fake_vcgencmd/LICENSE "https://raw.githubusercontent.com/clach04/fake_vcgencmd/0.0.2/LICENSE"
run_host_command_logged curl -vo "${MOUNT}"/usr/share/doc/fake_vcgencmd/README.md "https://raw.githubusercontent.com/clach04/fake_vcgencmd/0.0.2/README.md"
else
display_alert "Omitting installation on Raspberry Pi boards as these ship the original vcgencmd" "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Omitting installation on Raspberry Pi boards as these ship the original vcgencmd" "${EXTENSION}" "info"
fi
}
4 changes: 2 additions & 2 deletions extensions/fs-btrfs-support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# This is automatically enabled if ROOTFS_TYPE is set to btrfs in main-config.sh.

function extension_prepare_config__add_to_image_btrfs-progs() {
display_alert "Adding btrfs-progs extra package..." "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Adding extra package to image" "btrfs-progs" "info"
add_packages_to_image btrfs-progs
}

function add_host_dependencies__add_btrfs_tooling() {
display_alert "Adding BTRFS to host dependencies" "BTRFS" "debug"
display_alert "Extension: ${EXTENSION}: Adding packages to host dependencies" "btrfs-progs" "debug"
EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} btrfs-progs" # @TODO: convert to array later
}
14 changes: 7 additions & 7 deletions extensions/fs-cryptroot-support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
# This is automatically enabled if CRYPTROOT_ENABLE is set to yes in main-config.sh.

function add_host_dependencies__add_cryptroot_tooling() {
display_alert "Adding cryptroot to host dependencies" "cryptsetup LUKS" "debug"
display_alert "Extension: ${EXTENSION}: Adding packages to host dependencies" "cryptsetup openssh-client" "info"
EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} cryptsetup openssh-client" # @TODO: convert to array later
}

function extension_prepare_config__prepare_cryptroot() {
display_alert "Adding rootfs encryption related packages" "cryptsetup cryptsetup-initramfs" "info"
display_alert "Extension: ${EXTENSION}: Adding extra packages to image" "cryptsetup cryptsetup-initramfs" "info"
add_packages_to_image cryptsetup cryptsetup-initramfs

# Config for cryptroot, a boot partition is required.
declare -g BOOTPART_REQUIRED=yes
EXTRA_IMAGE_SUFFIXES+=("-crypt")

if [[ $CRYPTROOT_SSH_UNLOCK == yes ]]; then
display_alert "Adding rootfs encryption related packages" "dropbear-initramfs" "info"
display_alert "Extension: ${EXTENSION}: Adding extra packages to image" "dropbear-initramfs" "info"
add_packages_to_image dropbear-initramfs
fi
}

function prepare_root_device__encrypt_root_device() {
# We encrypt the rootdevice (currently a loop device) and return the new mapped rootdevice
check_loop_device "$rootdevice"
display_alert "Encrypting root partition with LUKS..." "cryptsetup luksFormat $rootdevice" ""
display_alert "Extension: ${EXTENSION}: Encrypting root partition with LUKS..." "cryptsetup luksFormat $rootdevice" ""
echo -n $CRYPTROOT_PASSPHRASE | cryptsetup luksFormat $CRYPTROOT_PARAMETERS $rootdevice -
echo -n $CRYPTROOT_PASSPHRASE | cryptsetup luksOpen $rootdevice $ROOT_MAPPER -
display_alert "Root partition encryption complete." "" "ext"
display_alert "Extension: ${EXTENSION}: Root partition encryption complete." "" "ext"
# TODO: pass /dev/mapper to Docker
rootdevice=/dev/mapper/$ROOT_MAPPER # used by `mkfs` and `mount` commands
}
Expand Down Expand Up @@ -56,7 +56,7 @@ function pre_install_kernel_debs__adjust_dropbear_configuration() {
else
# generate a default ssh key for login on dropbear in initramfs
# this key should be changed by the user on first login
display_alert "Generating a new SSH key pair for dropbear (initramfs)" "" ""
display_alert "Extension: ${EXTENSION}: Generating a new SSH key pair for dropbear (initramfs)" "" ""

# Generate the SSH keys
ssh-keygen -t ecdsa -f "${dropbear_dir}"/id_ecdsa \
Expand All @@ -68,7 +68,7 @@ function pre_install_kernel_debs__adjust_dropbear_configuration() {
CRYPTROOT_SSH_UNLOCK_KEY_NAME="${VENDOR}_${REVISION}_${BOARD^}_${RELEASE}_${BRANCH}_${DESKTOP_ENVIRONMENT}".key
# copy dropbear ssh key to image output dir for convenience
cp "${dropbear_dir}"/id_ecdsa "${DEST}/images/${CRYPTROOT_SSH_UNLOCK_KEY_NAME}"
display_alert "SSH private key for dropbear (initramfs) has been copied to:" \
display_alert "Extension: ${EXTENSION}: SSH private key for dropbear (initramfs) has been copied to:" \
"$DEST/images/$CRYPTROOT_SSH_UNLOCK_KEY_NAME" "info"
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion extensions/fs-f2fs-support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# This is automatically enabled if ROOTFS_TYPE is set to f2fs in main-config.sh.

function add_host_dependencies__add_f2fs_tooling() {
display_alert "Adding F2FS to host dependencies" "F2FS" "debug"
display_alert "Extension: ${EXTENSION}: Adding packages to host dependencies" "f2fs-tools" "debug"
EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} f2fs-tools" # @TODO: convert to array later
}
4 changes: 2 additions & 2 deletions extensions/fs-nilfs2-support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# This is automatically enabled if ROOTFS_TYPE is set to nilfs2 in main-config.sh.

function extension_prepare_config__add_to_image_nilfs-tools() {
display_alert "Adding nilfs-tools extra package..." "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Adding extra packages to image" "nilfs-tools" "info"
add_packages_to_image nilfs-tools
}

function add_host_dependencies__add_nilfs_tools() {
display_alert "Adding NILFS tools to host dependencies..." "${EXTENSION}" "debug"
display_alert "Extension: ${EXTENSION}: Adding packages to host dependencies" "nilfs-tools" "debug"
EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} nilfs-tools" # @TODO: convert to array later
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/fs-xfs-support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# This is automatically enabled if ROOTFS_TYPE is set to xfs in main-config.sh.

function extension_prepare_config__add_to_image_xfsprogs() {
display_alert "Adding xfsprogs extra package..." "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Adding extra packages to image" "xfsprogs" "info"
add_packages_to_image xfsprogs
}

function add_host_dependencies__add_xfs_tooling() {
display_alert "Adding XFS to host dependencies" "XFS xfsprogs" "debug"
display_alert "Extension: ${EXTENSION}: Adding packages to host dependencies" "xfsprogs" "debug"
EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} xfsprogs" # @TODO: convert to array later
}
2 changes: 1 addition & 1 deletion extensions/gen-sample-extension-docs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
## Hooks
function extension_metadata_ready__499_display_docs_generation_start_info() {
display_alert "Generating hook documentation and sample extension"
display_alert "Extension: ${EXTENSION}: Generating hook documentation and sample extension"
}

function extension_metadata_ready__docs_markdown() {
Expand Down
26 changes: 13 additions & 13 deletions extensions/grub-riscv64.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user.
function extension_prepare_config__prepare_grub-riscv64() {
display_alert "Prepare config" "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Prepare config" "${EXTENSION}" "info"
# Extension configuration defaults.
declare -g DISTRO_GENERIC_KERNEL=${DISTRO_GENERIC_KERNEL:-no} # if yes, does not build our own kernel, instead, uses generic one from distro
declare -g UEFI_GRUB_TERMINAL="${UEFI_GRUB_TERMINAL:-serial console}" # 'serial' forces grub menu on serial console. empty to not include
Expand All @@ -20,7 +20,7 @@ function extension_prepare_config__prepare_grub-riscv64() {
declare -g UEFI_GRUB_TARGET="riscv64-efi" # Default for x86_64

if [[ "${DISTRIBUTION}" != "Ubuntu" && "${BUILDING_IMAGE}" == "yes" ]]; then
exit_with_error "${DISTRIBUTION} is not supported yet"
exit_with_error "Extension: ${EXTENSION}: ${DISTRIBUTION} is not supported yet"
fi

add_packages_to_image efibootmgr efivar cloud-initramfs-growroot busybox os-prober "grub-efi-${ARCH}-bin" "grub-efi-${ARCH}"
Expand All @@ -32,10 +32,10 @@ pre_umount_final_image__install_grub() {

configure_grub
local chroot_target="${MOUNT}"
display_alert "Installing bootloader" "GRUB" "info"
display_alert "Extension: ${EXTENSION}: Installing bootloader" "GRUB" "info"

# RiscV64 specific: actually copy the DTBs to the ESP
display_alert "Copying DTBs to ESP" "${EXTENSION}" "info"
display_alert "Extension: ${EXTENSION}: Copying DTBs to ESP" "${EXTENSION}" "info"
run_host_command_logged mkdir -pv "${chroot_target}"/boot/efi/dtb
run_host_command_logged cp -rpv "${chroot_target}"/boot/dtb/* "${chroot_target}"/boot/efi/dtb/
# RiscV64 specific: @TODO ??? what is this ??
Expand All @@ -61,39 +61,39 @@ pre_umount_final_image__install_grub() {
# shellcheck disable=SC2016 # some wierd escaping going on there.
chroot_custom "$chroot_target" mkdir -pv '/dev/disk/by-uuid/"$(grub-probe --target=fs_uuid /)"' "||" true

display_alert "Creating GRUB config..." "${EXTENSION}: grub-mkconfig / update-grub"
display_alert "Extension: ${EXTENSION}: Creating GRUB config..." "${EXTENSION}: grub-mkconfig / update-grub"
chroot_custom "$chroot_target" update-grub || {
exit_with_error "update-grub failed!"
}

local install_grub_cmdline="grub-install --target=${UEFI_GRUB_TARGET} --no-nvram --removable" # nvram is global to the host, even across chroot. take care.
display_alert "Installing GRUB EFI..." "${EXTENSION}: ${UEFI_GRUB_TARGET}"
display_alert "Extension: ${EXTENSION}: Installing GRUB EFI..." "${EXTENSION}: ${UEFI_GRUB_TARGET}"
chroot_custom "$chroot_target" "$install_grub_cmdline" || {
exit_with_error "${install_grub_cmdline} failed!"
exit_with_error "Extension: ${EXTENSION}: ${install_grub_cmdline} failed!"
}

### Sanity check. The produced "/boot/grub/grub.cfg" should:
declare -i has_failed_sanity_check=0

# - NOT have any mention of `/dev` inside; otherwise something is going to fail
if grep -q '/dev' "${chroot_target}/boot/grub/grub.cfg"; then
display_alert "GRUB sanity check failed" "grub.cfg contains /dev" "err"
display_alert "Extension: ${EXTENSION}: GRUB sanity check failed" "grub.cfg contains /dev" "err"
SHOW_LOG=yes run_host_command_logged grep '/dev' "${chroot_target}/boot/grub/grub.cfg" "||" true
has_failed_sanity_check=1
else
display_alert "GRUB config sanity check passed" "no '/dev' found in grub.cfg" "info"
display_alert "Extension: ${EXTENSION}: GRUB config sanity check passed" "no '/dev' found in grub.cfg" "info"
fi

# - HAVE references to initrd, otherwise going to fail.
if ! grep -q 'initrd.img' "${chroot_target}/boot/grub/grub.cfg"; then
display_alert "GRUB config sanity check failed" "no initrd.img references found in /boot/grub/grub.cfg" "err"
display_alert "Extension: ${EXTENSION}: GRUB config sanity check failed" "no initrd.img references found in /boot/grub/grub.cfg" "err"
has_failed_sanity_check=1
else
display_alert "GRUB config sanity check passed" "initrd.img references found OK in /boot/grub/grub.cfg" "debug"
display_alert "Extension: ${EXTENSION}: GRUB config sanity check passed" "initrd.img references found OK in /boot/grub/grub.cfg" "debug"
fi

if [[ ${has_failed_sanity_check} -gt 0 ]]; then
exit_with_error "GRUB config sanity check failed, image will be unbootable; see above errors"
exit_with_error "Extension: ${EXTENSION}: GRUB config sanity check failed, image will be unbootable; see above errors"
fi

# Remove host-side config.
Expand Down Expand Up @@ -122,7 +122,7 @@ configure_grub() {
run_host_command_logged chmod -v +x "${MOUNT}"/usr/share/desktop-base/grub_background.sh
fi

display_alert "GRUB EFI kernel cmdline" "'${GRUB_CMDLINE_LINUX_DEFAULT}' distro=${UEFI_GRUB_DISTRO_NAME} timeout=${UEFI_GRUB_TIMEOUT}" ""
display_alert "Extension: ${EXTENSION}: GRUB EFI kernel cmdline" "'${GRUB_CMDLINE_LINUX_DEFAULT}' distro=${UEFI_GRUB_DISTRO_NAME} timeout=${UEFI_GRUB_TIMEOUT}" ""
cat <<- grubCfgFrag >> "${MOUNT}"/etc/default/grub.d/98-armbian.cfg
GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT}"
GRUB_TIMEOUT_STYLE=menu # Show the menu with Kernel options (Armbian or -generic)...
Expand Down
Loading

0 comments on commit cc59d8a

Please sign in to comment.