From c61c35397320ca4b36d25ea9b9b146d40e84c387 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 15 Mar 2013 18:07:22 +0100 Subject: fix stage3.1 build script --- mltk | 11 +- remote/rootfs/rootfs-stage31/rootfs-stage31.build | 50 ++-- remote/rootfs/rootfs-stage31/rootfs-stage31.conf | 109 ++++----- remote/setup_core | 219 ------------------ remote/setup_target | 261 +++++++++++++++++++++ remote/setup_tools | 266 ---------------------- 6 files changed, 336 insertions(+), 580 deletions(-) delete mode 100755 remote/setup_core create mode 100755 remote/setup_target delete mode 100755 remote/setup_tools diff --git a/mltk b/mltk index 7e6945c3..ac79798e 100755 --- a/mltk +++ b/mltk @@ -90,11 +90,8 @@ initial_checks() { pinfo "System's packet manager is $PACKET_MANAGER" # setup_tools and build_core - SETUP_CORE="${ROOT_DIR}/remote/setup_core" - SETUP_TOOLS="${ROOT_DIR}/remote/setup_tools" - - [ ! -e "${SETUP_CORE}" ] && perror "Missing script setup_core, re-clone. Exiting." - [ ! -e "${SETUP_TOOLS}" ] && perror "Missing script setup_tools, re-clone. Exiting." + SETUP_TARGET="${ROOT_DIR}/remote/setup_target" + [ ! -e "${SETUP_TARGET}" ] && perror "Missing script 'remote/setup_target', re-clone git. Exiting." } read_params() { @@ -182,8 +179,8 @@ read_params() { run() { if [[ $REMOTE_CLEAN == 1 || $REMOTE_BUILD == 1 ]]; then [[ $REMOTE_DEBUG == 1 ]] && unset_quiet || set_quiet - . "${SETUP_TOOLS}" || perror "Cannot source ${SETUP_TOOLS}" - [[ $REMOTE_CLEAN == 1 ]] && clean_tools $REMOTE_LIST_CLEAN + . "${SETUP_TARGET}" || perror "Cannot source ${SETUP_TARGET}" + [[ $REMOTE_CLEAN == 1 ]] && clean_modules $REMOTE_LIST_CLEAN [[ $REMOTE_BUILD == 1 ]] && generate_target $REMOTE_LIST_BUILD fi if [[ $SERVER_CLEAN == 1 || $SERVER_BUILD == 1 ]]; then diff --git a/remote/rootfs/rootfs-stage31/rootfs-stage31.build b/remote/rootfs/rootfs-stage31/rootfs-stage31.build index d0a95238..e5e45312 100644 --- a/remote/rootfs/rootfs-stage31/rootfs-stage31.build +++ b/remote/rootfs/rootfs-stage31/rootfs-stage31.build @@ -4,40 +4,18 @@ fetch_source() { } build() { - - BUILDDIR="${TARGET_DIR}/${MODULE}/build" - - FILELIST="list_binaries_and_files" - [ -e "${FILELIST}" ] && rm "${FILELIST}" - - for BIN in ${REQUIRED_BINARIES} - do + COPYLIST="list_binaries_and_files" + [ -e $COPYLIST ] && rm -f $COPYLIST + for BIN in $REQUIRED_BINARIES; do BIN_LOCATION=$(which ${BIN}) - if [ ! -z ${BIN_LOCATION} -a -e ${BIN_LOCATION} ]; - then - pdebug "Processing $BIN at $BIN_LOCATION ..." - get_link_chain ${BIN_LOCATION} >> "${FILELIST}" - else - perror "${BIN} not found on the system! Please install it." - fi + [ ! -z "${BIN_LOCATION}" -a -e "${BIN_LOCATION}" ] \ + && get_link_chain "${BIN_LOCATION}" >> "${COPYLIST}" done - - for FILE in ${REQUIRED_DIRECTORIES} - do - [ ! -d ${FILE} ] && perror "Missing required directory $FILE" - echo ${FILE} >> "${FILELIST}" - done - for FILE in ${REQUIRED_FILES} - do - [ ! -f ${FILE} ] && perror "Missing required file $FILE" - echo ${FILE} >> "${FILELIST}" + for FILE in $REQUIRED_FILES; do + get_link_chain "${FILE}" >> "${COPYLIST}" done - local NUMFILES=$(cat "${FILELIST}" | wc -l) - if [ "x$NUMFILES" != "x" -a "x$NUMFILES" != "x0" ]; then - pinfo "File list generated at ${BUILDDIR}/${FILELIST} ($NUMFILES entries)" - tarcopy "$(cat "${FILELIST}")" "${BUILDDIR}" - fi + tarcopy "$(cat $COPYLIST|sort -u)" "${MODULE_BUILD_DIR}" } post_copy() { @@ -47,6 +25,9 @@ post_copy() { copy_firmware } +# +# helper functions to generate the base rootfs +# generate_rootfs() { # create basic directory structure mkdir -p "${TARGET_BUILD_DIR}"/{bin,dev,proc,run,etc,mnt,sys} \ @@ -63,7 +44,7 @@ generate_rootfs() { tarcopy "${REQUIRED_FILES}" "${TARGET_BUILD_DIR}" # copy static data - cp -r "${MODULE_DIR}"/core/data/* "${TARGET_BUILD_DIR}" + cp -r "${MODULE_DIR}"/data/* "${TARGET_BUILD_DIR}" } copy_kernel_modules() { @@ -72,7 +53,7 @@ copy_kernel_modules() { [ -e $MODLIST ] && rm -f $MODLIST # process modules list - for MOD in ${REQUIRED_MODULES}; do + for MOD in ${REQUIRED_KERNEL_MODULES}; do local MOD_PATH="/lib/modules/${KERNEL_VERSION}/${MOD}" if [ ! -e "${MOD_PATH}" ]; then pwarning "Module $MOD not found. Skipping. (might cause problem on certain clients!)" @@ -88,13 +69,13 @@ copy_kernel_modules() { pinfo "Copying $MODLISTCOUNT modules to stage 3.1 target directory." tarcopy "$(cat "$MODLIST")" "${TARGET_BUILD_DIR}" fi - + rm -rf $MODLIST } generate_modules_map_files() { # first strip modules.order of all the modules we don't use - cat /lib/modules/"${KERNEL_VERSION}"/modules.order | grep -E $(echo ${REQUIRED_MODULES} | tr '\ ' '|') \ + cat /lib/modules/"${KERNEL_VERSION}"/modules.order | grep -E $(echo ${REQUIRED_KERNEL_MODULES} | tr '\ ' '|') \ >> "${TARGET_BUILD_DIR}"/lib/modules/"${KERNEL_VERSION}"/modules.order # copy list of builtin kernel modules @@ -131,4 +112,5 @@ copy_firmware() { pinfo "Copying $FWLISTCOUNT firmware to stage 3.1 target directory." tarcopy "$(cat "$FWLIST")" "${TARGET_BUILD_DIR}" fi + rm -f $FWLIST } diff --git a/remote/rootfs/rootfs-stage31/rootfs-stage31.conf b/remote/rootfs/rootfs-stage31/rootfs-stage31.conf index 4015e4a3..ea9fd580 100644 --- a/remote/rootfs/rootfs-stage31/rootfs-stage31.conf +++ b/remote/rootfs/rootfs-stage31/rootfs-stage31.conf @@ -1,57 +1,58 @@ -REQUIRED_MODULES=" kernel/drivers/video/sis/sisfb.ko - kernel/drivers/video/via/viafb.ko - kernel/drivers/video/uvesafb.ko - kernel/drivers/acpi/video.ko - kernel/drivers/ssb/ssb.ko - kernel/drivers/gpu/drm/ttm/ttm.ko - kernel/drivers/gpu/drm/via/via.ko - kernel/drivers/gpu/drm/drm.ko - kernel/drivers/gpu/drm/tdfx/tdfx.ko - kernel/drivers/gpu/drm/nouveau/nouveau.ko - kernel/drivers/gpu/drm/savage/savage.ko - kernel/drivers/gpu/drm/radeon/radeon.ko - kernel/drivers/gpu/drm/drm_kms_helper.ko - kernel/drivers/gpu/drm/i810/i810.ko - kernel/drivers/gpu/drm/i2c/ch7006.ko - kernel/drivers/gpu/drm/i2c/sil164.ko - kernel/drivers/gpu/drm/sis/sis.ko - kernel/drivers/gpu/drm/mga/mga.ko - kernel/drivers/gpu/drm/i915/i915.ko - kernel/drivers/gpu/drm/r128/r128.ko - kernel/drivers/gpu/drm/vmwgfx/vmwgfx.ko - kernel/drivers/i2c/algos/i2c-algo-bit.ko - kernel/drivers/net/netconsole.ko - kernel/drivers/net/ethernet/realtek/8139too.ko - kernel/drivers/net/ethernet/realtek/r8169.ko - kernel/drivers/net/ethernet/nvidia/forcedeth.ko - kernel/drivers/net/ethernet/via/via-rhine.ko - kernel/drivers/net/ethernet/amd/pcnet32.ko - kernel/drivers/net/ethernet/atheros/atl1e/atl1e.ko - kernel/drivers/net/ethernet/atheros/atl1c/atl1c.ko - kernel/drivers/net/ethernet/sis/sis900.ko - kernel/drivers/net/ethernet/broadcom/tg3.ko - kernel/drivers/net/ethernet/broadcom/b44.ko - kernel/drivers/net/ethernet/intel/e1000/e1000.ko - kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko - kernel/drivers/net/ethernet/intel/e100.ko - kernel/drivers/net/ethernet/marvell/skge.ko - kernel/drivers/net/ethernet/3com/3c59x.ko - kernel/drivers/net/ethernet/dec/tulip/tulip.ko - kernel/drivers/hid/hid.ko - kernel/drivers/hid/usbhid/usbhid.ko - kernel/drivers/platform/x86/wmi.ko - kernel/drivers/platform/x86/mxm-wmi.ko - kernel/fs/configfs/configfs.ko - kernel/fs/nfs_common/nfs_acl.ko - kernel/fs/nfs/nfs.ko - kernel/fs/fscache/fscache.ko - kernel/fs/lockd/lockd.ko - kernel/fs/squashfs/squashfs.ko - kernel/net/sunrpc/sunrpc.ko - kernel/net/sunrpc/auth_gss/auth_rpcgss.ko - kernel/net/802/stp.ko - kernel/net/bridge/bridge.ko - kernel/ubuntu/aufs/aufs.ko" +REQUIRED_BINARIES=" v86d" +REQUIRED_KERNEL_MODULES=" kernel/drivers/video/sis/sisfb.ko + kernel/drivers/video/via/viafb.ko + kernel/drivers/video/uvesafb.ko + kernel/drivers/acpi/video.ko + kernel/drivers/ssb/ssb.ko + kernel/drivers/gpu/drm/ttm/ttm.ko + kernel/drivers/gpu/drm/via/via.ko + kernel/drivers/gpu/drm/drm.ko + kernel/drivers/gpu/drm/tdfx/tdfx.ko + kernel/drivers/gpu/drm/nouveau/nouveau.ko + kernel/drivers/gpu/drm/savage/savage.ko + kernel/drivers/gpu/drm/radeon/radeon.ko + kernel/drivers/gpu/drm/drm_kms_helper.ko + kernel/drivers/gpu/drm/i810/i810.ko + kernel/drivers/gpu/drm/i2c/ch7006.ko + kernel/drivers/gpu/drm/i2c/sil164.ko + kernel/drivers/gpu/drm/sis/sis.ko + kernel/drivers/gpu/drm/mga/mga.ko + kernel/drivers/gpu/drm/i915/i915.ko + kernel/drivers/gpu/drm/r128/r128.ko + kernel/drivers/gpu/drm/vmwgfx/vmwgfx.ko + kernel/drivers/i2c/algos/i2c-algo-bit.ko + kernel/drivers/net/netconsole.ko + kernel/drivers/net/ethernet/realtek/8139too.ko + kernel/drivers/net/ethernet/realtek/r8169.ko + kernel/drivers/net/ethernet/nvidia/forcedeth.ko + kernel/drivers/net/ethernet/via/via-rhine.ko + kernel/drivers/net/ethernet/amd/pcnet32.ko + kernel/drivers/net/ethernet/atheros/atl1e/atl1e.ko + kernel/drivers/net/ethernet/atheros/atl1c/atl1c.ko + kernel/drivers/net/ethernet/sis/sis900.ko + kernel/drivers/net/ethernet/broadcom/tg3.ko + kernel/drivers/net/ethernet/broadcom/b44.ko + kernel/drivers/net/ethernet/intel/e1000/e1000.ko + kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko + kernel/drivers/net/ethernet/intel/e100.ko + kernel/drivers/net/ethernet/marvell/skge.ko + kernel/drivers/net/ethernet/3com/3c59x.ko + kernel/drivers/net/ethernet/dec/tulip/tulip.ko + kernel/drivers/hid/hid.ko + kernel/drivers/hid/usbhid/usbhid.ko + kernel/drivers/platform/x86/wmi.ko + kernel/drivers/platform/x86/mxm-wmi.ko + kernel/fs/configfs/configfs.ko + kernel/fs/nfs_common/nfs_acl.ko + kernel/fs/nfs/nfs.ko + kernel/fs/fscache/fscache.ko + kernel/fs/lockd/lockd.ko + kernel/fs/squashfs/squashfs.ko + kernel/net/sunrpc/sunrpc.ko + kernel/net/sunrpc/auth_gss/auth_rpcgss.ko + kernel/net/802/stp.ko + kernel/net/bridge/bridge.ko + kernel/ubuntu/aufs/aufs.ko" REQUIRED_FIRMWARE=" 3com/ e100/ matrox/ diff --git a/remote/setup_core b/remote/setup_core deleted file mode 100755 index 31854db6..00000000 --- a/remote/setup_core +++ /dev/null @@ -1,219 +0,0 @@ -#!/bin/bash -# ----------------------------------------------------------------------------- -# -# Copyright (c) 2013 - OpenSLX GmbH -# -# This program is free software distributed under the GPL version 2. -# See http://openslx.org/COPYING -# -# If you have any feedback please consult http://openslx.org/feedback and -# send your suggestions, praise, or complaints to feedback@openslx.org -# -# General information about OpenSLX can be found at http://openslx.org/ -# ----------------------------------------------------------------------------- -# -# -# Script to create the stage3.1 root file system: -# - generate the rootfs directory structure and copy system devices -# - copies kernel modules and firmware as given in the config -# file (core/core.conf) to be able to load NIC/GFX modules early. -# - compile and include following tools: 'busybox' and 'hwinfo' -# - -MODULE_DIR="${ROOT_DIR}/remote" -STAGE31_DIR="${MODULE_DIR}/stage3.1" - -initial_checks() { - - [ ! -z "${KERNEL_VERSION}" ] || perror "No kernel version, cannot proceed." - [ ! -z "${ARCH_TRIPLET}" ] || perror "No arch triplet, cannot proceed." - - [ -d "${STAGE31_DIR}" ] || mkdir -p "${STAGE31_DIR}" - [ ! -z "$(which depmod)" ] || perror "No 'depmod' found on this systemd." - - [ -d "${MODULE_DIR}"/tools/busybox/build ] \ - || perror "No busybox found, build it with './mltk tools -b busybox'" -} - -read_config() { - local CORE_CONFIG="${MODULE_DIR}/core/core.conf" - [ ! -e "${CORE_CONFIG}" ] && perror "${MODULE_DIR}/core/core.conf not found." - . "${CORE_CONFIG}" || perror "Sourcing "${MODULE_DIR}"/core/core.conf failed." -} - -generate_rootfs() { - # create basic directory structure - mkdir -p "${STAGE31_DIR}"/{bin,dev,proc,run,etc,mnt,sys} \ - || perror "Cannot create basic directory structure in '${STAGE31_DIR}'" - - # copy device files from running system - cp -a /dev/{console,kmsg,mem,null,tty,tty0,tty1,tty9,urandom,zero} \ - "${STAGE31_DIR}"/dev || perror "Cannot copy devices from running system" - - # copy libc and ld-linux - tarcopy "$(list_basic_libs)" "${STAGE31_DIR}" - - # copy required files - tarcopy "${REQUIRED_FILES}" "${STAGE31_DIR}" - - # copy static data - cp -r "${MODULE_DIR}"/core/data/* "${STAGE31_DIR}" -} - -copy_kernel_modules() { - - local MODLIST="stage31_modules_list" - [ -e $MODLIST ] && rm -f $MODLIST - - # process modules list - for MOD in ${REQUIRED_MODULES}; do - local MOD_PATH="/lib/modules/${KERNEL_VERSION}/${MOD}" - if [ ! -e "${MOD_PATH}" ]; then - pwarning "Module $MOD not found. Skipping. (might cause problem on certain clients!)" - continue - else - pdebug "Copying "${MOD_PATH}"" - echo "${MOD_PATH}" >> "${MODLIST}" - fi - done - - if [ -s "$MODLIST" ]; then - local MODLISTCOUNT=$(cat "$MODLIST" | wc -l) - pinfo "Copying $MODLISTCOUNT modules to stage 3.1 target directory." - tarcopy "$(cat "$MODLIST")" "${STAGE31_DIR}" - fi - -} - -generate_modules_map_files() { - - # first strip modules.order of all the modules we don't use - cat /lib/modules/"${KERNEL_VERSION}"/modules.order | grep -E $(echo ${REQUIRED_MODULES} | tr '\ ' '|') \ - >> "${STAGE31_DIR}"/lib/modules/"${KERNEL_VERSION}"/modules.order - - # copy list of builtin kernel modules - cp /lib/modules/"${KERNEL_VERSION}"/modules.builtin "${STAGE31_DIR}"/lib/modules/"${KERNEL_VERSION}" - # with modules.order and modules.builtin, we can run depmod for the rest of the files - depmod -b "${STAGE31_DIR}" -} - -copy_firmware() { - - local FWLIST="stage31_firmware_list" - [ -e $FWLIST ] && rm -f $FWLIST - - local FW_PATH="/lib/firmware" - - # process firmware list - for FW in ${REQUIRED_FIRMWARE}; do - local FOUND=0 - if [ -e "${FW_PATH}"/"${FW}" ]; then - pdebug "Copying "${FW_PATH}"/"${FW}"" - echo "${FW_PATH}"/"${FW}" >> "$FWLIST" - FOUND=1 - fi - if [ -e "${FW_PATH}"/"${KERNEL_VERSION}"/"${FW}" ]; then - pdebug "Copying "${FW_PATH}"/"${KERNEL_VERSION}"/"${FW}"" - echo "${FW_PATH}"/"${KERNEL_VERSION}"/"${FW}" >> "$FWLIST" - FOUND=1 - fi - [ $FOUND -ne 1 ] && pwarning "Neither "${FW_PATH}"/"${FW}" nor "${FW_PATH}"/"${KERNEL_VERSION}"/"${FW}" found on the system." - done - - if [ -s "${FWLIST}" ]; then - local FWLISTCOUNT=$(cat "$FWLIST"|wc -l) - pinfo "Copying $FWLISTCOUNT firmware to stage 3.1 target directory." - tarcopy "$(cat "$FWLIST")" "${STAGE31_DIR}" - fi -} - - -install_basic_tools() { - # get busybox from tools/ we checked earlier if its there. - pinfo "Copying busybox to ${STAGE31_DIR}." - cp -r "${MODULE_DIR}"/tools/busybox/build/openslx/* "${STAGE31_DIR}" - - # install plymouth - pinfo "Copying plymouth to ${STAGE31_DIR}." - rm -f list.ply - cd "${MODULE_DIR}"/tools/plymouth/build - echo ./bin/plymouth >> list.ply - echo ./sbin/plymouthd >> list.ply - get_dynamic_dependencies -l "${MODULE_DIR}"/tools/plymouth/build ./bin/plymouth >> list.ply - get_dynamic_dependencies -l "${MODULE_DIR}"/tools/plymouth/build ./sbin/plymouthd >> list.ply - for i in $(find lib/plymouth -name \*.so); do - get_link_chain "${MODULE_DIR}"/tools/plymouth/build/"$i" "${MODULE_DIR}"/tools/plymouth/build >> list.ply - get_dynamic_dependencies -l "${MODULE_DIR}"/tools/plymouth/build $i >> list.ply - done - tarcopy "$(cat list.ply | sort -u)" "${STAGE31_DIR}" - cd - &> /dev/null - cp -r "${MODULE_DIR}"/tools/plymouth/data/* "${STAGE31_DIR}" - - # copy debugging tools - STRACE=$(which strace) - [ "x${STRACE}" != "x" ] && tarcopy "$(get_link_chain ${STRACE})" "${STAGE31_DIR}" - - LDD=$(which ldd) - [ "x${LDD}" != "x" ] && tarcopy "$(get_link_chain ${LDD})" "${STAGE31_DIR}" - - # get hwinfo and the required libx86emu - [ ! -d "${MODULE_DIR}"/core/src ] && mkdir -p "${MODULE_DIR}"/core/src - cd "${MODULE_DIR}"/core/src - - # start with libx86emu - pinfo "Cloning 'git://gitorious.org/x86emu/libx86emu.git'..." - git clone git://gitorious.org/x86emu/libx86emu.git - cd libx86emu - pinfo "Compiling 'libx86emu'..." - make || perror "libx86emu: make failed." - pinfo "Installing 'libx86emu' in ${MODULE_DIR}/core/build" - DESTDIR="${MODULE_DIR}"/core/build make install || perror "libx86emu: make install to "${STAGE31_DIR}" failed." - cd - &> /dev/null - - # now hwinfo - pinfo "Cloning 'git://gitorious.org/opensuse/hwinfo.git'..." - git clone git://gitorious.org/opensuse/hwinfo.git - cd hwinfo - pinfo "Compiling 'hwinfo'..." - make || perror "hwinfo: make failed." - pinfo "Installing 'hwinfo' in ${MODULE_DIR}/core/build" - DESTDIR="${MODULE_DIR}"/core/build make install || perror "hwinfo: make install failed." - cd - &> /dev/null - - # get dependencies of hwinfo - cd "${MODULE_DIR}"/core/build - HWINFO=$(find . -type f -name hwinfo -executable) - get_link_chain "${MODULE_DIR}"/core/build/"${HWINFO}" "${MODULE_DIR}"/core/build >> list_wanted_stage3.1 - get_dynamic_dependencies -l "${MODULE_DIR}"/core/build "${MODULE_DIR}"/core/build/"${HWINFO}" >> list_wanted_stage3.1 - tarcopy "$(cat list_wanted_stage3.1)" "${STAGE31_DIR}" - cd - &> /dev/null -} - -generate_stage31() { - - local TOOL_STR="[core]" - - pinfo "Generating stage 3.1 file system..." - cd "${MODULE_DIR}"/core - initial_checks - read_config - generate_rootfs - copy_kernel_modules - generate_modules_map_files - copy_firmware - install_basic_tools - cd - &> /dev/null -} - -clean_core() { - pinfo "Cleaning '${STAGE31_DIR}'..." - [ -d ${STAGE31_DIR} ] && { rm -rf ${STAGE31_DIR} || perror "rm -rf failed."; } - pinfo "Cleaning '${MODULE_DIR}/core'..." - [ -e ${MODULE_DIR}/core/stage31_modules_list ] && { rm -f ${MODULE_DIR}/core/stage31_modules_list || perror "rm -f failed."; } - [ -e ${MODULE_DIR}/core/stage31_firmware_list ] && { rm -f ${MODULE_DIR}/core/stage31_firmware_list || perror "rm -f failed."; } - pinfo "Cleaning '${MODULE_DIR}/core/build'..." - [ -e ${MODULE_DIR}/core/build ] && { rm -rf ${MODULE_DIR}/core/build || perror "rm -rf failed."; } - pinfo "Cleaning '${MODULE_DIR}/core/src'..." - [ -e ${MODULE_DIR}/core/src ] && { rm -rf ${MODULE_DIR}/core/src || perror "rm -rf failed."; } - -} diff --git a/remote/setup_target b/remote/setup_target new file mode 100755 index 00000000..c1a45787 --- /dev/null +++ b/remote/setup_target @@ -0,0 +1,261 @@ +#!/bin/bash + +MODE_DIR="${ROOT_DIR}/remote" +MODULES_DIR="${MODE_DIR}/modules" + +# check for target directory +TARGET_DIR="${MODE_DIR}/targets/${TARGET}" +[ -d $TARGET_DIR ] || perror "Given target directory does not exist: $TARGET" +TARGET_BUILD_DIR="${MODE_DIR}/builds/${TARGET}" + +# Keep track of processed modules +PROCESSED_MODULES="" + +initial_checks () { + # check for required tools + for BIN in git locate depmod + do + local TEST=$(which ${BIN}) + [ -z "$TEST" ] && pinfo "Installing $BIN..." && apt-get install $BIN + done +} + + +read_config () { + unset REQUIRED_BINARIES + unset REQUIRED_LIBRARIES + unset REQUIRED_DIRECTORIES + unset REQUIRED_FILES + unset REQUIRED_MODULES + unset REQUIRED_PACKAGES + unset REQUIRED_DEPENDENCIES + + local MODULE_CONFIG="${MODULE_DIR}/${MODULE}.conf" + + if [ -e "${MODULE_CONFIG}.${PACKET_MANAGER}" ]; then + # a specific tool.conf seems to exist, try to use that one + # TODO: Maybe move this down right after loading the generic one, to allow "overloading".... but might be a bit confusing + . "${MODULE_CONFIG}.${PACKET_MANAGER}" || perror "Sourcing '${MODULE_CONFIG}.${PACKET_MANAGER}' failed." + else + # otherwise, use the generic one + [ ! -e "${MODULE_CONFIG}" ] && perror "Config for '$MODULE' not found." + . "${MODULE_CONFIG}" || perror "Sourcing '${MODULE_CONFIG}' failed." + fi +} + +read_build () { + local BUILD_SCRIPT="${MODULE_DIR}/${MODULE}.build" + + [ ! -e "${BUILD_SCRIPT}" ] && perror "Build script for specified tool not found." + + . "${BUILD_SCRIPT}" || perror "Sourcing '${BUILD_SCRIPT}' failed." +} + +copyfileswithdependencies () { + + [ ! -d $MODULE_BUILD_DIR ] && pinfo "No build directory found, skipping dependency copying" && return 0 + cd $MODULE_BUILD_DIR + + COPYFILES_LIST="list_wanted_stage3.2" + [ -e ${COPYFILES_LIST} ] && rm ${COPYFILES_LIST} + + + [ ! -z "${REQUIRED_BINARIES}" ] && pinfo "Gathering required binaries from config file..." + for FILENAME in ${REQUIRED_BINARIES} + do + local FILE_CANDIDATES=$( find . -name "${FILENAME}" -a \( -type f -o -type l \) ) + pdebug "Candidates for $FILENAME are: $FILE_CANDIDATES" + local FINAL_LIST="" + for FILE in $FILE_CANDIDATES; do + local TESTFILE="$(readlink -f "$FILE")" + pdebug " $FILE leads to $TESTFILE" + [ -f "$TESTFILE" -a -x "$TESTFILE" ] && [ "x$(grep -l -E '^(.ELF|#!)' "$TESTFILE")" != "x" ] && FINAL_LIST="$FINAL_LIST $FILE" + done + FINAL_LIST=$(trim "$FINAL_LIST") + pdebug " Final list is $FINAL_LIST" + if [ -z "$FINAL_LIST" ]; then + pwarning "\tNo Binary found for ${FILENAME}. Skipping." + continue + fi + if [[ "$FINAL_LIST" == *" "* ]]; then + pwarning "Found more than one match for required file '$FILENAME': $FINAL_LIST" + else + pdebug "\tFound ${FILENAME} at ${FILE}" + fi + for FILE in $FINAL_LIST; do + strip $FILE || pwarning "Could not strip '${FILE}'" + get_link_chain "${MODULE_BUILD_DIR}/${FILE}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" + get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${FILE}" >> "${COPYFILES_LIST}" + done + done + + [ ! -z "${REQUIRED_LIBRARIES}" ] && pinfo "Gathering required libraries from config file..." + for LIB in ${REQUIRED_LIBRARIES} + do + for LOCATION in $(find . -name ${LIB}.so\*) + do + pdebug "* $LOCATION" + strip $LOCATION || pwarning "Could not strip '${LOCATION}'" + get_link_chain "${MODULE_BUILD_DIR}/${LOCATION}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" + get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${LOCATION}" >> "${COPYFILES_LIST}" + done + done + + [ ! -z "${REQUIRED_DIRECTORIES}" ] && pinfo "Gathering required directories from config file..." + local CURRENT_PWD=$(pwd) # Prevent calling pwd 50000 times inside the loop below + for ENTRY in ${REQUIRED_DIRECTORIES} + do + pdebug "* ./$ENTRY" + echo "./${ENTRY}" >> "${COPYFILES_LIST}" + for BIN in $(find "./${ENTRY}" -type f -not -name '*.a' | xargs grep -l '^.ELF') + do + pdebug " Searching libs for ${BIN}..." + get_link_chain "${MODULE_BUILD_DIR}/${BIN}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" + get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${BIN}" >> "${COPYFILES_LIST}" + done + done + + [ ! -z "${REQUIRED_FILES}" ] && pinfo "Gathering required files from config file..." + for ENTRY in ${REQUIRED_FILES} + do + get_link_chain "${MODULE_BUILD_DIR}/${ENTRY}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" + get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${MODULE_BUILD_DIR}/.${ENTRY}" >> "${COPYFILES_LIST}" + done + + + #copy to initramfsdir + pdebug "[stage32] File list generated at ${MODULE_BUILD_DIR}/${COPYFILES_LIST}." + if [ -s "$COPYFILES_LIST" ]; then + local CLISTCOUNT=$(cat "$COPYFILES_LIST" | wc -l) + pinfo "Copying $CLISTCOUNT files to '${TARGET_BUILD_DIR}'." + tarcopy "$(cat "$COPYFILES_LIST"|sort -u)" "${TARGET_BUILD_DIR}" + fi +} + +generate_target() { + + initial_checks + + [[ $TARGET == builds || $TARGET == modules ]] && \ + perror "Target directory cannot be named 'builds' nor 'modules'." + + pinfo "Generating '$TARGET_BUILD_DIR' for '$TARGET'" + + # if no arguments assume all. + if [ "x$1" = "x" -o "x$1" = "xall" ]; then + MODULES=$(ls ${TARGET_DIR}) + set -- $MODULES + else + # tools = arguments given + MODULES=$@ + fi + + pinfo "Activated modules in '${TARGET}':" + pinfo "\t$(echo ${MODULES})" + + # copy basic libs + pinfo "Copying libc and ld-linux used by ${SHELL}" + tarcopy "$(list_basic_libs)" "${TARGET_BUILD_DIR}" + + # now iterate over given tools and copy them + while (( "$#" )); do + process_module "$1" + shift + done + TOOL_STR="" +} + +process_module() { + [ "$#" -ne "1" ] && perror "process_module: want 1 param." + local MODULE="$1" + [[ "$PROCESSED_MODULES" == *"!${MODULE}!"* ]] && return # Already processed this module + PROCESSED_MODULES="${PROCESSED_MODULES}!${MODULE}!" + local MODULE_DIR="${TARGET_DIR}/${MODULE}" + local MODULE_BUILD_DIR="${MODULE_DIR}/build" + local TOOL_STR="" + pinfo ">>>>>>>>>>>>>>>>> Processing module [ $MODULE ]" + TOOL_STR="[${MODULE}]" + if [ -d "${MODULE_DIR}" ]; then + + #[ "x$DEBUG" != "x1" ] \ + # && echo "Logging to ${TOOL_DIR}/${TOOL}/stage32.log" \ + # && exec 6>&1 > ${TOOL_DIR}/${TOOL}/stage32.log + # TODO: Make above work with the new logging system (add function to logging.inc to switch logfile) + cd "${MODULE_DIR}" || perror "Module dir '${MODULE_DIR}' seems to exist, but cd to it failed." + pinfo "## Reading config" + read_config + # Check if this module has a dependency that wasn't built yet: + if [ ! -z "$REQUIRED_MODULES" ]; then + pinfo "$MODULE depends on ${REQUIRED_MODULES}...." + for DEP in $REQUIRED_MODULES; do + #[[ "$DESIRED_MODULES" != *"!${DEP}!"* ]] && perror "$TOOL has dependency $DEP, but $DEP is not in current profile." + process_module "$DEP" + done + # Read old config again, as it got overwritten by the deps + cd "${MODULE_DIR}" || perror "Tool dir '${MODULE_DIR}' seems to exist, but cd to it failed (after building deps)." + read_config + pinfo "<<<<<<<<<<<<<<<<< Dependency modules processed, back to module [ $MODULE ]" + fi + pinfo "## Reading build" + read_build + pinfo "## Installing dependencies" + install_dependencies + pinfo "## Fetching source" + fetch_source + pinfo "## Building" + build + # remove *.la files as they might confuse libtool/linker of other tool packages + find "${MODULE_DIR}/build" -name '*.la' -exec rm -f {} \; + pinfo "## Copying files with dependencies" + copyfileswithdependencies + pinfo "## Post copy" + post_copy + + # reset pipes + #[ "x$DEBUG" != "x1" ] && exec 1>&6 6>&- + # TODO + pinfo "Module completed." + else + pwarning "Module directory for '$MODULE' not found." + fi +} + +clean_modules() { + if [ "x$1" = "x" -o "x$1" = "xall" ]; then + if [ -d ${TARGET_BUILD_DIR} ]; then + pinfo "Cleaning '${TARGET_BUILD_DIR}'" \ + && rm -rf "${TARGET_BUILD_DIR}"/* \ + || perror "Error deleting $TARGET_BUILD_DIR" + fi + set -- $(ls ${TARGET_DIR}) + fi + cd ${TARGET_DIR} + while (( "$#" )); do + clean_module $(readlink -f $1) + shift + done + cd - &> /dev/null +} + +clean_module() { + pinfo "Cleaning '$1'..." + local MODULE_DIR=$1 + if [ -e ${MODULE_DIR}/.built ]; then + rm "${MODULE_DIR}/.built" || perror "Could not clear built flag" + fi + if [ -e ${MODULE_DIR}/.fetched_source ]; then + rm "${MODULE_DIR}/.fetched_source" || perror "Could not clear fetched_source flag" + fi + if [ -d ${MODULE_DIR}/build ]; then + rm -rf "${MODULE_DIR}/build" || perror "Could not delete build path" + fi + if [ -d ${MODULE_DIR}/src ]; then + rm -rf "${MODULE_DIR}/src" || perror "Could not delete src path" + fi + if [ -e ${MODULE_DIR}/list_binaries_and_files ]; then + rm "${MODULE_DIR}/list_binaries_and_files" || perror "Could not delete list_binaries_and_files" + fi + if [ -e ${MODULE_DIR}/stage32.log ]; then + rm "${MODULE_DIR}/stage32.log" || perror "Could not delete stage32.log" + fi +} diff --git a/remote/setup_tools b/remote/setup_tools deleted file mode 100755 index 713d03fd..00000000 --- a/remote/setup_tools +++ /dev/null @@ -1,266 +0,0 @@ -#!/bin/bash - -MODE_DIR="${ROOT_DIR}/remote" - -#Create tools directory if not exists -MODULES_DIR="${MODE_DIR}/modules" - -# Keep track of processed modules -PROCESSED_MODULES="" - -initial_checks () { - # check for required tools - for BIN in git locate depmod - do - local TEST=$(which ${BIN}) - [ -z "$TEST" ] && pinfo "Installing $BIN..." && apt-get install $BIN - done -} - - -read_config () { - unset REQUIRED_BINARIES - unset REQUIRED_LIBRARIES - unset REQUIRED_DIRECTORIES - unset REQUIRED_FILES - unset REQUIRED_MODULES - unset REQUIRED_PACKAGES - unset REQUIRED_DEPENDENCIES - - local MODULE_CONFIG="${MODULE_DIR}/${MODULE}.conf" - - if [ -e "${MODULE_CONFIG}.${PACKET_MANAGER}" ]; then - # a specific tool.conf seems to exist, try to use that one - # TODO: Maybe move this down right after loading the generic one, to allow "overloading".... but might be a bit confusing - . "${MODULE_CONFIG}.${PACKET_MANAGER}" || perror "Sourcing '${MODULE_CONFIG}.${PACKET_MANAGER}' failed." - else - # otherwise, use the generic one - [ ! -e "${MODULE_CONFIG}" ] && perror "Config for '$MODULE' not found." - . "${MODULE_CONFIG}" || perror "Sourcing '${MODULE_CONFIG}' failed." - fi -} - -read_build () { - local BUILD_SCRIPT="${MODULE_DIR}/${MODULE}.build" - - [ ! -e "${BUILD_SCRIPT}" ] && perror "Build script for specified tool not found." - - . "${BUILD_SCRIPT}" || perror "Sourcing '${BUILD_SCRIPT}' failed." -} - -copyfileswithdependencies () { - - [ ! -d $MODULE_BUILD_DIR ] && pinfo "No build directory found, skipping dependency copying" && return 0 - cd $MODULE_BUILD_DIR - - COPYFILES_LIST="list_wanted_stage3.2" - [ -e ${COPYFILES_LIST} ] && rm ${COPYFILES_LIST} - - - [ ! -z "${REQUIRED_BINARIES}" ] && pinfo "Gathering required binaries from config file..." - for FILENAME in ${REQUIRED_BINARIES} - do - local FILE_CANDIDATES=$( find . -name "${FILENAME}" -a \( -type f -o -type l \) ) - pdebug "Candidates for $FILENAME are: $FILE_CANDIDATES" - local FINAL_LIST="" - for FILE in $FILE_CANDIDATES; do - local TESTFILE="$(readlink -f "$FILE")" - pdebug " $FILE leads to $TESTFILE" - [ -f "$TESTFILE" -a -x "$TESTFILE" ] && [ "x$(grep -l -E '^(.ELF|#!)' "$TESTFILE")" != "x" ] && FINAL_LIST="$FINAL_LIST $FILE" - done - FINAL_LIST=$(trim "$FINAL_LIST") - pdebug " Final list is $FINAL_LIST" - if [ -z "$FINAL_LIST" ]; then - pwarning "\tNo Binary found for ${FILENAME}. Skipping." - continue - fi - if [[ "$FINAL_LIST" == *" "* ]]; then - pwarning "Found more than one match for required file '$FILENAME': $FINAL_LIST" - else - pdebug "\tFound ${FILENAME} at ${FILE}" - fi - for FILE in $FINAL_LIST; do - strip $FILE || pwarning "Could not strip '${FILE}'" - get_link_chain "${MODULE_BUILD_DIR}/${FILE}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" - get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${FILE}" >> "${COPYFILES_LIST}" - done - done - - [ ! -z "${REQUIRED_LIBRARIES}" ] && pinfo "Gathering required libraries from config file..." - for LIB in ${REQUIRED_LIBRARIES} - do - for LOCATION in $(find . -name ${LIB}.so\*) - do - pdebug "* $LOCATION" - strip $LOCATION || pwarning "Could not strip '${LOCATION}'" - get_link_chain "${MODULE_BUILD_DIR}/${LOCATION}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" - get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${LOCATION}" >> "${COPYFILES_LIST}" - done - done - - [ ! -z "${REQUIRED_DIRECTORIES}" ] && pinfo "Gathering required directories from config file..." - local CURRENT_PWD=$(pwd) # Prevent calling pwd 50000 times inside the loop below - for ENTRY in ${REQUIRED_DIRECTORIES} - do - pdebug "* ./$ENTRY" - echo "./${ENTRY}" >> "${COPYFILES_LIST}" - for BIN in $(find "./${ENTRY}" -type f -not -name '*.a' | xargs grep -l '^.ELF') - do - pdebug " Searching libs for ${BIN}..." - get_link_chain "${MODULE_BUILD_DIR}/${BIN}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" - get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${BIN}" >> "${COPYFILES_LIST}" - done - done - - [ ! -z "${REQUIRED_FILES}" ] && pinfo "Gathering required files from config file..." - for ENTRY in ${REQUIRED_FILES} - do - get_link_chain "${MODULE_BUILD_DIR}/${ENTRY}" "${MODULE_BUILD_DIR}" >> "${COPYFILES_LIST}" - get_dynamic_dependencies -l "${MODULE_BUILD_DIR}" "${MODULE_BUILD_DIR}/.${ENTRY}" >> "${COPYFILES_LIST}" - done - - - #copy to initramfsdir - pdebug "[stage32] File list generated at ${MODULE_BUILD_DIR}/${COPYFILES_LIST}." - if [ -s "$COPYFILES_LIST" ]; then - local CLISTCOUNT=$(cat "$COPYFILES_LIST" | wc -l) - pinfo "Copying $CLISTCOUNT files to '${TARGET_BUILD_DIR}'." - tarcopy "$(cat "$COPYFILES_LIST"|sort -u)" "${TARGET_BUILD_DIR}" - fi -} - -generate_target() { - - initial_checks - - [[ $TARGET == build || $TARGET == modules ]] && \ - perror "Target directory cannot be named 'build' nor 'modules'." - - # check for target directory - TARGET_DIR="${MODE_DIR}/targets/${TARGET}" - [ -d $TARGET_DIR ] || perror "Given target directory does not exist: $TARGET" - - TARGET_BUILD_DIR="${MODE_DIR}/builds/${TARGET}" - - pinfo "Generating '$TARGET_BUILD_DIR' for '$TARGET'" - - # if no arguments assume all. - if [ "x$1" = "x" -o "x$1" = "xall" ]; then - MODULES=$(ls ${TARGET_DIR}) - set -- $MODULES - else - # tools = arguments given - MODULES=$@ - fi - - pinfo "Activated modules in '${TARGET}':" - pinfo "\t$(echo ${MODULES})" - - # copy basic libs - pinfo "Copying libc and ld-linux used by ${SHELL}" - tarcopy "$(list_basic_libs)" "${TARGET_BUILD_DIR}" - - # now iterate over given tools and copy them - while (( "$#" )); do - process_module "$1" - shift - done - TOOL_STR="" -} - -process_module() { - [ "$#" -ne "1" ] && perror "process_module: want 1 param." - local MODULE="$1" - [[ "$PROCESSED_MODULES" == *"!${MODULE}!"* ]] && return # Already processed this module - PROCESSED_MODULES="${PROCESSED_MODULES}!${MODULE}!" - local MODULE_DIR="${TARGET_DIR}/${MODULE}" - local MODULE_BUILD_DIR="${MODULE_DIR}/build" - local TOOL_STR="" - pinfo ">>>>>>>>>>>>>>>>> Processing module [ $MODULE ]" - TOOL_STR="[${MODULE}]" - if [ -d "${MODULE_DIR}" ]; then - - #[ "x$DEBUG" != "x1" ] \ - # && echo "Logging to ${TOOL_DIR}/${TOOL}/stage32.log" \ - # && exec 6>&1 > ${TOOL_DIR}/${TOOL}/stage32.log - # TODO: Make above work with the new logging system (add function to logging.inc to switch logfile) - cd "${MODULE_DIR}" || perror "Module dir '${MODULE_DIR}' seems to exist, but cd to it failed." - pinfo "## Reading config" - read_config - # Check if this module has a dependency that wasn't built yet: - if [ ! -z "$REQUIRED_MODULES" ]; then - pinfo "$MODULE depends on ${REQUIRED_MODULES}...." - for DEP in $REQUIRED_MODULES; do - #[[ "$DESIRED_MODULES" != *"!${DEP}!"* ]] && perror "$TOOL has dependency $DEP, but $DEP is not in current profile." - process_module "$DEP" - done - # Read old config again, as it got overwritten by the deps - cd "${MODULE_DIR}" || perror "Tool dir '${MODULE_DIR}' seems to exist, but cd to it failed (after building deps)." - read_config - pinfo "<<<<<<<<<<<<<<<<< Dependency modules processed, back to module [ $MODULE ]" - fi - pinfo "## Reading build" - read_build - pinfo "## Installing dependencies" - install_dependencies - pinfo "## Fetching source" - fetch_source - pinfo "## Building" - build - # remove *.la files as they might confuse libtool/linker of other tool packages - find "${MODULE_DIR}/build" -name '*.la' -exec rm -f {} \; - pinfo "## Copying files with dependencies" - copyfileswithdependencies - pinfo "## Post copy" - post_copy - - # reset pipes - #[ "x$DEBUG" != "x1" ] && exec 1>&6 6>&- - # TODO - pinfo "Module completed." - else - perror "Module directory for '$MODULE' not found." - # maybe make this a warning instead of error? - fi -} - -clean_tools() { - if [ "x$1" = "x" -o "x$1" = "xall" ]; then - #clean all - if [ -d ${TARGET_BUILD_DIR} ]; then - rm -rf "${TARGET_BUILD_DIR}"/* || perror "Error deleting $TARGET_BUILD_DIR" - fi - for MODULE in $(ls ${MODULES_DIR}); do - clean_tool $MODULE - done - else - while (( "$#" )); do - clean_tool $1 - shift - done - fi -} - -clean_tool() { - local MODULE_DIR=${MODULES_DIR}/$1 - pinfo "Cleaning '${MODULE_DIR}'..." - #[ -e ${TOOLDIR}/build/list_wanted_stage3.2 ] && cd ${TARGET_BUILD_DIR} \ - # && xargs rm < ${TOOLDIR}/build/list_wanted_stage3.2 - #[ -d ${TOOLDIR}/data ] && cd ${TARGET_BUILD_DIR} \ -# && xargs rm < $(find ${TOOLDIR}/data -type f) - if [ -e ${MODULE_DIR}/.built ]; then - rm "${MODULE_DIR}/.built" || perror "Could not clear built flag" - fi - if [ -e ${MODULE_DIR}/.fetched_source ]; then - rm "${MODULE_DIR}/.fetched_source" || perror "Could not clear fetched_source flag" - fi - if [ -d ${MODULE_DIR}/build ]; then - rm -rf "${MODULE_DIR}/build" || perror "Could not delete build path" - fi - if [ -d ${MODULE_DIR}/src ]; then - rm -rf "${MODULE_DIR}/src" || perror "Could not delete src path" - fi - if [ -e ${MODULE_DIR}/list_binaries_and_files ]; then - rm "${MODULE_DIR}/list_binaries_and_files" || perror "Could not delete list_binaries_and_files" - fi -} -- cgit v1.2.3-55-g7522