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

cpige: add man page for cook.slitaz.org
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 13 16:56:42 2019 +0100 (21 months ago)
parents 378b0ba41272
children 02c70d036ea0
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 O=$(($(get 64 "$ISO") - 0xC0))
36 L=$(($(get 20 "$ISO") - 0xC0 - $(get 24 "$ISO") - $O))
37 S=$((32+$L))
38 P=$((($S+511)/512))
39 E=$((4096-(32*$P)))
40 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
41 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
42 ddq bs=1 count=$L skip=$(echo $O) if="$ISO" >> $1
43 }
45 uncpio()
46 {
47 [ -s "$1" ] || return
48 echo -en "\n Extracting $(basename $1) ..."
49 case $(get 0 $1) in
50 *35615) ( zcat || gunzip ) ;;
51 *14333) unxz ;;
52 *\ 93) unlzma ;;
53 *) cat ;;
54 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
55 }
57 dotwait()
58 {
59 echo -n "${1:-Install filesystem}.."
60 touch /tmp/wait
61 [ "$REQUEST_URI" ] && return
62 while [ -e /tmp/wait ]; do
63 echo -n "." > /dev/tty
64 sleep 1
65 done &
66 }
68 getuuid()
69 {
70 dev=$(mount | sed "/ $(echo $mnt | sed 's|/|\\/|g') /!d;s/ .*//;s|/dev/||;q")
71 [ "$dev" ] &&
72 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/" ||
73 echo "/dev/hda1"
74 }
76 tazusbinitfs()
77 {
78 PAD=$(($(stat -c %s $1) % 4))
79 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
80 mkdir -p /tmp/fs$$/etc /tmp/fs$$/lib /tmp/fs$$/home
81 cp -a /etc/locale.conf /tmp/fs$$/etc 2> /dev/null
82 cp -a /etc/keymap.conf /tmp/fs$$/etc 2> /dev/null
83 cat > /tmp/fs$$/init1 <<EOT
84 #!/bin/sh
85 sed -i 's|sbin/init|init2|' /init
86 exec /init
87 EOT
88 cat > /tmp/fs$$/init2 <<EOT
89 #!/bin/sh
91 mount -t proc /proc /proc
92 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
93 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
94 mount / -o remount,rw
95 mkdir /mnt/dos
96 rm -f /cmdline 2> /dev/null
97 mount / -o remount,ro
98 mnt=/mnt/dos/\${v#*/}
99 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
100 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
101 mount \$dev /mnt/dos
102 if [ ! -d /mnt/dos/slitaz ]; then
103 umount /mnt/dos 2> /dev/null
104 (blkid /dev/[sh]d* || blkid) | while read dev line; do
105 case "\$line" in
106 *ntfs*|*vfat*|*msdos*) ;;
107 *) continue ;;
108 esac
109 mount \${dev%:} /mnt/dos
110 [ -d /mnt/dos/slitaz ] && break
111 umount /mnt/dos
112 done
113 fi
114 $([ "$2" ] || echo '# ')mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
115 mount --bind \$mnt /home
116 umount /proc
117 exec /sbin/init
118 EOT
119 chmod 755 /tmp/fs$$/init?
120 ( cd /tmp/fs$$ ; find * | cpio -o -H newc ) | gzip -9 >> $1
121 rm -rf /tmp/fs$$
122 }
124 mkinitrd()
125 {
126 echo -en "\nCreating $(basename $1) "
127 fs=/tmp/fs$$
128 for i in bin lib dev proc tmp mnt etc ; do
129 mkdir -p $fs/$i
130 done
131 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \
132 /dev/fuse /dev/hd* /dev/sd* ; do
133 cp -a $2$i $fs/dev/
134 done
135 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
136 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
137 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') $fs/lib
138 cp $i $fs/bin
139 done
140 cp -a /lib/ld-* $fs/lib
141 for i in $(busybox | sed '/Current/,$!d'); do
142 [ -e $fs/bin/${i%,} ] || ln -s busybox $fs/bin/${i%,}
143 done
144 ln -s /proc/mounts $fs/etc/mtab
145 sed 's/ .*//' /proc/modules | while read mod ; do
146 find /lib/modules/ | grep $mod.ko | \
147 sed 's|.*|cp & $fs/lib|' | sh
148 done
149 cat > $fs/init <<EOT
150 #!/bin/sh
152 arg()
153 {
154 grep -q \$1 /proc/cmdline &&
155 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
156 echo "\$2 \$val"
157 }
159 mount -t proc /proc /proc
160 arg debug "shell" && debug=true && set -x
161 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
162 arg mount "Mount device"
163 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
164 arg subroot "Change root to directory"
165 if [ -d /mnt/\$val ]; then
166 umount /mnt 2> /dev/null
167 (blkid /dev/[sh]d* || blkid) | while read dev line; do
168 case "\$line" in
169 *ntfs*|*vfat*|*msdos*) ;;
170 *) continue ;;
171 esac
172 mount \${dev%:} /mnt
173 [ -d /mnt/\$val ] && break
174 umount /mnt
175 done
176 fi
177 $([ "$3" ] || echo '# ')mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
178 mount --bind /mnt /mnt/\$val/mnt/dos
179 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
180 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
181 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
182 [ "$debug" = "true" ] && sh
183 umount /proc
184 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
185 EOT
186 chmod +x $fs/init
187 ( cd $fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
188 rm -rf $fs /tmp/wait
189 }
191 ls_r()
192 {
193 ls -r $@ 2> /dev/null || ls $@
194 }
196 doinstall()
197 {
198 unset useposixovl
199 blkid | grep $(df $mnt | sed '$!d;s/ .*/:/') | \
200 grep -qiE "(msdos|vfat|ntfs)" && useposixovl=YES
201 case "$mnt" in
202 *mkzip*) useposixovl=YES
203 esac
204 mkdir -p $mnt/slitaz/boot $mnt/slitaz/mnt/dos
205 [ "$useposixovl" ] &&
206 if ! mount.posixovl -F $mnt/slitaz -- \
207 -oallow_other -odefault_permissions -osuid; then
208 echo "Can't install SliTaz. Abort."
209 sleep 5
210 return 1
211 fi
212 dotwait "Install root filesystem in /slitaz.."
213 if [ "$1" ]; then
214 ls_r $media/boot/rootfs*gz | \
215 xargs cat > $mnt/slitaz/boot/rootfs.gz
216 tazusbinitfs $mnt/slitaz/boot/rootfs.gz $useposixovl
217 initrd=rootfs.gz
218 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
219 else
220 for i in $(ls_r $media/boot/rootfs*gz); do
221 uncpio $i $mnt/slitaz
222 done
223 for i in $packages_list; do
224 tazpkg get-install $i --root=$mnt/slitaz
225 done
226 for i in $packages_dir/*.tazpkg; do
227 [ -s "$i" ] &&
228 tazpkg install $i --root=$mnt/slitaz
229 done
230 cp -a /etc/locale.conf $mnt/slitaz/etc 2> /dev/null
231 cp -a /etc/keymap.conf $mnt/slitaz/etc 2> /dev/null
232 mkinitrd $mnt/slitaz/boot/initrd $mnt/slitaz $useposixovl
233 initrd=initrd
234 extraargs="mount=$(getuuid) subroot=slitaz"
235 fi
236 echo -en "\nInstall boot files..."
237 for i in $media/boot/bzImage* $media/boot/*pxe* \
238 $media/boot/isolinux/he* $media/boot/isolinux/opt* \
239 $media/README $media/boot/memtest* ; do
240 [ -s $i ] && cp $i $mnt/slitaz/boot
241 done
242 for i in $mnt/slitaz/boot/memtest $mnt/slitaz/boot/*pxe* ; do
243 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
244 mv $i $i.exe
245 done
246 bzimage=$(cd $mnt/slitaz/boot ; ls bzimage*)
247 gettazboot $mnt/slitaz/boot/tazboot.exe # autoappend 64 suffix
248 unix2dos > $mnt/slitaz/boot/tazboot.cmd <<EOT
249 kernel=/slitaz/boot/bzimage
250 initrd=/slitaz/boot/$initrd
251 rw root=/dev/null $extraargs autologin
252 EOT
253 unix2dos $mnt/slitaz/boot/he* $mnt/slitaz/boot/opt* \
254 $mnt/slitaz/boot/README
255 [ -d $mnt/slitaz/usr/sbin -a ! -x $mnt/slitaz/usr/sbin/mount.posixovl ] &&
256 cp $(which mount.posixovl) $mnt/slitaz/usr/sbin
257 if [ "$useposixovl" ] && grep -qs " $mnt " /proc/mounts &&
258 [ ! -d $mnt/boot/grub ]; then
259 mkdir -p $mnt/boot/grub
260 echo -en "\nInstall grub in /boot/grub..."
261 cp -a /usr/lib/grub/*/* $mnt/boot/grub
262 cat > $mnt/boot/grub/menu.lst <<EOT
263 # /boot/grub/menu.lst: GRUB boot loader configuration.
265 # By default, boot the first entry.
266 default 0
268 # Boot automatically after 8 secs.
269 timeout 8
271 title Microsoft Windows
272 chainloader +1
274 EOT
275 dev=$(grep " $mnt " /proc/mounts | awk '{ print $1 }')
276 base=${dev//[0-9]/}
277 dd if=$base bs=32k count=1 of=$mnt/boot/grub/$(basename $base)
278 cat > $mnt/boot/grub/uninstall-grub.sh <<EOT
279 #!/bin/sh
281 [ -s /boot/grub/$(basename $base) ] &&
282 dd if=/boot/grub/$(basename $base) of=$base
283 EOT
284 grub-install --no-floppy --root-directory=$mnt $base
285 fi
286 if [ -s $mnt/boot/grub/menu.lst ] &&
287 ! grep -q /slitaz/boot/$bzimage $mnt/boot/grub/menu.lst; then
288 echo -en "\nUpdate /boot/grub/menu.lst..."
289 cat >> $mnt/boot/grub/menu.lst <<EOT
290 title SliTaz GNU/Linux $(cat $mnt/slitaz/etc/slitaz-release)
291 kernel /slitaz/boot/$bzimage rw root=/dev/null $extraargs autologin
292 initrd /slitaz/boot/$initrd
294 EOT
295 fi
296 rm -f /tmp/wait
297 [ "$useposixovl" ] && umount $mnt/slitaz
298 return 0
299 }
301 windev()
302 {
303 if [ -b "$1" ]; then
304 device=$1
305 elif [ "$1" ]; then
306 echo "Invalid Linux/Windows partition"
307 return 1
308 else
309 DEV="$(blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | sed 's/:.*//;s|/dev/||')"
310 [ "$DEV" ] || return
311 cat > /tmp/dialog$$ <<EOT
312 $DIALOG --clear --title " Select your Linux/Windows partition " \
313 --menu "\nPlease select the Linux/Windows partition according to its known size.
314 The data will be kept untouched.\n" 17 70 8 \
315 $(for i in $DEV ; do
316 label="$(blkid | sed "/$i:/!d;s/.*://;s/[^ ]*UUID=[^ ]* //g;s/LABEL=//")"
317 echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" "
318 done)
319 EOT
320 exec 3>&1
321 [ $? -eq 0 ] || return
322 device=$(. /tmp/dialog$$ 2>&1 1>&3)
323 exec 3>&-
324 rm -f /tmp/dialog$$
325 fi
326 mnt=/tmp/mnt$$
327 mkdir -p $mnt && mount $device $mnt
328 }
330 extra_packages()
331 {
332 packages_list=
333 packages_dir=
334 $DIALOG --clear --title " Extra packages " \
335 --defaultno --yesno \
336 "Do you want to add extra packages ?" 7 70
337 [ $? -eq 0 ] || return
338 [ -s /var/lib/tazpkg/packages.txt ] || tazpkg recharge
339 if [ -s $media/boot/vmlinuz-$(uname -r) ]; then
340 cat > /tmp/dialog$$ <<EOT
341 $DIALOG --clear --title " Select the packages " \
342 --separate-output \
343 --cancel-label "Skip" \
344 --checklist "Please select the packages you want to install. Try with the first letter." \
345 0 0 0 \\
346 EOT
347 awk -F\| '{ printf "%s \"%s\" off ",$1,$3 }' \
348 /var/lib/tazpkg/packages.desc >> /tmp/dialog$$
349 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
350 [ $? -eq 0 ] && packages_list="$(cat /tmp/dialog.out$$)"
351 fi
352 cat > /tmp/dialog$$ <<EOT
353 $DIALOG --clear \
354 --title "Please select the directory with every custom package to install." \
355 --cancel-label "Skip" --dselect $PWD 13 78
356 EOT
357 sh /tmp/dialog$$ 2> /tmp/dialog.out$$
358 [ $? -eq 0 ] && packages_dir="$(cat /tmp/dialog.out$$)"
359 rm -f /tmp/dialog$$ /tmp/dialog.out$$
360 }
362 _install()
363 {
364 extra_packages
365 $DIALOG --clear --title " SliTaz UMSDOS way installation " \
366 --yes-label "Install" --yesno \
367 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
368 Linux/DOS/Windows partition. You can see your files from /mnt/dos.\n\n
369 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
370 To uninstall SliTaz, you have only to remove this directory.
371 The file \\boot.ini or \\config.sys may be modified too.\n\n
372 SliTaz may run slowly on the 'UMSDOS way' installation due to the
373 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
374 To do a traditional installation with disk partitioning,
375 start SliTaz Live with the 'SliTaz RAM boot' menu.\n" 19 70
376 [ $? -eq 0 ] || return
377 doinstall
378 }
380 readtazbootconf()
381 {
382 kernel="$(sed '/^kernel=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
383 initrd="$(sed '/^initrd=/!d;s/.*=//' $mnt/slitaz/boot/tazboot.cmd)"
384 cmdline="$(sed '/^kernel=/d;/^initrd=/d' $mnt/slitaz/boot/tazboot.cmd)"
385 }
387 bootinstalled()
388 {
389 [ "$(which kexec)" ] || return
390 [ -x $mnt/slitaz$1 ] || return
391 [ -s $mnt/slitaz/boot/tazboot.cmd ] || return
392 readtazbootconf
393 kexec -l $kernel --initrd $initrd --command-line "$cmdline" || return
394 umount $mnt
395 rm -rf $mnt
396 quit "kexec -e"
397 }
399 mkzip()
400 {
401 device=
402 packages_list=
403 packages_dir=
404 mnt=/tmp/mkzipmnt$$
405 mkdir -p $mnt
406 $1 $2 || return
407 for i in bootlace.com grubinst.exe grldr ; do
408 wget -O $mnt/slitaz/boot/$i http://mirror.slitaz.org/boot/$i
409 done
410 readtazbootconf
411 cat > $mnt/slitaz/boot/menu.lst <<EOT
412 title SliTaz
413 kernel $kernel $cmdline
414 initrd $initrd
416 EOT
417 while read file title; do
418 file=$(ls $mnt/slitaz/boot/*$file* 2> /dev/null)
419 [ -s "$file" ] && cat >> $mnt/slitaz/boot/menu.lst <<EOT
420 title $title
421 kernel ${file#$mnt}
423 EOT
424 done <<EOT
425 memtest MemTest
426 pxe Web boot
427 EOT
428 unix2dos $mnt/slitaz/boot/menu.lst
429 unix2dos > $mnt/slitaz/boot/install.txt <<EOT
430 For DOS users (real mode only):
432 Start SliTaz with \\slitaz\\boot\\tazboot.exe
435 For NT/2000/XP users:
437 1- Move the files grldr and menu.lst into the root directory
439 C:\\> copy \\slitaz\\boot\\grldr \\
440 C:\\> copy \\slitaz\\boot\\menu.lst \\
442 2- Remove boot.ini attributes
444 C:\\> attrib -r -h -s boot.ini
446 3- Append the following line to boot.init
448 C:\\grldr="slitaz"
450 4- Restore boot.ini attributes
452 C:\\> attrib +r