show errors on _full_dir, remove mode support from _file, remove firmware from module check, fix _abort directory remove

This commit is contained in:
Tobias Powalowski 2023-10-14 19:23:37 +02:00
parent 4d159100d0
commit 6a87cbfd29
5 changed files with 16 additions and 54 deletions

View file

@ -31,8 +31,8 @@ EOF
_abort() {
echo "Error:" "$@"
if [[ -n "$_d_workdir" ]]; then
rm -rf -- "$_d_workdir"
if [[ -n "${_BUILD_DIR}" ]]; then
rm -rf -- "${_BUILD_DIR}"
fi
exit 1
}
@ -90,24 +90,6 @@ _all_modules() {
return $(( !${#_MODS[*]} ))
}
_firmware() {
# add a firmware file to the image.
# $1: firmware path fragment
local _FW _FW_DIR
local -a _FW_BIN
_FW_DIR=/lib/firmware
for _FW; do
# shellcheck disable=SC2154,SC2153
if ! compgen -G "${_ROOTFS}${_FW_DIR}/${_FW}?(.*)" &>"${_NO_LOG}"; then
if read -r _FW_BIN < <(compgen -G "${_FW_DIR}/${_FW}?(.*)"); then
_map _file "${_FW_BIN[@]}"
break
fi
fi
done
return 0
}
_module() {
# Add a kernel module to the rootfs. Dependencies will be
# discovered and added.
@ -134,8 +116,6 @@ _module() {
depends) IFS=',' read -r -a _DEPS <<< "${_VALUE}"
_map _module "${_DEPS[@]}"
;;
firmware) _FW+=("${_VALUE}")
;;
softdep) read -ra _SOFT <<<"${_VALUE}"
for i in "${_SOFT[@]}"; do
[[ ${i} == *: ]] && continue
@ -144,18 +124,13 @@ _module() {
;;
esac
done < <(modinfo -k "${_KERNELVERSION}" -0 "${_CHECK}" 2>"${_NO_LOG}")
if (( ${#_FW[*]} )); then
_firmware "${_FW[@]}"
fi
}
_full_dir() {
# Add a directory and all its contents, recursively, to the rootfs.
# No parsing is performed and the contents of the directory is added as is.
# $1: path to directory
if [[ -n "${1}" && -d "${1}" ]]; then
command tar -C / --hard-dereference -cpf - ."${1}" | tar -C "${_ROOTFS}" -xpf - || return 1
fi
tar -C / --hard-dereference -cpf - ."${1}" | tar -C "${_ROOTFS}" -xpf - || return 1
}
_dir() {
@ -168,7 +143,7 @@ _dir() {
# ignore dir already exists
return 0
fi
command mkdir -p -m "${_MODE}" "${_ROOTFS}${1}" || return 1
mkdir -p -m "${_MODE}" "${_ROOTFS}${1}" || return 1
}
_symlink() {
@ -191,30 +166,25 @@ _symlink() {
_LINK_SOURCE="$(realpath -eq -- "${_LINK_SOURCE}")"
fi
_dir "${_LINK_NAME%/*}"
command ln -sfn "${_LINK_SOURCE}" "${_ROOTFS}${_LINK_NAME}"
ln -sfn "${_LINK_SOURCE}" "${_ROOTFS}${_LINK_NAME}"
}
_file() {
# Add a plain file to the rootfs. No parsing is performed and only
# the singular file is added.
# $1: path to file
# $2: destination on initcpio (optional, defaults to same as source)
# $3: mode
# $2: destination on rootfs (optional, defaults to same as source)
# determine source and destination
local _SRC="${1}" _DEST="${2:-$1}" _MODE="${3}"
if [[ ! -e "${_ROOTFS}${_DEST}" ]]; then
if [[ "${_SRC}" != "${_DEST}" ]]; then
command tar --hard-dereference --transform="s|${_SRC}|${_DEST}|" -C / -cpf - ."${_SRC}" | tar -C "${_ROOTFS}" -xpf - || return 1
tar --hard-dereference --transform="s|${_SRC}|${_DEST}|" -C / -cpf - ."${_SRC}" | tar -C "${_ROOTFS}" -xpf - || return 1
else
command tar --hard-dereference -C / -cpf - ."${_SRC}" | tar -C "${_ROOTFS}" -xpf - || return 1
tar --hard-dereference -C / -cpf - ."${_SRC}" | tar -C "${_ROOTFS}" -xpf - || return 1
fi
if [[ -L "${_SRC}" ]]; then
_LINK_SOURCE="$(realpath -- "${_SRC}")"
_file "${_LINK_SOURCE}" "${_LINK_SOURCE}" "${_MODE}"
else
if [[ -n "${_MODE}" ]]; then
command chmod "${_MODE}" "${_ROOTFS}${_DEST}"
fi
fi
fi
}
@ -285,15 +255,11 @@ _run_hook() {
unset -f _run
# shellcheck disable=SC1090
. "${_HOOK_FILE}"
if ! declare -f _run >"${_NO_LOG}"; then
_abort "Hook ${_HOOK_FILE} has no run function!"
return 1
fi
_run
}
_install_modules() {
command tar --hard-dereference -C / -cpf - "$@" | tar -C "${_ROOTFS}" -xpf -
tar --hard-dereference -C / -cpf - "$@" | tar -C "${_ROOTFS}" -xpf -
echo "Generating module dependencies..."
_map _file "${_MODULE_DIR}"/modules.{builtin,builtin.modinfo,order}
depmod -b "${_ROOTFS}" "${_KERNELVERSION}"

View file

@ -35,7 +35,7 @@ _run ()
[[ "$(uname -m)" == "riscv64" ]] && _map _binary waitpid
### add C.UTF-8 locale
_dir /usr/lib/locale
_full_dir /usr/lib/locale/C.UTF-8
_full_dir /usr/lib/locale/C.utf8
### add custom locale
[[ -e "/usr/lib/locale/locale-archive" ]] && _file /usr/lib/locale/locale-archive

View file

@ -58,7 +58,7 @@ _run ()
if grep -qw 'archboot' /etc/hostname; then
_map _binary locale-gen localedef
_file /etc/locale.gen
_LANG="be bg cs da de en el es fi fr hu it lt lv mk nl nn pl pt ro ru sk sr sv uk"
_LANG="be bg cs da de en_US el es fi fr hu it lt lv mk nl nn pl pt ro ru sk sr sv uk"
for i in ${_LANG}; do
_full_dir "/usr/share/locale/${i}"
done
@ -116,7 +116,7 @@ _run ()
_map _binary dbus-cleanup-sockets dbus-daemon dbus-launch dbus-monitor dbus-run-session dbus-send dbus-test-tool \
dbus-update-activation-environment dbus-uuidgen /usr/lib/dbus-1.0/dbus-daemon-launch-helper
_dir /var/lib/dbus
_map _full_dir /etc/dbus-1 /usr/share/dbus-1
_map _full_dir /usr/share/dbus-1
# tpm2-tss files
_map _binary secret-tool pinentry pinentry-curses gpgme-tool gpgme-json
@ -131,7 +131,7 @@ _run ()
systemd-tty-ask-password-agent timedatectl systemd-repart userdbctl homectl oomctl portablectl systemd-creds \
systemd-cryptenroll systemd-dissect systemd-id128 systemd-sysext
_map _dir /etc/tmpfiles.d /etc/modules-load.d /etc/binfmt.d/ /var/lib/systemd
_map _full_dir /etc/sysctl.d/ /etc/systemd /etc/xdg /usr/lib/systemd /usr/share/systemd /usr/share/factory \
_map _full_dir /etc/sysctl.d /etc/systemd /etc/xdg /usr/lib/systemd /usr/share/systemd /usr/share/factory \
/usr/share/polkit-1 /usr/lib/tmpfiles.d /usr/lib/modules-load.d /usr/lib/sysusers.d /usr/lib/sysctl.d
_file /usr/share/archboot/base/etc/locale.conf /etc/locale.conf
_file /usr/share/archboot/base/etc/vconsole.conf /etc/vconsole.conf
@ -241,7 +241,6 @@ _run ()
### fix licenses
_map _file /usr/share/licenses/shadow/COPYING /usr/share/licenses/iana-etc/LICENSE \
/usr/share/licenses/dbus/COPYING /usr/share/licenses/p11-kit/COPYING
}
# vim: set ft=sh ts=4 sw=4 et:

View file

@ -8,7 +8,7 @@ _run ()
ifstat ctstat rtstat lnstat nstat rtacct rtmon ss tc bridge \
dcb devlink rdma tipc vdpa ethtool elinks weechat brctl
# add iproute 2, add openssl helper libraries
_map _full_dir /usr/lib/tc /usr/share/tc /etc/iproute2 /usr/lib/engines
_map _full_dir /usr/lib/tc /usr/share/tc /usr/lib/engines-3
# add dnssec-anchors
_file /etc/trusted-key.key
# add weechat plugins and defaults

View file

@ -25,9 +25,6 @@ _run ()
done
_map _full_dir /etc/gss /etc/gssproxy
_map _dir /var/lib/gssproxy/{clients,rcache} /var/log/gssproxy
_dir /var/lib/openldap
chmod 700 "${_ROOTFS}/var/lib/openldap"
chown 439:439 "${_ROOTFS}/var/lib/openldap"
# start sshd on startup
_symlink /etc/systemd/system/multi-user.target.wants/sshd.service /usr/lib/systemd/system/sshd.service
# start ttyd on startup