diff options
Diffstat (limited to 'remote/includes')
| -rw-r--r-- | remote/includes/kernel.inc | 97 | ||||
| -rw-r--r-- | remote/includes/packagemanager.inc | 102 |
2 files changed, 135 insertions, 64 deletions
diff --git a/remote/includes/kernel.inc b/remote/includes/kernel.inc index 4eef36e5..a3c64d9a 100644 --- a/remote/includes/kernel.inc +++ b/remote/includes/kernel.inc @@ -16,36 +16,54 @@ # set global KERNEL_TARGET_NAME KERNEL_TARGET_NAME="kernel" +# set global KERNEL_BASE_DIR as in the directory containing lib/modules and lib/firmware +# for system kernel, that is "/" and for an openslx kernel KERNEL_BUILD_DIR +KERNEL_BASE_DIR="" + get_kernel_version () { # determine kernel version currently running on this machine - KERNEL_CURRENT_VERSION=$(uname -r) + [ -z "$KERNEL_CURRENT_VERSION" ] && declare -rg KERNEL_CURRENT_VERSION="$(uname -r)" [ -z "$KERNEL_CURRENT_VERSION" ] && pwarning "Could not determine kernel version." - # determine kernel version that will be running in the generated system - if [ -e "$MODULES_DIR/kernel/ksrc/include/generated/utsrelease.h" ]; then - SYS_UTS_RELEASE=$(grep 'UTS_RELEASE' "$MODULES_DIR/kernel/ksrc/include/generated/utsrelease.h" | awk -F '"' '{print $2}') - SYS_KERNEL=$(echo "$SYS_UTS_RELEASE" | grep -o -E '^[0-9\.]+') - else - SYS_UTS_RELEASE="(unknown-not-compiled-yet)" - SYS_KERNEL="$SYS_UTS_RELEASE" - fi + + # set empty SYS_UTS_RELEASE and SYS_KERNEL + SYS_UTS_RELEASE="(unknown)" + SYS_KERNEL="$(echo "$SYS_UTS_RELEASE" | grep -o -E '^[0-9\.]+')" } -check_kernel_build_dir() { +check_kernel_base_dir() { + + # check if KERNEL_BASE_DIR was set, if not we don't know + # whether kernel-openslx or kernel-system has been built + # and therefore not were to look for kernel modules, + # firmware and the kernel itself + + if [ -z "${KERNEL_BASE_DIR}" ]; then + # this is bad, abort + perror "KERNEL_BASE_DIR is not set. The kernel module did not run properly" + fi + # all good, keep going + + # old deprecated KERNEL_BUILD_DIR variable, here for compat reasons for now. TODO: delete [ -d "${MODULES_DIR}/kernel/build" ] && KERNEL_BUILD_DIR="${MODULES_DIR}/kernel/build" \ - || perror "No build directory set for the kernel. Was is built?" + || perror "No build directory set for the kernel. Was is built?" + # hack to get the real path of the installed modules - KERNEL_NEW_VERSION=$(ls ${KERNEL_BUILD_DIR}/lib/modules) + #KERNEL_NEW_VERSION=$(ls ${KERNEL_BUILD_DIR}/lib/modules) } copy_kernel_modules() { pinfo "Copying kernel modules for kernel ${KERNEL_CURRENT_VERSION}..." [ -z "${REQUIRED_KERNEL_MODULES}" ] && perror "REQUIRED_KERNEL_MODULES is empty. Check your config file." - check_kernel_build_dir + [ -z "${KERNEL_HEADERS_PATH}" ] && perror "KERNEL_HEADERS_PATH is empty. Kernel headers appears to be missing." + + + check_kernel_base_dir + # # process modules list # - # search for modules in KERNEL_BUILD_DIR - cd "${KERNEL_BUILD_DIR}" || perror "Could not cd to ${KERNEL_BUILD_DIR}" + # search for modules in KERNEL_BASE_DIR + cd "${KERNEL_BASE_DIR}" || perror "Could not cd to ${KERNEL_BASE_DIR}" local KERNEL_MODULES_DIR="lib/modules/${KERNEL_NEW_VERSION}" local KERNEL_MODULES_LIST="" @@ -62,12 +80,12 @@ copy_kernel_modules() { REQUIRED_KERNEL_MODULES_EXPANDED+=" $ELEM" done done - cd - + cd - 2>/dev/null pinfo "Expanded the list of $(echo "$REQUIRED_KERNEL_MODULES" | wc -w) required kernel modules to $(echo "$REQUIRED_KERNEL_MODULES_EXPANDED" | wc -w)" for KERNEL_MODULE in ${REQUIRED_KERNEL_MODULES_EXPANDED}; do local KERNEL_MODULE_PATH="${KERNEL_MODULES_DIR}/${KERNEL_MODULE}" - if grep "^${KERNEL_MODULE}$" "${KERNEL_BUILD_DIR}/${KERNEL_MODULES_DIR}/modules.builtin" >/dev/null; then + if grep "^${KERNEL_MODULE}$" "${KERNEL_BASE_DIR}/${KERNEL_MODULES_DIR}/modules.builtin" >/dev/null; then pdebug "Already built-in ${KERNEL_MODULE}." elif [ -e "${KERNEL_MODULE_PATH}" ]; then pdebug "Copying '${KERNEL_MODULE_PATH}'" @@ -78,7 +96,7 @@ copy_kernel_modules() { fi # check for dependencies - local DEPS=$(grep "${KERNEL_MODULE}:" "${KERNEL_BUILD_DIR}/${KERNEL_MODULES_DIR}/modules.dep" | cut -d ":" -f2-) + local DEPS=$(grep "${KERNEL_MODULE}:" "${KERNEL_BASE_DIR}/${KERNEL_MODULES_DIR}/modules.dep" | cut -d ":" -f2-) if [ ! -z "$DEPS" ]; then for DEP in $DEPS; do pdebug "Adding dep: ${KERNEL_MODULES_DIR}/$DEP" @@ -114,11 +132,13 @@ copy_firmware() { pinfo "Copying firmware for kernel ${KERNEL_CURRENT_VERSION}..." [ -z "${REQUIRED_FIRMWARE}" ] && perror "REQUIRED_FIRMWARE is empty. Check your config file." local OLD_DIR=$(pwd) - check_kernel_build_dir + + check_kernel_base_dir + # # process firmware list # - cd "${KERNEL_BUILD_DIR}" || perror "Could not cd!" + cd "${KERNEL_BASE_DIR}" || perror "Could not cd to ${KERNEL_BASE_DIR}" local FIRMWARE_DIR="lib/firmware" local FIRMWARE_LIST="" for FIRMWARE in ${REQUIRED_FIRMWARE}; do @@ -126,14 +146,21 @@ copy_firmware() { # check for firmware in the build directory of the kernel for CANDIDATE in "${FIRMWARE_DIR}/${FIRMWARE}" "${FIRMWARE_DIR}/${KERNEL_NEW_VERSION}/${FIRMWARE}"; do if [ -e "${CANDIDATE}" ]; then - pdebug "Copying from kernel build dir: '${CANDIDATE}'" + pdebug "Copying from kernel base dir ('$KERNEL_BASE_DIR'): '${CANDIDATE}'" FIRMWARE_LIST+=" ${CANDIDATE}" FOUND=1 fi done - + + # dont look under / if KERNEL_BASE_DIR is already / + if [ "x${KERNEL_BASE_DIR}" == "x/" ]; then + [ $FOUND -ne 1 ] && pwarning "Neither '${FIRMWARE_DIR}/${FIRMWARE}' nor '${FIRMWARE_DIR}/${KERNEL_NEW_VERSION}/${FIRMWARE}' found on the system" + continue + fi + # if we didn't found it in the kernel build directory, check for firmware in the system firmware directory if [ $FOUND -ne 1 ]; then + pdebug "Did not found '$FIRMWARE' in kernel base dir. Searching system..." for CANDIDATE in "/${FIRMWARE_DIR}/${FIRMWARE}" "/${FIRMWARE_DIR}/${KERNEL_CURRENT_VERSION}/${FIRMWARE}"; do if [ -e "${CANDIDATE}" ]; then if [ $(echo "${CANDIDATE}" | grep -c "${KERNEL_CURRENT_VERSION}") -eq 0 ]; then @@ -153,33 +180,37 @@ copy_firmware() { done if [ ! -z "${FIRMWARE_LIST}" ]; then + echo "$FIRMWARE_LIST" > /fwlist local COUNT=$(echo "${FIRMWARE_LIST}" | wc -w) pinfo "Copying $COUNT firmware to target directory." tarcopy "${FIRMWARE_LIST}" "${TARGET_BUILD_DIR}" fi + # only for kernel-openslx # post-process to fix the path of the firmwares found on the system unter /lib/firmware/$(uname -r) # which have to be copied to /lib/firmware/${KERNEL_NEW_VERSION} - if [ -d "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" ]; then - mkdir -p "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_NEW_VERSION}/" - cd "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" || perror "old kernel but no old kernel" - tarcopy "$(ls)" "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_NEW_VERSION}/" - cd - - rm -r "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" || perror "something went very wrong..." - else - pdebug "No ${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION} directory, skipping the merge." + if [ "x${KERNEL_BASE_DIR}" != "x/" ]; then + if [ -d "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" ]; then + mkdir -p "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_NEW_VERSION}/" + cd "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" || perror "old kernel but no old kernel" + tarcopy "$(ls)" "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_NEW_VERSION}/" + cd - + rm -r "${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION}" || perror "something went very wrong..." + else + pdebug "No ${TARGET_BUILD_DIR}/lib/firmware/${KERNEL_CURRENT_VERSION} directory, skipping the merge." + fi fi - + cd "$OLD_DIR" } copy_kernel() { - check_kernel_build_dir + check_kernel_base_dir local TOOL_STR="$TOOL_STR copy_kernel:" local KERNEL_DIR="${MODE_DIR}/builds/kernel" pinfo "Copying '${KERNEL_TARGET_NAME}' to '${KERNEL_DIR}'." [ -d "${KERNEL_DIR}" ] || mkdir -p "${KERNEL_DIR}" - cp "${KERNEL_BUILD_DIR}/${KERNEL_TARGET_NAME}" "${KERNEL_DIR}" || perror "Could not copy kernel!" + cp "${KERNEL_BASE_DIR}/${KERNEL_TARGET_NAME}" "${KERNEL_DIR}" || perror "Could not copy kernel!" pinfo "You may want to update your systems firmware/modules to match the current kernel." } diff --git a/remote/includes/packagemanager.inc b/remote/includes/packagemanager.inc index 358dd8b1..66013807 100644 --- a/remote/includes/packagemanager.inc +++ b/remote/includes/packagemanager.inc @@ -1,44 +1,84 @@ # # get all files of required packages by a module # -list_packet_files() { +# Usage: +# list_content_packages +# - lists all files/directories in REQUIRED_CONTENT_PACKAGES +# list_content_packages --files +# - lists all files in REQUIRED_CONTENT_PACKAGES +# list_content_packages --dirs +# - lists all dirs in REQUIRED_CONTENT_PACKAGES +# +# NOTE: additional packages needed to be listed can be given +# through the environment variable EXTRA_PACKAGES + +list_content_packages() { [ -z "$REQUIRED_CONTENT_PACKAGES" ] && pinfo "No required packages for $TOOL" && return 1 + [ $# -gt 2 ] && perror "'list_content_packages' accepts only 1 or no args. $# given." local PACKAGE="" - for PACKAGE in $REQUIRED_CONTENT_PACKAGES; do - local OPTIONAL="$(echo "$PACKAGE" | cut -c 1)" - [ "x$OPTIONAL" = "x@" ] && PACKAGE="$(echo "$PACKAGE" | cut -c 2-)" - local FILES="" - if [ "$PACKET_HANDLER" = "dpkg" ]; then - PACKAGECOMMAND="dpkg -L" - elif [ "$PACKET_HANDLER" = "rpm" ]; then - PACKAGECOMMAND="rpm -ql" - fi + for PACKAGE in $REQUIRED_CONTENT_PACKAGES $EXTRA_PACKAGES; do + list_content_package $1 $PACKAGE + done - if [ -n "$REQUIRED_PACKET_FILES_BLACKLIST" ]; then - FILES="$($PACKAGECOMMAND "$PACKAGE" | grep "^/" | \ - grep -v "$REQUIRED_PACKET_FILES_BLACKLIST" | \ - grep -v -E 'share/(man|doc)|/var/run|/var/log|/etc/init\.d'; \ - echo ":###:${PIPESTATUS[0]}")" - else - FILES="$($PACKAGECOMMAND "$PACKAGE" | grep "^/" | grep -v -E 'share/(man|doc)|/var/run|/var/log|/etc/init\.d'; echo ":###:${PIPESTATUS[0]}")" - fi +} +list_content_package(){ + #[ -z "$EXTRA_PACKAGES" ] || pinfo "Listing additional packages: $EXTRA_PACKAGES" + [ $# -gt 2 ] && perror "'list_content_package' accepts max 2 args. $# given." + local OP="-e" + case "$1" in + --files) + OP="-f" + ;; + --dirs) + OP="-d" + ;; + "") + OP="-e" + ;; + *) + perror "'list_content_packages' invalid argument: $1" + ;; + esac + local PACKAGE="$2" + local OPTIONAL="$(echo "$PACKAGE" | cut -c 1)" + [ "x$OPTIONAL" = "x@" ] && PACKAGE="$(echo "$PACKAGE" | cut -c 2-)" + local FILES="" + if [ "$PACKET_HANDLER" = "dpkg" ]; then + PACKAGECOMMAND="dpkg -L" + elif [ "$PACKET_HANDLER" = "rpm" ]; then + PACKAGECOMMAND="rpm -ql" + fi + + if [ -n "$REQUIRED_PACKET_FILES_BLACKLIST" ]; then + FILES="$($PACKAGECOMMAND "$PACKAGE" | grep "^/" | \ + grep -v "$REQUIRED_PACKET_FILES_BLACKLIST" | \ + grep -v -E 'share/(man|doc)|/var/run|/var/log|/etc/init\.d'; \ + echo ":###:${PIPESTATUS[0]}")" + else + FILES="$($PACKAGECOMMAND "$PACKAGE" | grep "^/" | grep -v -E 'share/(man|doc)|/var/run|/var/log|/etc/init\.d'; echo ":###:${PIPESTATUS[0]}")" + fi # FILES="$(rpm -ql "$PACKAGE" | grep "^/" | grep -v -E 'share/(man|doc)|/var/run|/var/log'; echo ":###:${PIPESTATUS[0]}")" - # ugly hack to get our return value - local LPRET=$(echo "$FILES" | awk -F ':###:' '{printf $2}') - FILES=$(echo "$FILES" | awk -F ':###:' '{print $1}') - if [ "x$LPRET" != "x0" -a "x$OPTIONAL" != "x@" ]; then - pdebug "FILES: '$FILES'" - perror "dpkg/rpm exited with code '$LPRET' for required package ${PACKAGE}." - fi - [ "x$LPRET" != "x0" ] && pwarning "dpkg/rpm exited with code '$LPRET' for optional package ${PACKAGE}." && continue - [ -z "$FILES" ] && pwarning "list_packet_files empty for packet ${PACKAGE}." && continue - pdebug "Packet $PACKAGE has $(echo $FILES | wc -w) files..." - for FILE in $FILES; do - [ ! -d "$FILE" ] && echo "$FILE" - done + # ugly hack to get our return value + local LPRET=$(echo "$FILES" | awk -F ':###:' '{printf $2}') + FILES=$(echo "$FILES" | awk -F ':###:' '{print $1}') + if [ "x$LPRET" != "x0" -a "x$OPTIONAL" != "x@" ]; then + pdebug "FILES: '$FILES'" + perror "dpkg/rpm exited with code '$LPRET' for required package ${PACKAGE}." + fi + [ "x$LPRET" != "x0" ] && pwarning "dpkg/rpm exited with code '$LPRET' for optional package ${PACKAGE}." && continue + [ -z "$FILES" ] && pwarning "list_packet_files empty for packet ${PACKAGE}." && continue + pdebug "Packet $PACKAGE has $(echo $FILES | wc -w) files..." + for FILE in $FILES; do + [ "$OP" "$FILE" ] && echo "$FILE" done } +# +# Convenience function +# +list_packet_files() { + list_content_packages --files +} # # Convenience function |
