diff --git a/lib/functions/general/schedule_deletion.sh b/lib/functions/general/schedule_deletion.sh new file mode 100644 index 000000000000..15e2c316ae78 --- /dev/null +++ b/lib/functions/general/schedule_deletion.sh @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2025 tabris +# This file is a part of the Armbian Build Framework https://github.com/armbian/build/ + +declare -a schedule_deletion_files_to_delete + +function schedule_deletion() { + local file="$1" + local source="${BASH_SOURCE[1]}" + local func="${FUNCNAME[1]}" + local line="${BASH_LINENO[0]}" + + schedule_deletion_files_to_delete+=("$file;$source;$func;$line") +} + +function pre_umount_final_image__schedule_deletion_delete_now() { + local file source func line deletion_info + local had_errexit=0 + case $- in *e*) had_errexit=1;; esac + for deletion_info in "${schedule_deletion_files_to_delete[@]}"; do + IFS=';' read -r file source func line <<< "$deletion_info" + local reason="scheduled from $source $func line#$line" + local message="" + local failure=0 + + [[ $had_errexit ]] && set +e # don't bail out, let us bail out ourselves more verbosely + if [[ ! -e "$file" ]]; then + message="FILE DELETION FAILED (missing): '${file}'" + ((failure++)) + elif rm -- "$file"; then + message="deleted file '${file}'" + else + message="FILE DELETION FAILED: '${file}'" + ((failure++)) + fi + [[ $had_errexit ]] && set -e # restore the previous behaviour + if [[ $failure ]]; then + exit_with_error "$message; $reason" + else + display_alert "$message" "$reason" "info" + fi + done +} diff --git a/lib/functions/rootfs/create-cache.sh b/lib/functions/rootfs/create-cache.sh index 0be75c4ffbdd..03ab7fa28294 100644 --- a/lib/functions/rootfs/create-cache.sh +++ b/lib/functions/rootfs/create-cache.sh @@ -122,7 +122,7 @@ function extract_rootfs_artifact() { wait_for_disk_sync "after restoring rootfs cache" - run_host_command_logged rm -v "${SDCARD}"/etc/resolv.conf + run_host_command_logged rm -fv "${SDCARD}"/etc/resolv.conf run_host_command_logged echo "nameserver ${NAMESERVER}" ">" "${SDCARD}"/etc/resolv.conf # all sources etc. diff --git a/lib/functions/rootfs/rootfs-create.sh b/lib/functions/rootfs/rootfs-create.sh index 1a74a3212e69..7c22037ccfe0 100644 --- a/lib/functions/rootfs/rootfs-create.sh +++ b/lib/functions/rootfs/rootfs-create.sh @@ -345,7 +345,7 @@ function create_new_rootfs_cache_via_debootstrap() { # please reinitialize this to uninitialized. Do note that systemd will start all services then by # default and that has to be handled by setting system presets. run_host_command_logged echo -n ">" "${SDCARD}/etc/machine-id" - run_host_command_logged rm -fv "${SDCARD}/var/lib/dbus/machine-id" + schedule_deletion "${SDCARD}/var/lib/dbus/machine-id" # Mask `systemd-firstboot.service` which will prompt locale, timezone and root-password too early. # `armbian-first-run` will do the same thing later diff --git a/lib/library-functions.sh b/lib/library-functions.sh index 7dfcaeea72ee..bc1312c183bb 100644 --- a/lib/library-functions.sh +++ b/lib/library-functions.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# This file is/was autogenerated by ./lib/tools/gen-library.sh; don't modify manually +# This file is/was autogenerated by lib/tools/gen-library.sh; don't modify manually # no errors tolerated. invoked before each sourced file to make sure. #set -o pipefail # trace ERR through pipes - will be enabled "soon" @@ -748,6 +748,15 @@ set -o errexit ## set -e : exit the script if any statement returns a non-true # shellcheck source=lib/functions/general/retry.sh source "${SRC}"/lib/functions/general/retry.sh +# no errors tolerated. invoked before each sourced file to make sure. +#set -o pipefail # trace ERR through pipes - will be enabled "soon" +#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled +set -o errtrace # trace ERR through - enabled +set -o errexit ## set -e : exit the script if any statement returns a non-true return value - enabled +### lib/functions/general/schedule_deletion.sh +# shellcheck source=lib/functions/general/schedule_deletion.sh +source "${SRC}"/lib/functions/general/schedule_deletion.sh + # no errors tolerated. invoked before each sourced file to make sure. #set -o pipefail # trace ERR through pipes - will be enabled "soon" #set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled @@ -1176,4 +1185,4 @@ source "${SRC}"/lib/functions/rootfs/trap-rootfs.sh #set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled set -o errtrace # trace ERR through - enabled set -o errexit ## set -e : exit the script if any statement returns a non-true return value - enabled -# This file is/was autogenerated by ./lib/tools/gen-library.sh; don't modify manually +# This file is/was autogenerated by lib/tools/gen-library.sh; don't modify manually