distribution/packages/sysutils/systemd/scripts/kernel-overlays-setup
fewtarius 4acb3fe902
* Continue to work on improving power consumption on battery.
* Update emulators and cores.
* Improve logging in some scripts.
2023-01-19 21:30:33 -05:00

85 lines
2.1 KiB
Bash
Executable file

#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2017-present Team LibreELEC (https://libreelec.tv)
SYSTEM_OVERLAYS_DIR=/usr/lib/kernel-overlays
OVERLAY_CONFIG_DIR=/storage/.cache/kernel-overlays
KVER=$(uname -r)
MODULES_DIR="/var/lib/modules/${KVER}"
FIRMWARE_DIR="/var/lib/firmware"
USER_FIRMWARE_DIR="/storage/.config/firmware"
mkdir -p "${MODULES_DIR}"
mkdir -p "${FIRMWARE_DIR}"
mkdir -p "${OVERLAY_CONFIG_DIR}"
log() {
echo "kernel-overlays-setup: $@" > /dev/kmsg
}
apply_overlay() {
case "$1" in
/*)
modules_overlay_dir="${1}/lib/modules/${KVER}"
firmware_overlay_dir="${1}/lib/firmware"
;;
*)
modules_overlay_dir="${SYSTEM_OVERLAYS_DIR}/${1}/lib/modules/${KVER}"
firmware_overlay_dir="${SYSTEM_OVERLAYS_DIR}/${1}/lib/firmware"
;;
esac
if [ -d "${modules_overlay_dir}" ] ; then
GOT_MODULE_OVERLAY="yes"
if cp -rfs "${modules_overlay_dir}"/* "${MODULES_DIR}" ; then
log $0 "added modules from $modules_overlay_dir"
else
log $0 "failed to add modules from $modules_overlay_dir"
fi
fi
if [ -d "${firmware_overlay_dir}" ] ; then
if cp -rfs "${firmware_overlay_dir}"/* "${FIRMWARE_DIR}" ; then
log $0 "added firmware from $firmware_overlay_dir"
else
log $0 "failed to add firmware from $firmware_overlay_dir"
fi
fi
}
# setup system base modules
log $0 "setup base modules"
apply_overlay base
# apply user-configured module overlays
if [ -d "${OVERLAY_CONFIG_DIR}" ] ; then
log $0 "adding overlays from ${OVERLAY_CONFIG_DIR}"
GOT_MODULE_OVERLAY="no"
for conf in "${OVERLAY_CONFIG_DIR}/"*.conf ; do
if [ -e "$conf" ] ; then
log $0 "processing conf $conf"
overlay=$(cat "$conf")
[ -n "$overlay" ] && apply_overlay "$overlay"
fi
done
if [ "yes" = "$GOT_MODULE_OVERLAY" ] ; then
log $0 "running depmod"
/usr/sbin/depmod -a
fi
fi
if [ -d "${USER_FIRMWARE_DIR}" ] && [ -n "$(ls ${USER_FIRMWARE_DIR})" ] ; then
if cp -rfs "${USER_FIRMWARE_DIR}"/* "${FIRMWARE_DIR}" ; then
log $0 "added firmware from ${USER_FIRMWARE_DIR}"
else
log $0 "failed to add firmware from ${USER_FIRMWARE_DIR}"
fi
fi
log $0 "done"