diff options
author | Jonathan Bauer | 2012-12-20 15:33:34 +0100 |
---|---|---|
committer | Jonathan Bauer | 2012-12-20 15:33:34 +0100 |
commit | f6dad6269ab3228ead055291b846d2a9edb04564 (patch) | |
tree | 30096a5fbd037fe4f9f0a0ef2b68d04317883c8e /server | |
parent | static unit files for dbus, cleanup (diff) | |
download | tm-scripts-f6dad6269ab3228ead055291b846d2a9edb04564.tar.gz tm-scripts-f6dad6269ab3228ead055291b846d2a9edb04564.tar.xz tm-scripts-f6dad6269ab3228ead055291b846d2a9edb04564.zip |
mltk basic script :)
Diffstat (limited to 'server')
-rwxr-xr-x | server/build_core | 143 | ||||
-rw-r--r-- | server/build_core.old | 64 |
2 files changed, 78 insertions, 129 deletions
diff --git a/server/build_core b/server/build_core index d0441c69..4e615520 100755 --- a/server/build_core +++ b/server/build_core @@ -18,71 +18,84 @@ # in the future the prefix should be set via slxsettings ... -ROOT_DIR=$(dirname $(readlink -f $0)) -SELF=$(readlink -f $0) +MODULE_DIR=${ROOT_DIR}/server -STAGE31_STATIC_DIR=${ROOT_DIR}/../data/stage3.1 -STAGE31_DIR=${ROOT_DIR}/stage3.1 -STAGE32_DIR=${ROOT_DIR}/../remote/stage3.2 +STAGE31_STATIC_DIR=${ROOT_DIR}/data/stage3.1 +STAGE31_DIR=${MODULE_DIR}/stage3.1 +STAGE32_DIR=${ROOT_DIR}/remote/stage3.2 # initial checks -if [ "x$(whoami)" != "xroot" ]; then - echo "ERROR: You need to have root rights to install packages." - exit 1 -fi - -if [ ! -d ${STAGE32_DIR} ]; -then - echo "No stage3.2 directory found. Please run setup-tools.sh first." - exit 1 -fi - -if [ ! -e ${STAGE32_DIR}/openslx/bin/busybox ]; -then - echo "Busybox not found, run 'setup-tools.sh 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 - -# produce stage3.1 -[ ! -d ${STAGE31_DIR} ] && mkdir -p ${STAGE31_DIR} - -# create basic directory structure -mkdir -p ${STAGE31_DIR}/{bin,dev,proc,run,lib,etc,mnt,sys} - -# copy device files from running system -cp -a /dev/{console,kmsg,mem,null,tty,tty0,tty1,tty9,urandom,zero} \ - ${STAGE31_DIR}/dev - -# copy busybox, its libs and static data to stage3.1 -cp -r ${STAGE32_DIR}/openslx/* ${STAGE31_STATIC_DIR}/* ${STAGE31_DIR} - -# fetch the libraries needed for busybox -BASICLIBS="" -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 ]; - then - echo $i - BASICLIBS="$BASICLIBS $i $(readlink -f "$i")" - fi -done -tar cpv $BASICLIBS | tar xpv -C ${STAGE31_DIR} &>/dev/null - -# finalize the initramfs target -[ ! -d ${STAGE32_DIR} ] && echo "No stage3.2 directory found. Please run setup_tools first." && exit 1 -[ -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 - -cd ${STAGE31_DIR} -find . | cpio --format="newc" --create | gzip -9 > ${ROOT_DIR}/initramfs -cd - &>/dev/null +initial_checks() { + if [ ! -d ${STAGE32_DIR} ]; + then + echo "No stage3.2 directory found. Please run setup_tools first." + exit 1 + fi + + 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 +} + +generate_initramfs() { + + # produce stage3.1 + [ ! -d ${STAGE31_DIR} ] && mkdir -p ${STAGE31_DIR} + + # create basic directory structure + mkdir -p ${STAGE31_DIR}/{bin,dev,proc,run,lib,etc,mnt,sys} + + # copy device files from running system + cp -a /dev/{console,kmsg,mem,null,tty,tty0,tty1,tty9,urandom,zero} \ + ${STAGE31_DIR}/dev + + # copy busybox, its libs and static data to stage3.1 + cp -r ${STAGE32_DIR}/openslx/* ${STAGE31_STATIC_DIR}/* ${STAGE31_DIR} + + # fetch the libraries needed for busybox + BASICLIBS="" + 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 ]; + then + echo $i + BASICLIBS="$BASICLIBS $i $(readlink -f "$i")" + fi + done + tar cpv $BASICLIBS | tar xpv -C ${STAGE31_DIR} &>/dev/null + +} + +generate_squashfs() { + + # finalize the initramfs target + [ ! -d ${STAGE32_DIR} ] && echo "No stage3.2 directory found. Please run setup_tools first." && exit 1 + [ -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 + + cd ${STAGE31_DIR} + find . | cpio --format="newc" --create | gzip -9 > ${MODULE_DIR}/initramfs + cd - &>/dev/null +} + +generate_stage31() { + initial_checks + generate_initramfs + generate_squashfs +} + +clean_core() { + [ -d ${STAGE31_DIR} ] && rm -rf ${STAGE31_DIR} + [ -e ${MODULE_DIR}/initramfs ] && rm ${MODULE_DIR}/initramfs +} diff --git a/server/build_core.old b/server/build_core.old deleted file mode 100644 index e761eb2e..00000000 --- a/server/build_core.old +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# Copyright (c) 2012 - 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 feedback to feedback@openslx.org -# -# General information about OpenSLX can be found at http://openslx.org -# -# Server side script to generate stage3.1,2 initial ramfses for OpenSLX Linux -# stateless clients -############################################################################# - -# first parameter is a hash pointing to the target directory -# /srv/openslx/build - -# in the future the prefix should be set via slxsettings ... -SLXPREFIX=/srv/openslx -IRTARGET=${SLXPREFIX}/build/$1 - -# add openslx distro (in)dependent data to the initramfs target -DISTRONAME=ubuntu -DISTROVER=12.04 - -for content in ${SLXPREFIX}/core/base - ${SLXPREFIX}/core/${DISTRONAME}/base - ${SLXPREFIX}/core/${DISTRONAME}/${DISTROVER} ; do - cp -a $content ${IRTARGET} -done - -# add kernel stuff to the initramfs target -KERNELVER= -mkdir -p ${IRTARGET}/lib/modules -cp -a ${SLXPREFIX}/kernel/${KERNELVER}/modules \ - ${IRTARGET}/lib/modules/${KERNELVER} - -# produce stage3.1 -mkdir -p ${IRTARGET}/stage3.1 - -# create the base directory structure for stage3.1 -mkdir -p ${IRTARGET}/stage3.1/{bin,dev,proc,run,lib,etc,mnt,sys} -cp -a /dev/{console,kmsg,mem,null,tty,tty0,tty1,tty9,urandom,zero} \ - ${IRTARGET}/stage3.1/dev -cp ${IRTARGET}/openslx/bin/busybox ${IRTARGET}/stage3.1/bin - -# link the required busybox applets for stage3.1 -for app in insmod modprobe mount mkdir umount sh switch_root ; do - ln -s /bin/busybox ${IRTARGET}/stage3.1/bin/${app} -done - -# add the static stuff for stage3.1 -cp -a ${SLXPREFIX}/core/stage3.1 ${IRTARGET}/stage3.1 - -# finalize the initramfs target -which mksquashfs 2>&1>/dev/null || { echo "Please install SquashFS utilities" ; exit 1 } - -mksquashfs -ef ${IRTARGET}/stage3.1 ${IRTARGET} \ - ${IRTARGET}/stage3.1/mnt/openslx.sqfs -comp xz -b 1M -no-progress -no-recovery 2>/dev/null - -(cd ${IRTARGET}/stage3.1; find . | cpio --format="newc" --create | gzip -9 > ${IRTARGET}/initramfs) - - |