diff options
| -rwxr-xr-x | server/build_core | 78 |
1 files changed, 36 insertions, 42 deletions
diff --git a/server/build_core b/server/build_core index c231dc82..6d975984 100755 --- a/server/build_core +++ b/server/build_core @@ -26,31 +26,23 @@ STAGE32_DIR=${ROOT_DIR}/remote/stage3.2 # initial checks initial_checks() { - if [ ! -d ${STAGE32_DIR} ]; - then - echo "No stage3.2 directory found. Please run \"./mltk tools build\" first." - exit 1 - fi + [ -d ${STAGE32_DIR} ] || perror "No stage3.2 directory found. Please run './mltk tools build' first." + + [ -e ${STAGE32_DIR}/openslx/bin/busybox ] || perror "Busybox not found, run './mltk tools build busybox' first." - if [ ! -e ${STAGE32_DIR}/openslx/bin/busybox ]; - then - echo "Busybox not found, run 'setup_tools busybox' first." - exit 1 - fi # shouldn't squashfs-tools be automatically installed as we need them nevertheless!? # what if it is already on the machine? faster to check with which than the apt-get check? - if [ -z $(which mksquashfs) ]; - then - echo "mksquashfs not found, please install squashfs-tools first." - exit 1 - fi + if [ -z $(which mksquashfs) ] && perror "mksquashfs not found, please install squashfs-tools first." + #check for kernel modules, if not present copy from system if [ ! -d ${STAGE32_DIR}/lib/modules ]; then - echo "Couldn't find kernel modules in stage3.2." - echo "Copying modules for kernel $(uname -r)..." - mkdir -p ${STAGE32_DIR}/lib/modules - cp -r /lib/modules/$(uname -r) ${STAGE32_DIR}/lib/modules/ + pinfo "Couldn't find kernel modules in stage3.2." + pinfo "Copying modules for kernel $(uname -r)..." + mkdir -p "${STAGE32_DIR}/lib/modules" || perror "Cannot create '${STAGE32_DIR}/lib/modules'" + cp -r "/lib/modules/$(uname -r)" "${STAGE32_DIR}/lib/modules/" || perror "Cannot copy kernel modules from '/lib/modules/$(uname -r)' '${STAGE32_DIR}/lib/modules/'" + else + pinfo "Not copying kernel modules from system, as '${STAGE32_DIR}/lib/modules/' already exists." fi # TODO: check for aufs and squaskfs modules @@ -59,26 +51,26 @@ initial_checks() { generate_rootfs() { # produce stage3.1 - [ ! -d ${STAGE31_DIR} ] && mkdir -p ${STAGE31_DIR} + mkdir -p "${STAGE31_DIR}" || perror "Cannot create stage3.1 dir '${STAGE31_DIR}'" # create basic directory structure - mkdir -p ${STAGE31_DIR}/{bin,dev,proc,run,etc,mnt,sys} + 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 + "${STAGE31_DIR}"/dev || perror "Cannot copy devices from running system" # copy busybox, its libs and static data to stage3.1 - cp -r ${STAGE32_DIR}/openslx/* ${STAGE31_STATIC_DIR}/* ${STAGE31_DIR} + cp -r "${STAGE32_DIR}/openslx/*" "${STAGE31_STATIC_DIR}/*" "${STAGE31_DIR}" || perror "Copying busybox, its libs and static data failed." # fix for aufs & squashfs modules needed for stage 3.1 - mkdir -p ${STAGE31_DIR}/lib/modules.0/ - cp /lib/modules/$(uname -r)/kernel/fs/squashfs/squashfs.ko ${STAGE31_DIR}/lib/modules.0/ - cp /lib/modules/$(uname -r)/kernel/ubuntu/aufs/aufs.ko ${STAGE31_DIR}/lib/modules.0/ + mkdir -p "${STAGE31_DIR}/lib/modules.0/" || perror "Creating modules.0 dir for aufs & squashfs in stage 3.1 failed." + cp "/lib/modules/$(uname -r)/kernel/fs/squashfs/squashfs.ko" "${STAGE31_DIR}/lib/modules.0/" || perror "Copying squashfs.ko failed." + cp "/lib/modules/$(uname -r)/kernel/ubuntu/aufs/aufs.ko" "${STAGE31_DIR}/lib/modules.0/" || perror "Copying aufs.ko failed." # fetch the libraries needed for busybox BASICLIBS="" - for i in $(ldd ${STAGE31_DIR}/bin/busybox); + for i in $(ldd "${STAGE31_DIR}/bin/busybox"); do if [ $(echo $i | grep '^/' | grep -c ld) -eq 1 \ -o $(echo $i | grep '^/' | grep -c libc.so) -eq 1 ]; @@ -86,23 +78,26 @@ generate_rootfs() { BASICLIBS="$BASICLIBS $i $(readlink -f "$i")" fi done - (tar cpv $BASICLIBS | tar xpv -C ${STAGE31_DIR}) &>/dev/null - + tarcopy "$BASICLIBS" "${STAGE31_DIR}" } generate_squashfs() { # finalize the initramfs target - [ -e ${STAGE31_DIR}/mnt/openslx.sqfs ] && rm ${STAGE31_DIR}/mnt/openslx.sqfs + [ -e "${STAGE31_DIR}/mnt/openslx.sqfs" ] && rm "${STAGE31_DIR}/mnt/openslx.sqfs" - mksquashfs ${STAGE32_DIR} ${STAGE31_DIR}/mnt/openslx.sqfs -comp xz -b 1M -no-recovery 2>/dev/null + mksquashfs "${STAGE32_DIR}" "${STAGE31_DIR}/mnt/openslx.sqfs" -comp xz -b 1M -no-recovery || perror "mksquashfs failed ($?)." } generate_initramfs() { - cd ${STAGE31_DIR} - find . | cpio --format="newc" --create | gzip -9 > ${MODULE_DIR}/initramfs - cd - &>/dev/null - pinfo "[core] initramfs created at ${MODULE_DIR}/initramfs" + cd "${STAGE31_DIR}" || perror "Cannot cd to '${STAGE31_DIR}'" + find . | cpio --format="newc" --create | gzip -9 > "${MODULE_DIR}/initramfs" + local PS=($PIPESTATUS[*]) + [ "x${PS[0]}" != "x0" ] && perror "'find .' failed." + [ "x${PS[1]}" != "x0" ] && perror "cpio create failed." + [ "x${PS[2]}" != "x0" ] && perror "gzip to '${MODULE_DIR}/initramfs' failed." + cd - + pinfo "initramfs created at ${MODULE_DIR}/initramfs" } generate_stage31() { @@ -112,15 +107,14 @@ generate_stage31() { generate_initramfs # TODO better kernel copy - cp /boot/vmlinuz-$(uname -r) ${MODULE_DIR}/kernel + cp "/boot/vmlinuz-$(uname -r)" "${MODULE_DIR}/kernel" || perror "Cannot copy kernel from '/boot/vmlinuz-$(uname -r)' to '${MODULE_DIR}/kernel'" pinfo "[core] kernel $(uname -r) copied to ${MODULE_DIR}/kernel" } clean_core() { - echo -n "Cleaning ${STAGE31_DIR}..." - [ -d ${STAGE31_DIR} ] && rm -rf ${STAGE31_DIR} - echo " done." - echo -n "Cleaning ${MODULE_DIR}/initramfs..." - [ -e ${MODULE_DIR}/initramfs ] && rm ${MODULE_DIR}/initramfs - echo " done." + pinfo "Cleaning '${STAGE31_DIR}'..." + [ -d ${STAGE31_DIR} ] && { rm -rf ${STAGE31_DIR} || perror "rm -rf failed." } + pinfo "Cleaning '${MODULE_DIR}/initramfs'..." + [ -e ${MODULE_DIR}/initramfs ] && { rm ${MODULE_DIR}/initramfs || perror "rm failed." } } + |
