diff options
author | Jonathan Bauer | 2013-03-11 12:44:31 +0100 |
---|---|---|
committer | Jonathan Bauer | 2013-03-11 12:44:31 +0100 |
commit | cec704825e7efa19a18d6b628fdab7ca2025da17 (patch) | |
tree | 14842e6ddecfbef4718668090f39dfec7dad1069 /remote/setup_core | |
parent | ignore new temp list files for stage3.1 (diff) | |
download | tm-scripts-cec704825e7efa19a18d6b628fdab7ca2025da17.tar.gz tm-scripts-cec704825e7efa19a18d6b628fdab7ca2025da17.tar.xz tm-scripts-cec704825e7efa19a18d6b628fdab7ca2025da17.zip |
new setup_core script, builds the stage3.1 rootfs on the remote system, instead of the server
Diffstat (limited to 'remote/setup_core')
-rwxr-xr-x | remote/setup_core | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/remote/setup_core b/remote/setup_core new file mode 100755 index 00000000..6888bc07 --- /dev/null +++ b/remote/setup_core @@ -0,0 +1,170 @@ +#!/bin/bash + +ROOT_DIR="/home/joe/work/tm-scripts" + +MODULE_DIR="${ROOT_DIR}/remote" +STAGE31_DIR="${MODULE_DIR}/stage3.1" + +MODULE_LIST="${MODULE_DIR}/core/stage31.modules" +FIRMWARE_LIST="${MODULE_DIR}/core/stage31.firmware" + + +. "${ROOT_DIR}/helper/logging.inc" +. "${ROOT_DIR}/helper/string.inc" +. "${ROOT_DIR}/helper/fileutil.inc" +. "${ROOT_DIR}/helper/system.inc" +. "${ROOT_DIR}/helper/binutil.inc" + +initial_checks() { + + [ ! -z "${KERNEL_VERSION}" ] || perror "No kernel version, cannot proceed." + [ ! -z "${ARCH_TRIPLET}" ] || perror "No arch triplet, cannot proceed." + + [ -f "${MODULE_LIST}" ] || perror "No list for stage3.1 kernel modules found." + [ -f "${FIRMWARE_LIST}" ] || perror "No list for stage3.1 firmware found." + + + [ -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 first." +} + +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." +} + +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 $(tr '\n' '|' < $MODULE_LIST) \ + >> "${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 + pinfo "Copying firmware from system..." + 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 +} + +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}" +} + +get_basic_tools() { + # get busybox from tools/ we checked earlier if its there. + cp -r "${MODULE_DIR}"/tools/busybox/build/openslx/* "${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 + git clone git://gitorious.org/x86emu/libx86emu.git + cd libx86emu + make || perror "[libx86emu] make failed." + #make install || perror "[libx86emu] make install to system failed." + DESTDIR="${MODULE_DIR}"/core/build make install || perror "[libx86emu] make install to "${STAGE31_DIR}" failed." + cd - &> /dev/null + + # now hwinfo + git clone git://gitorious.org/opensuse/hwinfo.git + cd hwinfo + make || perror "[hwinfo] make failed." + 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() { + + pinfo "Generating stage 3.1 file system..." + cd "${MODULE_DIR}"/core + initial_checks + read_config + copy_kernel_modules + generate_modules_map_files + copy_firmware + generate_rootfs + get_basic_tools + cd - &> /dev/null +} |