summaryrefslogtreecommitdiffstats
path: root/build_tools/clarch/larch/run/usbboot.orig
diff options
context:
space:
mode:
Diffstat (limited to 'build_tools/clarch/larch/run/usbboot.orig')
-rwxr-xr-xbuild_tools/clarch/larch/run/usbboot.orig155
1 files changed, 155 insertions, 0 deletions
diff --git a/build_tools/clarch/larch/run/usbboot.orig b/build_tools/clarch/larch/run/usbboot.orig
new file mode 100755
index 0000000..b1f41b4
--- /dev/null
+++ b/build_tools/clarch/larch/run/usbboot.orig
@@ -0,0 +1,155 @@
+#! /bin/bash
+#
+# usbboot
+#
+# Author: Michael Towers <gradgrind[at]online[dot]de>
+#
+# This file is part of the larch project.
+#
+# larch is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# larch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with larch; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+#----------------------------------------------------------------------------
+# 2008.06.22
+
+APP="$( basename $0 )"
+
+usage () {
+ echo
+ echo "Usage:"
+ echo " ${APP} [<Arch installation root directory>]"
+ echo
+ echo " Prepare a bootable USB-stick from a larch build."
+ echo " If no Arch directory is given, '/' is assumed."
+ exit 1
+}
+
+if [ -n "$1" ]; then
+ AINSTALL="$( readlink -f $1 )"
+else
+ AINSTALL=""
+fi
+CDDATA=${AINSTALL}/.larch/cd
+
+if [ ! -f ${CDDATA}/system.sqf ]; then
+ echo "ERROR: ${CDDATA} does not contain larch cd data"
+ usage
+fi
+if [ ! -f ${CDDATA}/isolinux/isolinux.cfg ]; then
+ echo "ERROR: isolinux data not in ${CDDATA}/isolinux"
+ exit 1
+fi
+
+if ! [ -f ${AINSTALL}/usr/bin/syslinux ]; then
+ echo "ERROR: syslinux not found -"
+ echo " it must be installed on live system"
+ return 1
+fi
+
+echo "//"
+echo "// **********************************************************"
+echo "//"
+echo "// ${APP} will prepare a bootable USB stick with your"
+echo "// previously prepared larch data from ${CDDATA}"
+echo "//"
+echo "// Please insert your USB stick, which should already be"
+echo "// appropriately partitioned."
+echo "//"
+echo "// **********************************************************"
+echo "//"
+
+# test if the script is started by root user. If not, exit
+if [ $UID -ne 0 ]; then
+ echo "Only root can run ${APP}"; exit 1
+fi
+
+echo "// Do you want to continue?"
+# Await yes or no
+read -p "// [y/N]: " ans
+if [ -z "`echo ${ans} | grep '^ *[yY]'`" ]; then exit 2; fi
+
+echo "//"
+echo "// Enter the number of the partition you wish to use (0 to quit):"
+
+devices=/tmp/devices$$
+:> ${devices}
+i=0
+sfdisk -d | grep "/dev/sd[a-z][1-4] " | grep -v "Id= [05]" | \
+ sed "s|\(.*\):.*size=\( *[0-9]*\).*|\1 \2|" | while read device sectors; do
+
+ i=$(( ${i} + 1 ))
+ echo "${device}" >>${devices}
+ echo "// ${i}: ${device} $(( ${sectors} / 2048 )) MiB"
+done
+
+while true; do
+ read -p "// Device: " d
+ if [ "${d}" -eq "0" ]; then exit 1; fi
+ i=0
+ { while read device; do
+ i=$(( ${i} + 1 ))
+ if [ "${d}" -eq "${i}" ]; then break 2; fi
+ done } <${devices}
+done
+
+rm ${devices}
+
+echo "//"
+read -p "// \"${device}\" will now be prepared. Continue? [y/N]: " ans
+if [ -z "`echo ${ans} | grep '^ *[yY]'`" ]; then exit 1; fi
+
+echo "//"
+echo "// Formatting ${device} (vfat)"
+dev=${device:0:8}
+part=${device:8}
+sfdisk ${dev} -N${part} <<EOF
+,,0e,*
+EOF
+
+dd if=/dev/zero of=${device} bs=512 count=1
+mkfs.vfat ${device}
+
+echo "// Copying the boot sector"
+dd if=${AINSTALL}/usr/lib/syslinux/mbr.bin of=${dev}
+
+echo "// Copying the files"
+stick=/tmp/mnt
+mkdir -p ${stick}
+umount ${device} &>/dev/null
+mount ${device} ${stick}
+if [ $? != 0 ]; then
+ echo "ERROR: Failed to mount device, quitting"
+ exit 3
+fi
+cp -a ${CDDATA}/* ${stick}
+mv ${stick}/isolinux ${stick}/syslinux
+mv ${stick}/syslinux/isolinux.cfg ${stick}/syslinux/syslinux.cfg
+rm -f ${stick}/syslinux/isolinux*
+
+umount ${stick}
+
+echo "// Running syslinux"
+if [ -n "${AINSTALL}" ]; then
+ mount --bind /dev ${AINSTALL}/dev
+ mount --bind /proc ${AINSTALL}/proc
+ chroot ${AINSTALL} syslinux ${device}
+ umount ${AINSTALL}/dev
+ umount ${AINSTALL}/proc
+else
+ syslinux ${device}
+fi
+
+echo "//"
+echo "// Done!"
+echo "// If all went well your usb stick should now be a bootable larch system"