PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/build/scripts/image_hd_syslinux

https://bitbucket.org/x539/t-ndur
#! | 113 lines | 95 code | 18 blank | 0 comment | 0 complexity | fe9a2e113be76d1517603203b99cf528 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #!/bin/bash
  2. # Copyright (c) 2012 The tyndur Project. All rights reserved.
  3. #
  4. # This code is derived from software contributed to the tyndur Project
  5. # by Arne Hasselbring.
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions
  9. # are met:
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. # 3. All advertising materials mentioning features or use of this software
  16. # must display the following acknowledgement:
  17. # This product includes software developed by the tyndur Project
  18. # and its contributors.
  19. # 4. Neither the name of the tyndur Project nor the names of its
  20. # contributors may be used to endorse or promote products derived
  21. # from this software without specific prior written permission.
  22. #
  23. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  25. # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  26. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
  27. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  30. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  33. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. ROOT=build/root
  35. ROOT_COMMON=build/root-common
  36. ROOT_HD=build/root-hd
  37. ROOT_LOCAL=build/root-local
  38. MOUNT=build/mnt
  39. SUDO=sudo
  40. export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
  41. export LOST_BUILDMK_ROOT="`pwd`"
  42. source build/config/image_hd.sh
  43. source config.sh
  44. die()
  45. {
  46. echo $1
  47. exit -1
  48. }
  49. # Wenn das Image neu erstellt werden muss, kommen noch ein paar schritte mehr
  50. # dazu.
  51. NEW=0
  52. if ! [ -f $IMAGE_PATH ]; then
  53. # Leeres Image erstellen und formatieren
  54. dd of=$IMAGE_PATH bs=$((1024 * 1024)) seek=$IMAGE_SIZE count=0
  55. build/scripts/create_partition $IMAGE_PATH
  56. NEW=1
  57. fi
  58. # Start und Ende der Partition einlesen
  59. PARTITIONS="`build/scripts/get_partition $IMAGE_PATH`"
  60. PART_START=`echo $PARTITIONS | awk '{print $1}'`
  61. PART_SIZE=`echo $PARTITIONS | awk '{print $2}'`
  62. if [ $NEW -ne 0 ]; then
  63. LOOP_DEV=`$SUDO losetup -f $IMAGE_PATH --sizelimit $(($PART_SIZE * 512)) -o $(($PART_START * 512)) --show`
  64. if [ $? -ne 0 ]; then
  65. die "Loop Device konnte nicht angelegt werden"
  66. fi
  67. # Dateisystem erstellen
  68. $SUDO $LOST_TOOLS_MKE2FS -T ext2 -F -q $LOOP_DEV || die "Dateisystem konnte nicht erstellt werden"
  69. $SUDO losetup -d $LOOP_DEV
  70. fi
  71. # Partition mounten
  72. mkdir -p $MOUNT
  73. $SUDO mount $IMAGE_PATH $MOUNT -t ext2 -o loop,offset=$((${PART_START} * 512))
  74. $SUDO chmod 777 -Rf $MOUNT
  75. # Daten Kopieren
  76. cp -rP --preserve=links,timestamps $ROOT/* $ROOT_COMMON/* $ROOT_HD/* $MOUNT/
  77. [ -d $ROOT_LOCAL ] && cp -rP --preserve=links,timestamps $ROOT_LOCAL/* $MOUNT/
  78. # Syslinux-Konfiguration kopieren
  79. mkdir -p $MOUNT/boot/syslinux
  80. rm -f $MOUNT/boot/syslinux/syslinux.cfg
  81. cat build/config/syslinux_hd.cfg >> $MOUNT/boot/syslinux/syslinux.cfg
  82. # Syslinux installieren und Dateien kopieren
  83. if [ $NEW -ne 0 ]; then
  84. $SUDO extlinux --install $MOUNT/boot/syslinux
  85. cp $LOST_SYSLINUX_DIR/mboot.c32 $MOUNT/boot/syslinux
  86. cp $LOST_SYSLINUX_DIR/menu.c32 $MOUNT/boot/syslinux
  87. fi
  88. # Partition unmounten und loopback-Device freigeben
  89. while fuser -m $MOUNT; do true; done
  90. $SUDO umount $MOUNT
  91. rmdir $MOUNT
  92. # MBR installieren
  93. if [ $NEW -ne 0 ]; then
  94. printf '\1' | cat $LOST_SYSLINUX_DIR/altmbr.bin - | dd bs=440 count=1 conv=notrunc iflag=fullblock of=$IMAGE_PATH
  95. fi