wok view syslinux/stuff/iso2exe/taziso @ rev 18034

syslinux/taziso: add burn
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 09 21:54:15 2015 +0200 (2015-05-09)
parents f796d8c9c50e
children 551c5f787dd0
line source
1 #!/bin/sh
3 [ $(id -u) -eq 0 ] || exec su -c "$0 $@"
5 DIALOG=dialog
7 ddq()
8 {
9 dd $@ 2> /dev/null
10 }
12 get()
13 {
14 od -v -j $1 -N ${4:-${3:-2}} -t u${3:-2} -w${3:-2} -An $2 2>/dev/null ||
15 hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %d\n\"" $2
16 }
18 bytes2bin()
19 {
20 for i in $@ ; do
21 printf '\\\\x%02X' $(($i&255))
22 done | xargs echo -en
23 }
25 words2bin()
26 {
27 for i in $@ ; do
28 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255))
29 done | xargs echo -en
30 }
32 gettazboot()
33 {
34 echo "Creating $(basename $1) ..."
35 if [ $(get 0 "$ISO") -eq 23117 ]; then
36 O=$(($(get 64 "$ISO") - 0xC0))
37 L=$(($(get 20 "$ISO") - 0xC0 - $(get 24 "$ISO") - $O))
38 S=$((32+$L))
39 P=$((($S+511)/512))
40 E=$((4096-(32*$P)))
41 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
42 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
43 ddq bs=1 count=$L skip=$(echo $O) if="$ISO" >> $1
44 else
45 wget -O $1 http://mirror.slitaz.org/boot/tazboot.exe
46 fi
47 }
49 uncpio()
50 {
51 [ -s "$1" ] || return
52 echo -en "\n Extracting $(basename $1) ..."
53 case $(get 0 $1) in
54 *35615) ( zcat || gunzip ) ;;
55 *14333) unxz ;;
56 *\ 93) unlzma ;;
57 *) cat ;;
58 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
59 }
61 dotwait()
62 {
63 echo -n "${1:-Install filesystem}.."
64 touch /tmp/wait
65 [ "$REQUEST_URI" ] && return
66 while [ -e /tmp/wait ]; do
67 echo -n "." > /dev/tty
68 sleep 1
69 done &
70 }
72 getuuid()
73 {
74 dev=$(mount | sed "/ $(echo $mnt | sed 's|/|\\/|g') /!d;s/ .*//;s|/dev/||;q")
75 [ "$dev" ] &&
76 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/" ||
77 echo "/dev/hda1"
78 }
80 tazusbinitfs()
81 {
82 PAD=$(($(stat -c %s $1) % 4))
83 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
84 mkdir -p /tmp/fs$$/etc /tmp/fs$$/lib /tmp/fs$$/home
85 cp -a /etc/locale.conf /tmp/fs$$/etc 2> /dev/null
86 cp -a /etc/keymap.conf /tmp/fs$$/etc 2> /dev/null
87 cat > /tmp/fs$$/init1 <<EOT
88 #!/bin/sh
89 sed -i 's|sbin/init|init2|' /init
90 exec /init
91 EOT
92 cat > /tmp/fs$$/init2 <<EOT
93 #!/bin/sh
95 mount -t proc /proc /proc
96 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
97 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
98 mount / -o remount,rw
99 mkdir /mnt/dos
100 rm -f /cmdline 2> /dev/null
101 mount / -o remount,ro
102 mnt=/mnt/dos/\${v#*/}
103 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
104 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
105 mount \$dev /mnt/dos
106 if [ ! -d /mnt/dos/slitaz ]; then
107 umount /mnt/dos 2> /dev/null
108 (blkid /dev/[sh]d* || blkid) | while read dev line; do
109 case "\$line" in
110 *ntfs*|*vfat*|*msdos*) ;;
111 *) continue ;;
112 esac
113 mount \${dev%:} /mnt/dos
114 [ -d /mnt/dos/slitaz ] && break
115 umount /mnt/dos
116 done
117 fi
118 $([ "$2" ] || echo '# ')mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
119 mount --bind \$mnt /home
120 umount /proc
121 exec /sbin/init
122 EOT
123 chmod 755 /tmp/fs$$/init?
124 ( cd /tmp/fs$$ ; find * | cpio -o -H newc ) | gzip -9 >> $1
125 rm -rf /tmp/fs$$
126 }
128 mkinitrd()
129 {
130 echo -en "\nCreating $(basename $1) "
131 fs=/tmp/fs$$
132 for i in bin lib dev proc tmp mnt etc ; do
133 mkdir -p $fs/$i
134 done
135 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \
136 /dev/fuse /dev/hd* /dev/sd* ; do
137 cp -a $2$i $fs/dev/
138 done
139 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
140 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
141 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') $fs/lib
142 cp $i $fs/bin
143 done
144 cp -a /lib/ld-* $fs/lib
145 for i in $(busybox | sed '/Current/,$!d'); do
146 [ -e $fs/bin/${i%,} ] || ln -s busybox $fs/bin/${i%,}
147 done
148 ln -s /proc/mounts $fs/etc/mtab
149 sed 's/ .*//' /proc/modules | while read mod ; do
150 find /lib/modules/ | grep $mod.ko | \
151 sed 's|.*|cp & $fs/lib|' | sh
152 done
153 cat > $fs/init <<EOT
154 #!/bin/sh
156 arg()
157 {
158 grep -q \$1 /proc/cmdline &&
159 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
160 echo "\$2 \$val"
161 }
163 mount -t proc /proc /proc
164 arg debug "shell" && debug=true && set -x
165 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
166 arg mount "Mount device"
167 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
168 arg subroot "Change root to directory"
169 if [ -d /mnt/\$val ]; then
170 umount /mnt 2> /dev/null
171 (blkid /dev/[sh]d* || blkid) | while read dev line; do
172 case "\$line" in
173 *ntfs*|*vfat*|*msdos*) ;;
174 *) continue ;;
175 esac
176 mount \${dev%:} /mnt
177 [ -d /mnt/\$val ] && break
178 umount /mnt
179 done
180 fi
181 $([ "$3" ] || echo '# ')mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
182 mount --bind /mnt /mnt/\$val/mnt/dos
183 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
184 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
185 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
186 [ "$debug" = "true" ] && sh
187 umount /proc
188 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
189 EOT
190 chmod +x $fs/init
191 ( cd $fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
192 rm -rf $fs /tmp/wait
193 }
195 ls_r()
196 {
197 ls -r $@ 2> /dev/null || ls $@
198 }
200 doinstall()
201 {
202 unset useposixovl
203 blkid | grep $(df $mnt | sed '$!d;s/ .*/:/') | \
204 grep -qiE "(msdos|vfat|ntfs)" && useposixovl=YES
206 mkdir -p $mnt/slitaz/boot $mnt/slitaz/mnt/dos
207 [ "$useposixovl" ] &&
208 if ! mount.posixovl -F $mnt/slitaz -- \
209 -oallow_other -odefault_permissions -osuid; then
210 echo "Can't install SliTaz. Abort."
211 sleep 5
212 return 1
213 fi
214 dotwait "Install root filesystem in /slitaz.."
215 if [ "$1" ]; then
216 ls_r /media/cdrom/boot/rootfs*gz | \
217 xargs cat > $mnt/slitaz/boot/rootfs.gz
218 tazusbinitfs $mnt/slitaz/boot/rootfs.gz $useposixovl
219 initrd=rootfs.gz
220 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
221 else
222 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
223 uncpio $i $mnt/slitaz
224 done
225 for i in $packages_list; do
226 tazpkg get-install $i --root=$mnt/slitaz
227 done
228 for i in $packages_dir/*.tazpkg; do
229 [ -s "$i" ] &&
230 tazpkg install $i --root=$mnt/slitaz
231 done
232 cp -a /etc/locale.conf $mnt/slitaz/etc 2> /dev/null
233 cp -a /etc/keymap.conf $mnt/slitaz/etc 2> /dev/null
234 mkinitrd $mnt/slitaz/boot/initrd $mnt/slitaz $useposixovl
235 initrd=initrd
236 extraargs="mount=$(getuuid) subroot=slitaz"
237 fi
238 echo -en "\nInstall boot files..."
239 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
240 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
241 /media/cdrom/README /media/cdrom/boot/memtest* ; do
242 [ -s $i ] && cp $i $mnt/slitaz/boot
243 done
244 for i in $mnt/slitaz/boot/memtest $mnt/slitaz/boot/*pxe* ; do
245 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
246 mv $i $i.exe
247 done
248 gettazboot $mnt/slitaz/boot/tazboot.exe
249 unix2dos > $mnt/slitaz/boot/tazboot.cmd <<EOT
250 kernel=/slitaz/boot/bzimage
251 initrd=/slitaz/boot/$initrd
252 rw root=/dev/null $extraargs autologin
253 EOT
254 unix2dos $mnt/slitaz/boot/he* $mnt/slitaz/boot/opt* \
255 $mnt/slitaz/boot/README
256 [ -d $mnt/slitaz/usr/sbin -a ! -x $mnt/slitaz/usr/sbin/mount.posixovl ] &&
257 cp $(which mount.posixovl) $mnt/slitaz/usr/sbin
258 if "$useposixovl" && grep -qs " $mnt " /proc/mounts &&
259 [ ! -d $mnt/boot/grub ]; then
260 mkdir -p $mnt/boot/grub
261 echo -en "\nInstall grub in /boot/grub..."
262 cp -a /usr/lib/grub/*/* $mnt/boot/grub
263 cat > $mnt/boot/grub/menu.lst <<EOT
264 # /boot/grub/menu.lst: GRUB boot loader configuration.
266 # By default, boot the first entry.
267 default 0
269 # Boot automatically after 8 secs.
270 timeout 8
272 title Microsoft Windows
273 chainloader +1
275 EOT
276 dev=$(grep " $mnt " /proc/mounts | awk '{ print $1 }')
277 base=${dev//[0-9]/}
278 dd if=$base bs=32k count=1 of=$mnt/boot/grub/$(basename $base)
279 cat > $mnt/boot/grub/uninstall-grub.sh <<EOT
280 #!/bin/sh
282 [ -s /boot/grub/$(basename $base) ] &&
283 dd if=/boot/grub/$(basename $base) of=$base
284 EOT
285 grub-install --no-floppy --root-directory=$mnt $base