diff options
author | Sebastian Schmelzer | 2011-05-02 16:43:55 +0200 |
---|---|---|
committer | Sebastian Schmelzer | 2011-05-02 16:43:55 +0200 |
commit | 7931e88ac8ab2eab4da6840a698920f8c28deba4 (patch) | |
tree | f1138f213c41f9582519839fefac355eec7620ed | |
parent | Make the calculation right (normalize to MByte) ... (diff) | |
download | usb-boot-stick-7931e88ac8ab2eab4da6840a698920f8c28deba4.tar.gz usb-boot-stick-7931e88ac8ab2eab4da6840a698920f8c28deba4.tar.xz usb-boot-stick-7931e88ac8ab2eab4da6840a698920f8c28deba4.zip |
update installer ..
-rwxr-xr-x | create-installer | 2 | ||||
-rwxr-xr-x | install-usb | 5 | ||||
-rwxr-xr-x | installer/tpl/installer.tpl.sh | 170 |
3 files changed, 154 insertions, 23 deletions
diff --git a/create-installer b/create-installer index ddec96d..50075f9 100755 --- a/create-installer +++ b/create-installer @@ -30,7 +30,7 @@ cp -f $SYSLINUX/linux/syslinux $ROOT_DIR/installer/tmp/bin cp -f $ROOT_DIR/build/kernel-preboot-latest $ROOT_DIR/installer/tmp/boot/kernel build.initramfs.sh -cp -f $ROOT_DIR/build/initramfs-default $ROOT_DIR/installer/tmp/boot/init +cp -f $ROOT_DIR/build/initramfs-default $ROOT_DIR/installer/tmp/boot/initramfs cp -f $SYSLINUX/com32/menu/menu.c32 $ROOT_DIR/installer/tmp/boot/ cp -f $SYSLINUX/com32/menu/vesamenu.c32 $ROOT_DIR/installer/tmp/boot/ diff --git a/install-usb b/install-usb index ccac69e..1467019 100755 --- a/install-usb +++ b/install-usb @@ -24,7 +24,8 @@ fi OUT_DEV=$1 if [ -z $OUT_DEV ]; then - echo "no dev" + echo "[Error] No output device specified." + echo "Usage $0 [devicename of usb-stick] (e.g. \"sdc\" for /dev/sdc)." exit 1 fi @@ -39,7 +40,7 @@ done SYSLINUX=${ROOT_DIR}/contrib/syslinux/latest -PATH="$PATH:${ROOT_DIR}/bin/" +PATH="${ROOT_DIR}/bin/:$PATH" # create the required stuff (syslinux, kernel, initramfs) [ ! -f ${SYSLINUX}/Makefile ] && env.setup-syslinux.sh diff --git a/installer/tpl/installer.tpl.sh b/installer/tpl/installer.tpl.sh index 9777fc1..1214af3 100755 --- a/installer/tpl/installer.tpl.sh +++ b/installer/tpl/installer.tpl.sh @@ -1,67 +1,197 @@ #!/bin/bash +# ----------------------------------------------------------------------------- +# Copyright (c) 2011 - 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/ +# ----------------------------------------------------------------------------- +# PreBoot USB stick installer +# ----------------------------------------------------------------------------- ROOT_DIR=$(dirname $(readlink -f $0)) SELF=$(readlink -f $0) TMP_DIR="/tmp/pbstick-$$" -OUT_DEV=$1 +DEBUG=0 +FORCE=0 + +VERSION="" +VDATE="" + +SHORT_OPTS=":vfdh" +LONG_OPTS="version,force,debug,help" + +print_usage() { + echo "Usage: $(basename $SELF) [OPTIONS] DEVICE" + echo -e " -d --debug \t give more debug output" + echo -e " -f --force \t don't ask questions" + echo -e " -h --help \t print help" + echo -e " -v --version \t print version information" + echo "DEVICE is the device used by the usb stick (e.g. \"sdX\" for /dev/sdX)." +} + +TEMP=`getopt -o $SHORT_OPTS --long $LONG_OPTS \ + -n "$0" -- "$@"` + +if [ $? != 0 ] ; then + echo -e "[Error] Unknown option(s).\n" + print_usage + exit 1 +fi + +eval set -- "$TEMP" + +while true ; do + case "$1" in + -v|--version) + echo "OpenSLX PreBoot USB stick installer ($VERSION - $VDATE)." + exit 0 + ;; + -h|--help) + print_usage + exit 0 + ;; + -f|--force) echo "[Info] Disable user-interaction."; FORCE=1; shift ;; + -d|--debug) echo "[Info] Enabled debugmode."; DEBUG=1; shift ;; + --) shift ; break ;; + *) echo "[Error] Internal error!" ; exit 1 ;; + esac +done + if [ $(whoami) != "root" ]; then - echo "you should be root" + echo -e "[Error] You should be root." exit 1; fi +OUT_DEV=$1 +shift + +if [ ! -z $1 ]; then + echo -e "[Error] Too many parameters. \n" + print_usage + exit 1 +fi + if [ -z $OUT_DEV ]; then - echo "no outputdev specified - usage $0 [devicename of usbstick] (eg sdc for /dev/sdc)" + echo -e "[Error] No output device specified.\n" + print_usage exit 1 fi +if [ ! -e "/dev/$OUT_DEV" ]; then + echo -e "[Error] There is no /dev/${OUT_DEV}." + exit 1 +fi + +if [ -z $(which uuencode) ]; then + echo -e "[Error] uuencode is missing (if you are on a debian/ubuntu system: apt-get install sharutils)" + exit 1 +fi + + +# unpack script payload + mkdir -p $TMP_DIR +set_quiet () { + if [ "x$DEBUG" != "x1" ]; then + touch $TMP_DIR/stdout.log + touch $TMP_DIR/stderr.log + exec 6>&1 > $TMP_DIR/stdout.log + exec 2> $TMP_DIR/stderr.log + fi +} + +unset_quiet () { + if [ "x$DEBUG" != "x1" ]; then + exec 1>&6 6>&- + exec 2>&- + fi +} + +set_quiet match=$(grep --text --line-number '^PAYLOAD:$' $SELF | cut -d ':' -f 1) payload_start=$((match + 1)) cd $TMP_DIR -tail -n +$payload_start $SELF | uudecode | tar -xjvf - +tail -n +$payload_start $SELF | uudecode | tar -xjf - cd $ROOT_DIR -PATH="$PATH:$TMP_DIR/bin/" + + +PATH="$TMP_DIR/bin/:$PATH" + +if [ "x$FORCE" != "x1" ]; then + unset_quiet + echo "Device \"/dev/${OUT_DEV}\" will be repartitioned and formatted." + echo -n "Do you really want to proceed? Then type in 'yes': " + read cont + [ "x${cont}" != "xyes" ] && exit 1 + set_quiet +fi for i in 1 2 3 4 5 6 7 8 9; do umount /dev/${OUT_DEV}$i &> /dev/null done -# create bootable vfat partition with 96cylinders and a ext3 partition for the -# rest of the stick -sfdisk /dev/${OUT_DEV} << EOF -,96,6,* -,,L +# get the total size of the device +DISKSIZE=$(sfdisk -s /dev/${OUT_DEV} 2>/dev/null || echo 0) +DISKSIZE=$((${DISKSIZE}/1024)) + +# get the size of boot stuff and calculate the left over free space on device +KSIZE=$(ls -l ${TMP_DIR}/boot/kernel|awk '{print $5}') +ISIZE=$(ls -l ${TMP_DIR}/boot/initramfs|awk '{print $5}') +IMAGESIZE=$(((${KSIZE}+${ISIZE}+6000000)/1048576)) +FREE=$((${DISKSIZE}-${IMAGESIZE})) + +# create bootable vfat at the end of the device if big enough, otherwise use +# the entire device +if [ ${FREE} -ge 50 ] ; then + sfdisk /dev/${OUT_DEV} -uM << EOF +,${FREE},L, +,,6,* EOF +else + sfdisk /dev/${OUT_DEV} << EOF +,,6,* +EOF +fi sync # copy mbr to stick -dd bs=440 count=1 conv=notrunc if=$TMP_DIR/share/mbr.bin of=/dev/${OUT_DEV} +dd bs=440 count=1 conv=notrunc if=$TMP_DIR/share/mbr.bin of=/dev/${OUT_DEV} $DEBUG_OUT # create filesystems on newly createt partitions -mkfs.vfat -F 16 -n PBStick /dev/${OUT_DEV}1 -mkfs.ext2 -L OpenSLX-Home /dev/${OUT_DEV}2 +mkfs.vfat -F 16 -n PBStick /dev/${OUT_DEV}2 $DEBUG_OUT +mkfs.ext2 -L openslx-usrhome /dev/${OUT_DEV}1 $DEBUG_OUT mkdir -p /media/openslx-stick /media/openslx-stick-usrhome sync -mount /dev/${OUT_DEV}1 /media/openslx-stick -mount /dev/${OUT_DEV}2 /media/openslx-stick-usrhome +mount /dev/${OUT_DEV}2 /media/openslx-stick +mount /dev/${OUT_DEV}1 /media/openslx-stick-usrhome mkdir -p /media/openslx-stick/boot -cp -v $TMP_DIR/boot/* /media/openslx-stick/boot/ +cp -v $TMP_DIR/boot/* /media/openslx-stick/boot/ $DEBUG_OUT -sync -umount /media/openslx-stick -umount /media/openslx-stick-usrhome +umount /media/openslx-stick $DEBUG_OUT +umount /media/openslx-stick-usrhome $DEBUG_OUT + +rm -rf /media/openslx-stick* $DEBUG_OUT + +$TMP_DIR/bin/syslinux --install -d /boot -f /dev/${OUT_DEV}2 $DEBUG_OUT + +unset_quiet -$TMP_DIR/bin/syslinux --install -d /boot -f /dev/${OUT_DEV}1 +echo "Successfully created OpenSLX PreBoot USB Stick .." exit 0 |