* updated kubrick (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / misc / archive / iso2stick.sh
blob0bf14e6f40fe561a2d659b650e8d72ace5cb2581
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 #
5 # T2 SDE: misc/archive/iso2stick.sh
6 # Copyright (C) 2006 - 2020 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 set -e
18 usage() {
19 echo "Usage iso2stick [ -fs file-system | -n ] iso-image usb-device [ files ]"
20 exit
23 fs="vfat -F 32"
25 while [ "$1" ]; do
26 case "$1" in
27 -fs) fs="$2" ; shift ;;
28 -n) fs="" ;;
29 -*) usage ;;
30 *) break ;;
31 esac
32 shift
33 done
35 if [ -z "$1" -o -z "$2" ]; then
36 usage
39 file="$1" ; shift
40 dev="$1" ; shift
42 # # create fresh image
43 # size=`du --block-size=1000000 $1 | cut -f 1`
44 # size=$(( size + 20 )) # just to be sure
46 # dd if=/dev/zero of=hd.img bs=1000000 count=$size
48 # loop=`losetup -f`
49 # losetup $loop hd.img
51 case "$fs" in
52 vfat*) ptype=b ;;
53 *) ptype=83 ;;
54 esac
56 if [ "$fs" ]; then
57 sfdisk $dev << EOT
58 ,,$ptype
59 EOT
61 # losetup -d $loop
63 mkfs.$fs ${dev}1
66 # losetup /dev/loop0 -o 512 hd.img
68 mkdir -p /mnt/{source,target}
69 mount ${dev}1 /mnt/target
70 mount -o loop $file /mnt/source
72 rsync -arvH --inplace --exclude TRANS.TBL /mnt/source/ /mnt/target/
73 # copy additional content specified in arguments
74 for x ; do
75 cp -arv $x /mnt/target/
76 done
78 sed -i 's/(cd)/(hd0,0)/g' /mnt/target/boot/grub/menu.lst
80 umount /mnt/source
81 umount /mnt/target
83 echo -e "(hd0) $dev" > device.map
84 echo -e "root (hd0,0)\ninstall /boot/grub/stage1 (hd0) (hd0,0)/boot/grub/stage2 (hd0,0)/boot/grub/menu.lst\nquit" | grub --batch --device-map=./device.map
86 rm ./device.map