From 489e71b7fb45e0e95396a2d085e4bfcb2287d580 Mon Sep 17 00:00:00 2001 From: Tobias Powalowski Date: Fri, 20 Oct 2023 16:21:03 +0200 Subject: [PATCH] collect all files first and run _install_files when it fits best --- usr/bin/archboot-cpio.sh | 1 + usr/lib/archboot/cpio/cpio.sh | 25 ++++++++++---- usr/lib/archboot/cpio/hooks/base_cleanup | 1 + usr/lib/archboot/cpio/hooks/base_common | 2 +- .../archboot/cpio/hooks/base_common_cleanup | 33 ++++++------------- .../archboot/cpio/hooks/filesystems_cleanup | 1 + usr/lib/archboot/cpio/hooks/firmware | 3 +- usr/lib/archboot/cpio/hooks/net_cleanup | 1 + usr/lib/archboot/cpio/hooks/remote | 3 +- 9 files changed, 36 insertions(+), 34 deletions(-) diff --git a/usr/bin/archboot-cpio.sh b/usr/bin/archboot-cpio.sh index 1d3d1e802..039ed808b 100755 --- a/usr/bin/archboot-cpio.sh +++ b/usr/bin/archboot-cpio.sh @@ -82,6 +82,7 @@ for i in "${_HOOKS[@]}"; do _run_hook "${i}" _HOOK_COUNT="$((_HOOK_COUNT+1))" done +_install_files _install_libs _install_mods "${!_MOD_PATH[@]}" ldconfig -r "${_ROOTFS}" &>"${_NO_LOG}" || exit 1 diff --git a/usr/lib/archboot/cpio/cpio.sh b/usr/lib/archboot/cpio/cpio.sh index 3ef708494..bde91c890 100644 --- a/usr/lib/archboot/cpio/cpio.sh +++ b/usr/lib/archboot/cpio/cpio.sh @@ -59,6 +59,11 @@ _map() { return "${_RETURN}" } +_loaded_mods() { +modinfo -k ${_KERNELVERSION} --field filename $(cut -d ' ' -f1 /dev/null +modinfo -k ${_KERNELVERSION} --field firmware $(cut -d ' ' -f1 ${_NO_LOG} | grep 'NEEDED' | sort -u | sed -e 's#NEEDED##g' -e 's# .* #/lib/#g') + _install_files echo "Checking libraries in /lib..." _LIB_COUNT="" while true; do @@ -231,6 +241,7 @@ _install_libs() { [[ -e "${i}" ]] && _file "${i}" done < <(objdump -p "${_ROOTFS}"/lib/*.so* | grep 'NEEDED' | sort -u | sed -e 's#NEEDED##g' -e 's# .* #/lib/#g') + _install_files # rerun loop if new libs were discovered, else break _LIB_COUNT2="$(ls "${_ROOTFS}"/lib/*.so* | wc -l)" [[ "${_LIB_COUNT}" == "${_LIB_COUNT2}" ]] && break diff --git a/usr/lib/archboot/cpio/hooks/base_cleanup b/usr/lib/archboot/cpio/hooks/base_cleanup index 6272c6267..add89375b 100644 --- a/usr/lib/archboot/cpio/hooks/base_cleanup +++ b/usr/lib/archboot/cpio/hooks/base_cleanup @@ -39,6 +39,7 @@ _run () if [[ "${_RUNNING_ARCH}" == "riscv64" ]]; then _APPS="waitpid ${_APPS}" fi + _install_files for i in ${_APPS}; do rm /usr/bin/"${i}" done diff --git a/usr/lib/archboot/cpio/hooks/base_common b/usr/lib/archboot/cpio/hooks/base_common index c033756a4..1bdc4c287 100644 --- a/usr/lib/archboot/cpio/hooks/base_common +++ b/usr/lib/archboot/cpio/hooks/base_common @@ -46,7 +46,7 @@ var/lib/pacman/local \ ### add nano _binary nano - _file /etc/nanorc + _file_rename /etc/nanorc /etc/nanorc # add syntax highlighting echo "include \"/usr/share/nano/*.nanorc\"" >> "${_ROOTFS}/etc/nanorc" diff --git a/usr/lib/archboot/cpio/hooks/base_common_cleanup b/usr/lib/archboot/cpio/hooks/base_common_cleanup index c23d5b948..cc39fbcff 100644 --- a/usr/lib/archboot/cpio/hooks/base_common_cleanup +++ b/usr/lib/archboot/cpio/hooks/base_common_cleanup @@ -10,29 +10,16 @@ _run () rm -f /tmp/etc/systemd/system/pacman-init.service # add created gpg keyring cp -ar /etc/pacman.d/gnupg /tmp/etc/pacman.d - apps="login nologin" - for i in $apps; do - rm /usr/bin/"${i}" - done - apps="mount.nfs4 umount.nfs umount.nfs4 mount.nfs setfont loadkeys mkfs.btrfs rmmod mountpoint gzip" - for i in $apps; do - rm /usr/bin/"${i}" - done - #dbus files - apps="dbus-cleanup-sockets dbus-daemon dbus-launch dbus-monitor dbus-run-session dbus-send dbus-test-tool \ - dbus-update-activation-environment dbus-uuidgen" - for i in $apps; do - rm /usr/bin/"${i}" - done - #systemd files - _APPS="systemd-umount busctl bootctl coredumpctl hostnamectl journalctl kernel-install localectl \ - loginctl machinectl networkctl systemctl systemd-analyze systemd-ask-password \ - systemd-cat systemd-cgls systemd-cgtop \ - systemd-delta systemd-detect-virt systemd-escape systemd-firstboot systemd-hwdb systemd-inhibit systemd-machine-id-setup \ - systemd-mount systemd-notify systemd-nspawn systemd-path systemd-resolve \ - systemd-run systemd-socket-activate systemd-stdio-bridge systemd-sysusers \ - systemd-tty-ask-password-agent timedatectl systemd-repart userdbctl homectl oomctl portablectl systemd-creds \ - systemd-cryptenroll systemd-dissect systemd-id128 systemd-sysext" + _APPS="login nologin mount.nfs4 umount.nfs umount.nfs4 mount.nfs setfont loadkeys mkfs.btrfs rmmod mountpoint gzip \ + dbus-cleanup-sockets dbus-daemon dbus-launch dbus-monitor dbus-run-session dbus-send dbus-test-tool \ + dbus-update-activation-environment dbus-uuidgen systemd-umount busctl bootctl coredumpctl hostnamectl \ + journalctl kernel-install localectl loginctl machinectl networkctl systemctl systemd-analyze systemd-ask-password \ + systemd-cat systemd-cgls systemd-cgtop systemd-delta systemd-detect-virt systemd-escape systemd-firstboot \ + systemd-hwdb systemd-inhibit systemd-machine-id-setup systemd-mount systemd-notify systemd-nspawn \ + systemd-path systemd-resolve systemd-run systemd-socket-activate systemd-stdio-bridge systemd-sysusers \ + systemd-tty-ask-password-agent timedatectl systemd-repart userdbctl homectl oomctl portablectl systemd-creds \ + systemd-cryptenroll systemd-dissect systemd-id128 systemd-sysext" + _install_files for i in ${_APPS}; do rm /usr/bin/"${i}" done diff --git a/usr/lib/archboot/cpio/hooks/filesystems_cleanup b/usr/lib/archboot/cpio/hooks/filesystems_cleanup index 0500e1ccd..6696ba76d 100644 --- a/usr/lib/archboot/cpio/hooks/filesystems_cleanup +++ b/usr/lib/archboot/cpio/hooks/filesystems_cleanup @@ -22,6 +22,7 @@ _run () nfsdcld nfsdclddb nfsdclnts nfsidmap nfsv4.exportd nilfs-clean nilfs-resize nilfs-tune \ xfs_growfs xfs_quota xfs_spaceman compile_et mk_cmds fsck.xfs xfs_admin \ xfs_bmap xfs_freeze xfs_info xfs_metadump xfs_mkfile xfs_ncheck" + _install_files for i in ${_APPS}; do rm /usr/bin/"${i}" done diff --git a/usr/lib/archboot/cpio/hooks/firmware b/usr/lib/archboot/cpio/hooks/firmware index 9654c9a2e..bcade6f0e 100644 --- a/usr/lib/archboot/cpio/hooks/firmware +++ b/usr/lib/archboot/cpio/hooks/firmware @@ -5,8 +5,7 @@ _run () { # add firmware files and licenses - tar -C / --exclude=./lib/firmware/{amphion,"as102*",atusb,av7110,cadence,cavium,"cmmb*",cis,cpia2,cnm,"ct*","cxgb*","cmmb*",dabusb,dpaa2,dsp56k,"dvb*",edgeport,emi26,emi62,ess,"f2255usb*",go7007,"hfi1*",inside-secure,"isdbt*","keyspan*",korg,meson,"lgs8g75*","lt9611uxc*",moxa,"mts*","myri10ge*",myricom,nxp,ositech,"qat*",sb16,"s2250*","s5p-*","sms1*",rtl_bt,"tdmb*",ttusb-budget,ueagle-atm,"usbdux*",ti,ti-keystone,"v4l*",vicam,vxge,"whiteheat*",yam,yamaha,"*.txt*","*README*"} --hard-dereference -cpf - ./lib/firmware | tar -C "${_ROOTFS}" -xpf - - _full_dir "/usr/share/licenses/linux-firmware" + tar -C / --exclude=lib/firmware/{amphion,"as102*",atusb,av7110,cadence,cavium,"cmmb*",cis,cpia2,cnm,"ct*","cxgb*","cmmb*",dabusb,dpaa2,dsp56k,"dvb*",edgeport,emi26,emi62,ess,"f2255usb*",go7007,"hfi1*",inside-secure,"isdbt*","keyspan*",korg,meson,"lgs8g75*","lt9611uxc*",moxa,"mts*","myri10ge*",myricom,nxp,ositech,"qat*",sb16,"s2250*","s5p-*","sms1*",rtl_bt,"tdmb*",ttusb-budget,ueagle-atm,"usbdux*",ti,ti-keystone,"v4l*",vicam,vxge,"whiteheat*",yam,yamaha,"*.txt*","*README*"} --hard-dereference -cpf - lib/firmware usr/share/licenses/linux-firmware | tar -C "${_ROOTFS}" -xpf - _all_mods "/firmware/" } diff --git a/usr/lib/archboot/cpio/hooks/net_cleanup b/usr/lib/archboot/cpio/hooks/net_cleanup index d6e5e3e8f..c496d9999 100644 --- a/usr/lib/archboot/cpio/hooks/net_cleanup +++ b/usr/lib/archboot/cpio/hooks/net_cleanup @@ -8,6 +8,7 @@ _run () _APPS="arping clockdiff tracepath ssh arpd \ genl ifstat ctstat rtstat lnstat nstat rtacct rtmon ss tc \ bridge dcb devlink rdma tipc vdpa ethtool elinks brctl" + _install_files for i in ${_APPS}; do rm /usr/bin/"${i}" done diff --git a/usr/lib/archboot/cpio/hooks/remote b/usr/lib/archboot/cpio/hooks/remote index a7977b6f8..fbd14b7b2 100644 --- a/usr/lib/archboot/cpio/hooks/remote +++ b/usr/lib/archboot/cpio/hooks/remote @@ -8,10 +8,11 @@ _run () exportfs nfsstat rpc.idmapd rpc.mountd rpc.nfsd rpc.statd rpcdebug showmount \ sm-notify start-statd rpc.gssd \ nfsdcltrack gssproxy screen tmux rsync ttyd - _map _file /etc/screenrc /etc/ssh/ssh_config /etc/ssh/sshd_config /etc/ssh/moduli \ + _map _file /etc/screenrc /etc/ssh/ssh_config /etc/ssh/moduli \ /etc/rsyncd.conf /etc/exports /usr/lib/ssh/sftp-server /usr/lib/ssh/ssh-keysign \ /usr/lib/ssh/ssh-pkcs11-helper \ /etc/netconfig + _file_rename /etc/ssh/sshd_config /etc/ssh/sshd_config # allow root login and empty passwords echo "PermitRootLogin yes" >> "${_ROOTFS}/etc/ssh/sshd_config" echo "PermitEmptyPasswords yes" >> "${_ROOTFS}/etc/ssh/sshd_config"