/build/scripts/image_hd_syslinux
#! | 113 lines | 95 code | 18 blank | 0 comment | 0 complexity | fe9a2e113be76d1517603203b99cf528 MD5 | raw file
Possible License(s): BSD-3-Clause
- #!/bin/bash
- # Copyright (c) 2012 The tyndur Project. All rights reserved.
- #
- # This code is derived from software contributed to the tyndur Project
- # by Arne Hasselbring.
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions
- # are met:
- # 1. Redistributions of source code must retain the above copyright
- # notice, this list of conditions and the following disclaimer.
- # 2. Redistributions in binary form must reproduce the above copyright
- # notice, this list of conditions and the following disclaimer in the
- # documentation and/or other materials provided with the distribution.
- # 3. All advertising materials mentioning features or use of this software
- # must display the following acknowledgement:
- # This product includes software developed by the tyndur Project
- # and its contributors.
- # 4. Neither the name of the tyndur Project nor the names of its
- # contributors may be used to endorse or promote products derived
- # from this software without specific prior written permission.
- #
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ROOT=build/root
- ROOT_COMMON=build/root-common
- ROOT_HD=build/root-hd
- ROOT_LOCAL=build/root-local
- MOUNT=build/mnt
- SUDO=sudo
- export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
- export LOST_BUILDMK_ROOT="`pwd`"
- source build/config/image_hd.sh
- source config.sh
- die()
- {
- echo $1
- exit -1
- }
- # Wenn das Image neu erstellt werden muss, kommen noch ein paar schritte mehr
- # dazu.
- NEW=0
- if ! [ -f $IMAGE_PATH ]; then
- # Leeres Image erstellen und formatieren
- dd of=$IMAGE_PATH bs=$((1024 * 1024)) seek=$IMAGE_SIZE count=0
- build/scripts/create_partition $IMAGE_PATH
- NEW=1
- fi
- # Start und Ende der Partition einlesen
- PARTITIONS="`build/scripts/get_partition $IMAGE_PATH`"
- PART_START=`echo $PARTITIONS | awk '{print $1}'`
- PART_SIZE=`echo $PARTITIONS | awk '{print $2}'`
- if [ $NEW -ne 0 ]; then
- LOOP_DEV=`$SUDO losetup -f $IMAGE_PATH --sizelimit $(($PART_SIZE * 512)) -o $(($PART_START * 512)) --show`
- if [ $? -ne 0 ]; then
- die "Loop Device konnte nicht angelegt werden"
- fi
- # Dateisystem erstellen
- $SUDO $LOST_TOOLS_MKE2FS -T ext2 -F -q $LOOP_DEV || die "Dateisystem konnte nicht erstellt werden"
- $SUDO losetup -d $LOOP_DEV
- fi
- # Partition mounten
- mkdir -p $MOUNT
- $SUDO mount $IMAGE_PATH $MOUNT -t ext2 -o loop,offset=$((${PART_START} * 512))
- $SUDO chmod 777 -Rf $MOUNT
- # Daten Kopieren
- cp -rP --preserve=links,timestamps $ROOT/* $ROOT_COMMON/* $ROOT_HD/* $MOUNT/
- [ -d $ROOT_LOCAL ] && cp -rP --preserve=links,timestamps $ROOT_LOCAL/* $MOUNT/
- # Syslinux-Konfiguration kopieren
- mkdir -p $MOUNT/boot/syslinux
- rm -f $MOUNT/boot/syslinux/syslinux.cfg
- cat build/config/syslinux_hd.cfg >> $MOUNT/boot/syslinux/syslinux.cfg
- # Syslinux installieren und Dateien kopieren
- if [ $NEW -ne 0 ]; then
- $SUDO extlinux --install $MOUNT/boot/syslinux
- cp $LOST_SYSLINUX_DIR/mboot.c32 $MOUNT/boot/syslinux
- cp $LOST_SYSLINUX_DIR/menu.c32 $MOUNT/boot/syslinux
- fi
- # Partition unmounten und loopback-Device freigeben
- while fuser -m $MOUNT; do true; done
- $SUDO umount $MOUNT
- rmdir $MOUNT
- # MBR installieren
- if [ $NEW -ne 0 ]; then
- printf '\1' | cat $LOST_SYSLINUX_DIR/altmbr.bin - | dd bs=440 count=1 conv=notrunc iflag=fullblock of=$IMAGE_PATH
- fi