#!/usr/bin/env ash # # Copyright (C) 2023 AuxXxilium and Ing # # This is free software, licensed under the MIT License. # See /LICENSE for more information. # if [ "${1}" = "early" ]; then echo "Installing addon eudev - ${1}" tar -zxf /addons/eudev-7.1.tgz -C / [ ! -L "/usr/sbin/modprobe" ] && ln -vsf /usr/bin/kmod /usr/sbin/modprobe [ ! -L "/usr/sbin/modinfo" ] && ln -vsf /usr/bin/kmod /usr/sbin/modinfo [ ! -L "/usr/sbin/depmod" ] && ln -vsf /usr/bin/kmod /usr/sbin/depmod elif [ "${1}" = "modules" ]; then echo "Installing addon eudev - ${1}" # mv -f /usr/lib/udev/rules.d/60-persistent-storage.rules /usr/lib/udev/rules.d/60-persistent-storage.rules.bak # mv -f /usr/lib/udev/rules.d/60-persistent-storage-tape.rules /usr/lib/udev/rules.d/60-persistent-storage-tape.rules.bak # mv -f /usr/lib/udev/rules.d/80-net-name-slot.rules /usr/lib/udev/rules.d/80-net-name-slot.rules.bak [ -e /proc/sys/kernel/hotplug ] && printf '\000\000\000\000' >/proc/sys/kernel/hotplug /usr/sbin/depmod -a /usr/sbin/udevd -d || { echo "FAIL" exit 1 } echo "Triggering add events to udev" udevadm trigger --type=subsystems --action=add udevadm trigger --type=devices --action=add udevadm trigger --type=devices --action=change udevadm settle --timeout=30 || echo "udevadm settle failed" # Give more time sleep 10 # Remove from memory to not conflict with RAID mount scripts /usr/bin/killall udevd # modprobe pcspeaker, pcspkr /usr/sbin/modprobe pcspeaker /usr/sbin/modprobe pcspkr # Remove kvm module /usr/sbin/lsmod 2>/dev/null | grep -q ^kvm_intel && /usr/sbin/modprobe -r kvm_intel || true # kvm-intel.ko /usr/sbin/lsmod 2>/dev/null | grep -q ^kvm_amd && /usr/sbin/modprobe -r kvm_amd || true # kvm-amd.ko elif [ "${1}" = "late" ]; then echo "Installing addon eudev - ${1}" # [ ! -L "/tmpRoot/usr/sbin/modprobe" ] && ln -vsf /usr/bin/kmod /tmpRoot/usr/sbin/modprobe [ ! -L "/tmpRoot/usr/sbin/modinfo" ] && ln -vsf /usr/bin/kmod /tmpRoot/usr/sbin/modinfo [ ! -L "/tmpRoot/usr/sbin/depmod" ] && ln -vsf /usr/bin/kmod /tmpRoot/usr/sbin/depmod echo "copy modules" isChange="false" export LD_LIBRARY_PATH=/tmpRoot/bin:/tmpRoot/lib /tmpRoot/bin/cp -rnf /usr/lib/firmware/* /tmpRoot/usr/lib/firmware/ if cat /proc/version 2>/dev/null | grep -q 'RR@RR'; then if [ -d /tmpRoot/usr/lib/modules.bak ]; then /tmpRoot/bin/rm -rf /tmpRoot/usr/lib/modules /tmpRoot/bin/cp -rpf /tmpRoot/usr/lib/modules.bak /tmpRoot/usr/lib/modules else echo "Custom - backup modules." /tmpRoot/bin/cp -rpf /tmpRoot/usr/lib/modules /tmpRoot/usr/lib/modules.bak fi /tmpRoot/bin/cp -rpf /usr/lib/modules/* /tmpRoot/usr/lib/modules echo "true" >/tmp/modulesChange else if [ -d /tmpRoot/usr/lib/modules.bak ]; then echo "Custom - restore modules from backup." /tmpRoot/bin/rm -rf /tmpRoot/usr/lib/modules /tmpRoot/bin/mv -rf /tmpRoot/usr/lib/modules.bak /tmpRoot/usr/lib/modules fi cat /addons/modulelist 2>/dev/null | /tmpRoot/bin/sed '/^\s*$/d' | while IFS=' ' read -r O M; do [ "${O:0:1}" = "#" ] && continue [ -z "${M}" -o -z "$(ls /usr/lib/modules/${M} 2>/dev/null)" ] && continue if [ "$(echo "${O}" | /tmpRoot/bin/sed 's/.*/\U&/')" = "F" ]; then /tmpRoot/bin/cp -vrf /usr/lib/modules/${M} /tmpRoot/usr/lib/modules/ else /tmpRoot/bin/cp -vrn /usr/lib/modules/${M} /tmpRoot/usr/lib/modules/ fi # isChange="true" # In Bash, the pipe operator | creates a subshell to execute the commands in the pipe. # This means that if you modify a variable inside a while loop, # the modification is not visible outside the loop because the while loop is executed in a subshell. echo "true" >/tmp/modulesChange done fi isChange="$(cat /tmp/modulesChange 2>/dev/null || echo "false")" echo "isChange: ${isChange}" [ "${isChange}" = "true" ] && /usr/sbin/depmod -a -b /tmpRoot # Restore kvm module /usr/sbin/modprobe kvm_intel || true # kvm-intel.ko /usr/sbin/modprobe kvm_amd || true # kvm-amd.ko echo "Copy rules" /tmpRoot/bin/cp -vrf /usr/lib/udev/* /tmpRoot/usr/lib/udev/ mkdir -p "/tmpRoot/usr/lib/systemd/system" DEST="/tmpRoot/usr/lib/systemd/system/udevrules.service" { echo "[Unit]" echo "Description=Reload udev rules" echo echo "[Service]" echo "Type=oneshot" echo "RemainAfterExit=yes" echo "ExecStart=/usr/bin/udevadm hwdb --update" echo "ExecStart=/usr/bin/udevadm control --reload-rules" echo echo "[Install]" echo "WantedBy=multi-user.target" } >"${DEST}" mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants ln -vsf /usr/lib/systemd/system/udevrules.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/udevrules.service fi