wok-6.x annotate syslinux/stuff/iso2exe/init @ rev 20620

pypi.python.org access with untrusted https
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Dec 31 11:54:16 2018 +0100 (2018-12-31)
parents 6c622282f662
children 378b0ba41272
rev   line source
pascal@13691 1 #!/bin/sh
pascal@13691 2
pascal@13691 3 DIALOG=dialog
pascal@13691 4
pascal@17454 5 ddq()
pascal@17454 6 {
pascal@17454 7 dd $@ 2> /dev/null
pascal@17454 8 }
pascal@17454 9
pascal@13691 10 get()
pascal@13691 11 {
pascal@17496 12 od -v -j $1 -N ${4:-${3:-2}} -t u${3:-2} -w${3:-2} -An $2 2>/dev/null ||
pascal@17496 13 hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %d\n\"" $2
pascal@13691 14 }
pascal@13691 15
pascal@13691 16 getarg()
pascal@13691 17 {
pascal@13691 18 sed "/$1=/!d;s/.*$1=\\([^ ]*\\).*/\\1/" /proc/cmdline
pascal@13691 19 }
pascal@13691 20
pascal@17489 21 clear()
pascal@17489 22 {
pascal@17489 23 echo -e "\x1B[1;1H\x1B[J"
pascal@17489 24 }
pascal@17489 25
pascal@17569 26 xless()
pascal@17569 27 {
pascal@17569 28 [ $(wc -l < "$1") -gt 22 ] &&
pascal@17569 29 sed 's/..3.;4.m/===/g;$s/.*/&\n---\nPress q to continue/' "$1" | less ||
pascal@17569 30 { cat "$1"
pascal@17569 31 [ "$2" ] || return
pascal@17569 32 echo -e "$2"
pascal@17569 33 read n
pascal@17569 34 }
pascal@17569 35 }
pascal@17569 36
pascal@17489 37 tinydialog()
pascal@17489 38 {
pascal@17489 39 clear
pascal@17489 40 label=""
pascal@17489 41 while [ "$1" ]; do
pascal@17489 42 case "$1" in
pascal@17489 43 --title) title=" \x1B[30;47m$2\x1B[37;40m\n"
pascal@17489 44 echo -e $title; shift ;;
pascal@17489 45 --yes-label) label="$2" ; shift ;;
pascal@17489 46 --textbox)
pascal@17569 47 xless "$2" "\nPress RETURN to continue."
pascal@17489 48 break;;
pascal@17489 49 --gauge)
pascal@17489 50 t=" "
pascal@17489 51 echo -e "$t$2\n"
pascal@17489 52 while read pct ; do
pascal@17489 53 s=" "
pascal@17489 54 s="$s$pct%$s"
pascal@17489 55 pct=$((($pct*63)/100))
pascal@17489 56 echo -en "\r$t\x1B[30;47m$(echo "$s" | cut -c-$pct)\x1B[37;40m$(echo "$s" | cut -c$(($pct+1))-)"
pascal@17489 57 done
pascal@17489 58 break;;
pascal@17489 59 --yesno)
pascal@17489 60 while true; do
pascal@17489 61 clear
pascal@17491 62 echo "$2" | sed 's/\\n\\n/\\n/g;s/\\n/\n/g'
pascal@17491 63 echo -en " <- 1:${label:-Yes} 2:Cancel\r"
pascal@17489 64 read x
pascal@17489 65 case "$x" in
pascal@17489 66 ''|Y*|y*|1) return 0;;
pascal@17489 67 N*|n*|2|0) return 1;;
pascal@17489 68 esac
pascal@17489 69 done ;;
pascal@17489 70 --menu|--radiolist)
pascal@17491 71 [ "$1" == "--menu" ] && shft=2 || shft=3
pascal@17491 72 label=""
pascal@17491 73 [ "$2" ] && label="\n$2"
pascal@17489 74 shift 5
pascal@17491 75 echo -e "$title$label\n0 Cancel" > /tmp/data
pascal@17489 76 n=1
pascal@17489 77 while [ "$1" ]; do
pascal@17489 78 eval key_$n='$1'
pascal@17489 79 echo "$((n++)) $2"
pascal@17491 80 shift $shft
pascal@17489 81 done >> /tmp/data
pascal@17489 82 while ! grep -q "^$n " /tmp/data ; do
pascal@17489 83 clear
pascal@17569 84 xless /tmp/data
pascal@17489 85 echo -en "\n <- Enter the selection number\r"
pascal@17489 86 read n
pascal@17489 87 done 2> /dev/null
pascal@17489 88 rm -f /tmp/data
pascal@17489 89 [ $n -eq 0 ] && return 1
pascal@17489 90 eval echo -n \$key_$n 1>&2
pascal@17489 91 return 0;;
pascal@17489 92 esac
pascal@17489 93 shift
pascal@17489 94 done
pascal@17489 95 }
pascal@17489 96
pascal@16041 97 mount_proc()
pascal@16041 98 {
pascal@16041 99 mount -t proc /proc /proc
pascal@16041 100 mount -t sysfs /sys /sys
pascal@16041 101 udevd --daemon 2> /dev/null && udevadm trigger && sleep 5
pascal@16041 102 }
pascal@16041 103
pascal@16041 104 umount_proc()
pascal@16041 105 {
pascal@16041 106 killall udevd 2> /dev/null
pascal@16041 107 umount /sys/fs/fuse/connections 2> /dev/null
pascal@16041 108 umount /sys
pascal@16041 109 umount /proc
pascal@16041 110 }
pascal@16041 111
pascal@17473 112 bytes2bin()
pascal@17473 113 {
pascal@17473 114 for i in $@ ; do
pascal@17569 115 printf '\\\\x%02X' $(($i&255))
pascal@17569 116 done | xargs echo -en
pascal@17473 117 }
pascal@17473 118
pascal@17454 119 words2bin()
pascal@17454 120 {
pascal@17454 121 for i in $@ ; do
pascal@17569 122 printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255))
pascal@17569 123 done | xargs echo -en
pascal@17454 124 }
pascal@17454 125
pascal@13691 126 gettazboot()
pascal@13691 127 {
paul@13692 128 echo "Creating $(basename $1) ..."
pascal@17810 129 O=$(($(get 64 /mnt/$ISO) - 0xC0))
pascal@17492 130 L=$(($(get 20 /mnt/$ISO) - 0xC0 - $(get 24 /mnt/$ISO) - $O))
pascal@13691 131 S=$((32+$L))
pascal@13691 132 P=$((($S+511)/512))
pascal@13691 133 E=$((4096-(32*$P)))
pascal@17454 134 words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
pascal@17454 135 -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
pascal@17454 136 ddq bs=1 count=$L skip=$(echo $O) if=/mnt/$ISO >> $1
pascal@13691 137 }
pascal@13691 138
pascal@13691 139 checkmagic()
pascal@13691 140 {
pascal@19872 141 [ -s $1 ] && [ $(getarg magic) == $(get 18 $1 2) ]
pascal@13691 142 }
pascal@13691 143
pascal@13691 144 getiso()
pascal@13691 145 {
pascal@13713 146 mkdir -p /media/cdrom
pascal@17489 147 for dev in /sys/block/?d?/?d??* ; do
pascal@17489 148 mount /dev/$(basename $dev) /mnt
pascal@13713 149 if checkmagic /mnt/$ISO; then
pascal@13713 150 mount -o loop,ro /mnt/$ISO /media/cdrom
pascal@17489 151 echo "Found $ISO on $(basename $dev)"
pascal@19510 152 return 0
pascal@13713 153 fi
pascal@13713 154 umount /mnt
pascal@19510 155 done 2> /dev/null
pascal@19510 156 return 1
pascal@13691 157 }
pascal@13691 158
pascal@13691 159 uncpio()
pascal@13691 160 {
pascal@17489 161 [ -s "$1" ] || return
pascal@17476 162 echo -en "\n Extracting $(basename $1) ..."
pascal@13699 163 case $(get 0 $1) in
pascal@17160 164 *35615) ( zcat || gunzip ) ;;
pascal@17476 165 *14333) unxz ;;
pascal@17160 166 *\ 93) unlzma ;;
pascal@17160 167 *) cat ;;
pascal@17160 168 esac < $1 | ( cd ${2:-/} ; cpio -idmu > /dev/null 2>&1 )
pascal@13691 169 }
pascal@13691 170
pascal@17476 171 dotwait()
pascal@17476 172 {
pascal@17476 173 echo -n "${1:-Install filesystem}.."
pascal@17476 174 touch /tmp/wait
pascal@17476 175 while [ -e /tmp/wait ]; do
pascal@17476 176 echo -n "." > /dev/tty0
pascal@17476 177 sleep 1
pascal@17476 178 done &
pascal@17476 179 }
pascal@17476 180
pascal@13691 181 getuuid()
pascal@13691 182 {
pascal@13691 183 dev=$(mount | sed '/ \/mnt /!d;s/ .*//;s|/dev/||;q')
pascal@16041 184 blkid | sed "/$dev:/!d;s/.* UUID=.\\([^ ]*\\)\".*/\\1/"
pascal@13691 185 }
pascal@13691 186
pascal@16055 187 tazusbinitfs()
pascal@16055 188 {
pascal@16055 189 PAD=$(($(stat -c %s $1) % 4))
pascal@17454 190 [ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
pascal@16055 191 mkdir -p /tmp/fs/etc /tmp/fs/lib /tmp/fs/home
pascal@16055 192 cp -a /etc/locale.conf /tmp/fs/etc 2> /dev/null
pascal@16055 193 cp -a /etc/keymap.conf /tmp/fs/etc 2> /dev/null
pascal@16055 194 sed 's/ .*//' /proc/modules | while read mod ; do
pascal@16055 195 find /lib/modules/ | grep $mod.ko | \
pascal@16055 196 sed 's|.*|cp & /tmp/fs/lib|' | sh
pascal@16055 197 done
pascal@16055 198 cat > /tmp/fs/init1 <<EOT
pascal@16055 199 #!/bin/sh
pascal@16055 200 sed -i 's|sbin/init|init2|' /init
pascal@16055 201 exec /init
pascal@16055 202 EOT
pascal@16055 203 cat > /tmp/fs/init2 <<EOT
pascal@16055 204 #!/bin/sh
pascal@16055 205
pascal@16055 206 mount -t proc /proc /proc
pascal@16055 207 grep -q debug /proc/cmdline && debug=true && set -x
pascal@16055 208 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
pascal@16055 209 v=\$(sed '/\\/home=/!d;s|.*/home=\\([^ ]*\\).*|\\1|' /proc/cmdline /cmdline 2> /dev/null)
pascal@16055 210 mount / -o remount,rw
pascal@16055 211 mkdir /mnt/dos
pascal@16055 212 rm -f /cmdline 2> /dev/null
pascal@16055 213 mount / -o remount,ro
pascal@16055 214 mnt=/mnt/dos/\${v#*/}
pascal@16055 215 dev=\$( (blkid /dev/[sh]d* || blkid) | grep \${v%%/*} | sed 's/:.*//;q')
pascal@16055 216 echo "Mount \$dev in /mnt/dos for \$v..." | tee -a /run/boot.log
pascal@16055 217 mount \$dev /mnt/dos
pascal@16055 218 mount.posixovl -F \$mnt -- -oallow_other -odefault_permissions -osuid
pascal@16055 219 mount --bind \$mnt /home
pascal@16055 220 [ "\$debug" = "true" ] && sh
pascal@16055 221 umount /proc
pascal@16055 222 exec /sbin/init
pascal@16055 223 EOT
pascal@16055 224 chmod 755 /tmp/fs/init?
pascal@16055 225 cp -a /tmp/fs/* /
pascal@16055 226 ( cd /tmp/fs ; find * | cpio -o -H newc ) | gzip -9 >> $1
pascal@16055 227 }
pascal@16055 228
pascal@13691 229 mkinitrd()
pascal@13691 230 {
pascal@17476 231 dotwait "Creating $(basename $1) "
pascal@13691 232 for i in bin lib dev proc tmp mnt etc ; do
pascal@13691 233 mkdir -p /tmp/fs/$i
pascal@13691 234 done
pascal@17476 235 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/tty1 /dev/tty2 \
pascal@17476 236 /dev/fuse /dev/hd* /dev/sd* ; do
pascal@13691 237 cp -a $i /tmp/fs$i
pascal@13691 238 done
pascal@13713 239 for i in /bin/busybox $(which mount.posixovl) $(which blkid); do
pascal@13691 240 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $i | \
pascal@13691 241 sed 's|.*=> \(.*/lib/l[^ ]*\).*|\1|;/^\//!d') /tmp/fs/lib
pascal@13691 242 cp $i /tmp/fs/bin
pascal@13691 243 done
pascal@13691 244 cp -a /lib/ld-* /tmp/fs/lib
pascal@13691 245 for i in $(busybox | sed '/Current/,$!d'); do
pascal@14271 246 [ -e /tmp/fs/bin/${i%,} ] || ln -s busybox /tmp/fs/bin/${i%,}
pascal@13691 247 done
pascal@13691 248 ln -s /proc/mounts /tmp/fs/etc/mtab
pascal@16041 249 sed 's/ .*//' /proc/modules | while read mod ; do
pascal@16041 250 find /lib/modules/ | grep $mod.ko | \
pascal@16041 251 sed 's|.*|cp & /tmp/fs/lib|' | sh
pascal@16041 252 done
pascal@13691 253 cat > /tmp/fs/init <<EOT
pascal@13691 254 #!/bin/sh
pascal@13691 255
pascal@13691 256 arg()
pascal@13691 257 {
pascal@13691 258 grep -q \$1 /proc/cmdline &&
pascal@13691 259 val="\$(sed "s/.*\$1=\\([^ ]*\\).*/\\1/" < /proc/cmdline)" &&
pascal@13691 260 echo "\$2 \$val"
pascal@13691 261 }
pascal@13691 262
pascal@13691 263 mount -t proc /proc /proc
pascal@16041 264 arg debug "shell" && debug=true && set -x
pascal@16055 265 for i in /lib/*.ko* ; do insmod \$i 2> /dev/null ; done; sleep 2
pascal@13691 266 arg mount "Mount device"
pascal@16055 267 mount \$( (blkid /dev/[sh]d* || blkid) | grep \$val | sed 's/:.*//;q') /mnt
pascal@13691 268 arg subroot "Change root to directory"
pascal@16041 269 mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
pascal@13691 270 mount --bind /mnt /mnt/\$val/mnt/dos
pascal@17454 271 mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
pascal@13691 272 LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
pascal@16041 273 export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
pascal@16041 274 [ "$debug" = "true" ] && sh
pascal@13691 275 umount /proc
pascal@13691 276 exec /bin/switch_root /mnt \${LDSO#/mnt/} \$val/usr/sbin/chroot \$val /sbin/init
pascal@13691 277 EOT
pascal@13691 278 chmod +x /tmp/fs/init
pascal@13691 279 ( cd /tmp/fs ; find * | cpio -o -H newc ) | lzma e $1 -si 2> /dev/null
pascal@17476 280 rm -rf /tmp/fs /tmp/wait
pascal@13691 281 }
pascal@13691 282
pascal@13713 283 is_loram()
pascal@13713 284 {
pascal@13713 285 [ -s /lib/squashfs.ko* ]
pascal@13713 286 }
pascal@13713 287
pascal@16041 288 ls_r()
pascal@16041 289 {
pascal@16041 290 ls -r $@ 2> /dev/null || ls $@
pascal@16041 291 }
pascal@16041 292
pascal@13691 293 doinstall()
pascal@13691 294 {
pascal@14271 295 mkdir -p /mnt/slitaz/boot /mnt/slitaz/mnt/dos
pascal@16041 296 if ! mount.posixovl -F /mnt/slitaz -- \
pascal@16041 297 -oallow_other -odefault_permissions -osuid; then
pascal@16041 298 echo "Can't install SliTaz. Abort."
pascal@16041 299 sleep 5
pascal@16041 300 return 1
pascal@16041 301 fi
pascal@17635 302 dotwait "Install root filesystem in /slitaz.."
pascal@17454 303 if [ "$1" ]; then
pascal@14271 304 if [ -d /media/cdrom/fs ]; then
pascal@14271 305 ( cd /mnt/slitaz/fs; find | cpio -o -H newc ) | gzip -9
pascal@14271 306 else
pascal@17635 307 ls_r /media/cdrom/boot/rootfs*gz | xargs cat
pascal@14271 308 fi > /mnt/slitaz/boot/rootfs.gz
pascal@16055 309 tazusbinitfs /mnt/slitaz/boot/rootfs.gz
pascal@14271 310 initrd=rootfs.gz
pascal@16055 311 extraargs="/home=$(getuuid)/slitaz rdinit=/init1"
pascal@13713 312 else
pascal@14271 313 if [ -d /media/cdrom/fs ]; then
pascal@14271 314 cp -a /media/cdrom/fs/. /mnt/slitaz
pascal@14271 315 elif is_loram ; then
pascal@17473 316 for i in /media/cdrom/boot/rootfs?*.* ; do
pascal@14271 317 [ -s $(basename $i) ] && continue
pascal@14271 318 cpio -i $i
pascal@14271 319 done
pascal@17635 320 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
pascal@14271 321 mount -o loop,ro $i /sqfs/mnt
pascal@14271 322 cp -a /sqfs/mnt/. /mnt/slitaz
pascal@14271 323 umount -d /sqfs/mnt
pascal@14271 324 done
pascal@14271 325 else
pascal@17635 326 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
pascal@14271 327 uncpio $i /mnt/slitaz
pascal@14271 328 done
pascal@14271 329 fi
pascal@17635 330 cp -a /etc/locale.conf /mnt/slitaz/etc 2> /dev/null
pascal@17635 331 cp -a /etc/keymap.conf /mnt/slitaz/etc 2> /dev/null
pascal@14271 332 mkinitrd /mnt/slitaz/boot/initrd
pascal@14271 333 initrd=initrd
pascal@14271 334 extraargs="mount=$(getuuid) subroot=slitaz"
pascal@13713 335 fi
pascal@17476 336 echo -en "\nInstall boot files..."
pascal@13691 337 for i in /media/cdrom/boot/bzImage /media/cdrom/boot/*pxe* \
pascal@13691 338 /media/cdrom/boot/isolinux/he* /media/cdrom/boot/isolinux/opt* \
pascal@13691 339 /media/cdrom/README /media/cdrom/boot/memtest* ; do
pascal@13691 340 [ -s $i ] && cp $i /mnt/slitaz/boot
pascal@13691 341 done
pascal@16047 342 for i in /mnt/slitaz/boot/memtest /mnt/slitaz/boot/*pxe* ; do
pascal@16047 343 [ $(get 0 $i 2> /dev/null || echo 0) -eq 23117 ] &&
pascal@16047 344 mv $i $i.exe
pascal@16047 345 done
pascal@13691 346 gettazboot /mnt/slitaz/boot/tazboot.exe
pascal@14247 347 unix2dos > /mnt/slitaz/boot/tazboot.cmd <<EOT
pascal@16041 348 kernel=/slitaz/boot/bzimage
pascal@16041 349 initrd=/slitaz/boot/$initrd
pascal@14271 350 rw root=/dev/null $extraargs autologin
pascal@13691 351 EOT
pascal@13691 352 unix2dos /mnt/slitaz/boot/he* /mnt/slitaz/boot/opt* \
pascal@14247 353 /mnt/slitaz/boot/README
pascal@14271 354 [ -d /mnt/slitaz/usr/sbin -a ! -x /mnt/slitaz/usr/sbin/mount.posixovl ] &&
pascal@13713 355 cp $(which mount.posixovl) /mnt/slitaz/usr/sbin
pascal@17476 356 rm -f /tmp/wait
pascal@16041 357 false &&
pascal@17476 358 [ -s /mnt/boot.ini ] && ! grep -qs tazboot /mnt/boot.ini &&
pascal@17476 359 echo "Update boot.ini ..." && unix2dos >> /mnt/boot.ini <<EOT
pascal@13691 360 C:\\slitaz\\boot\\tazboot.exe="SliTaz"
pascal@13691 361 EOT
pascal@16073 362 false &&
pascal@16073 363 grep -qis menuitem /mnt/config.sys && ! grep -qi tazboot /mnt/config.sys &&
pascal@16041 364 echo "Update config.sys ..." &&
pascal@16073 365 sed -i 's/menudefault/menuitem SLITAZ, SliTaz\r\n&/' /mnt/config.sys &&
pascal@16073 366 unix2dos >> /mnt/config.sys <<EOT
pascal@16073 367 [SLITAZ]
pascal@16073 368 install=\\slitaz\\boot\\tazboot.exe
pascal@13691 369 EOT
pascal@16041 370 return 0
pascal@13691 371 }
pascal@13691 372
pascal@13691 373 install()
pascal@13691 374 {
pascal@13691 375 $DIALOG --clear \
pascal@14271 376 --title " SliTaz UMSDOS way installation " \
pascal@13691 377 --yes-label "Install" --yesno \
pascal@13691 378 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
pascal@13691 379 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
paul@13692 380 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
pascal@13691 381 To uninstall SliTaz, you have only to remove this directory.
pascal@13691 382 The file \\boot.ini or \\config.sys may be modified too.\n\n
paul@19451 383 SliTaz may run slowly on the 'UMSDOS way' installation due to the
paul@14320 384 posixovl filesystem. The 'TAZUSB way' installation runs faster.\n\n
pascal@13697 385 To do a traditional installation with disk partitioning,
paul@19451 386 start SliTaz Live with the 'SliTaz RAM boot' menu.\n
pascal@14271 387 " 19 70
pascal@14271 388 [ $? -eq 0 ] || return
pascal@16041 389 doinstall || return
pascal@16041 390 [ -x /mnt/slitaz/sbin/init ] || return
pascal@14271 391 umount -d /media/cdrom
pascal@16041 392 umount_proc
pascal@13691 393 exec chroot /mnt/slitaz /sbin/init
pascal@13691 394 }
pascal@13691 395
pascal@14271 396 installtaz()
pascal@14271 397 {
pascal@14271 398 $DIALOG --clear \
pascal@14271 399 --title " SliTaz TAZUSB way installation " \
pascal@14271 400 --yes-label "Install" --yesno \
pascal@14271 401 "\nSliTaz will be installed in the subdirectory \\slitaz of the current
pascal@14271 402 DOS/Windows partition. You will see your files from /mnt/dos.\n\n
pascal@14271 403 You can start SliTaz with \\slitaz\\boot\\tazboot.exe\n\n
pascal@14271 404 To uninstall SliTaz, you have only to remove this directory.
pascal@14271 405 The file \\boot.ini or \\config.sys may be modified too.\n\n
pascal@14271 406 The filesystem is loaded entirely into memory upon boot to
paul@19451 407 increase responsiveness. Only /home lands on the hard disk.\n\n
pascal@14271 408 To do a traditional installation with disk partitioning,
paul@19451 409 start SliTaz Live with the 'SliTaz RAM boot' menu.\n
pascal@14271 410 " 19 70
pascal@14271 411 [ $? -eq 0 ] || return
pascal@16041 412 doinstall tazusblike || return
pascal@17476 413 dotwait
pascal@14271 414 if [ -d /media/cdrom/fs ]; then
pascal@16055 415 cp -a /media/cdrom/fs/. /
pascal@14271 416 else
pascal@17635 417 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
pascal@17454 418 uncpio $i
pascal@14271 419 done
pascal@14271 420 fi
pascal@16055 421 cp /tmp/fs/etc/* /etc
pascal@16055 422 echo "/home=$(getuuid)/slitaz" > /cmdline
pascal@17476 423 rm -f /tmp/wait
pascal@16055 424 [ -x /init1 ] || return
pascal@14271 425 umount -d /media/cdrom
pascal@16055 426 umount /mnt/slitaz
pascal@16073 427 rm -f /dev/cdrom
pascal@16055 428 umount /mnt
pascal@16055 429 mkdir /mnt/dos
pascal@16041 430 umount_proc
pascal@16055 431 exec /init1
pascal@14271 432 }
pascal@14271 433
pascal@13691 434 tazboot()
pascal@13691 435 {
pascal@13691 436 $DIALOG --clear \
pascal@13691 437 --title " SliTaz bootloader for DOS " \
pascal@13691 438 --yes-label "Install" --yesno \
paul@13692 439 "\nThe file TAZBOOT.EXE will be created in the top directory. It supports
pascal@17476 440 any linux kernel, multiple initramfs, a kernel command line and
paul@13692 441 an ISO image file loopback (retrieves files from an ISO file).\n\n
pascal@13691 442 Usage: tazboot.exe [[@commands]|[kernel=<bzimage>]
pascal@17489 443 [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] cmdline args ...]\n\n
paul@13692 444 Defaults: tazboot @tazboot.cmd or tazboot kernel=bzImage auto\n\n\
pascal@13691 445 Examples for tazboot.cmd:\n\n\
pascal@17489 446 bootfrom=\\isos\\slitaz-4.0.iso\n\
pascal@13691 447 kernel=boot/bzImage\n\
pascal@13691 448 initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz\n\
pascal@13691 449 rw root=/dev/null autologin\n\n\
pascal@13691 450 kernel=\\slitaz\\vmlinuz root=/dev/sda5 ro\n\n
pascal@13691 451 Unlike GRUB4DOS, it doesn't require unfragmented ISO image files.\n
pascal@13691 452 " 24 78
pascal@13691 453 [ $? -eq 0 ] || return
pascal@13691 454 gettazboot /mnt/tazboot.exe
pascal@13691 455 }
pascal@13691 456
pascal@13697 457 md5()
pascal@13697 458 {
pascal@17476 459 dotwait "Checking files"
pascal@18061 460 ( cd /media/cdrom ; ${1:-md5sum -c md5sum*} | sort ) > /tmp/data
pascal@17476 461 rm -f /tmp/wait
pascal@13697 462 $DIALOG --clear \
pascal@13697 463 --title " Checked files " \
pascal@13697 464 --textbox /tmp/data 24 78
pascal@13697 465 rm -f /tmp/data
pascal@13697 466 }
pascal@13697 467
pascal@17491 468 gotcdfile()
pascal@17491 469 {
pascal@17635 470 for i in "/media/cdrom/$1" "/media/cdrom/*/$1" \
pascal@17635 471 "/media/cdrom/*/isolinux/$1" ; do
pascal@17491 472 file=$(ls $i 2> /dev/null | sed q)
pascal@17491 473 [ -s "$file" ] && break
pascal@17491 474 done
pascal@17491 475 }
pascal@17491 476
pascal@17489 477 sha()
pascal@17489 478 {
pascal@17635 479 gotcdfile "sha*sum*"
pascal@17489 480 sha=$(basename $file)
pascal@17489 481 md5 "${sha%sum*}sum -c ${file#/media/cdrom/}"
pascal@17489 482 }
pascal@17489 483
pascal@13697 484 readme()
pascal@13697 485 {
pascal@17635 486 gotcdfile "README*"
pascal@13697 487 $DIALOG --clear \
pascal@13697 488 --title " Readme " \
pascal@17489 489 --textbox $file 24 78
pascal@13697 490 }
pascal@13697 491
pascal@13697 492 bootlog()
pascal@13697 493 {
pascal@13697 494 $DIALOG --clear \
pascal@13697 495 --title " Linux boot messages " \
pascal@13697 496 --textbox /tmp/dmesg 24 78
pascal@13697 497 }
pascal@13697 498
pascal@17476 499 bzimage()
pascal@17476 500 {
pascal@17476 501 $DIALOG --clear \
pascal@17476 502 --title " Create linux.exe ? " \
pascal@17476 503 --yes-label "Install" --yesno \
pascal@17476 504 "\nLinux.exe launches the linux kernel under DOS (in real mode only).
pascal@17569 505 The cmdline arguments are supported except initrd=,
pascal@17569 506 vga= (you can try 'rdev -v') and mem= (partially).
pascal@17569 507 \nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n
pascal@17476 508 " 12 70
pascal@17476 509 [ $? -eq 0 ] || return
pascal@17476 510 cp /media/cdrom/boot/bzImage /mnt/linux.exe
pascal@17476 511 }
pascal@17476 512
pascal@13697 513 memtest()
pascal@13697 514 {
pascal@13697 515 $DIALOG --clear \
pascal@17476 516 --title " Create memtest.exe ? " \
pascal@13697 517 --yes-label "Install" --yesno \
pascal@13697 518 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
pascal@13697 519 computers. BIOS based memory tests are a quick, cursory check and often
pascal@13697 520 miss many of the failures that are detected by Memtest86.\n
pascal@13697 521 " 12 70
pascal@17635 522 [ $? -eq 0 ] && gotcdfile "memtest*" && cp $file /mnt/memtest.exe
pascal@13697 523 }
pascal@13697 524
pascal@17489 525 mkfat12()
pascal@17473 526 {
pascal@17473 527 [ $(($(get 0 $1) - 0x5A4D)) -eq 0 ] || return
pascal@17473 528 J=$(($(get 3 $1 1) + 0x02))
pascal@17473 529 R=$((1 + $(get 497 $1 1) + 1 + ($(get 500 $1)-1)/32))
pascal@17473 530 [ $R -lt 2500 ] || return
pascal@17476 531 [ $((($(get 500 $1)-1) & 31)) -lt 30 ] &&
pascal@17474 532 ddq if=$file bs=32 count=1 seek=$(($R*16 - 1)) of=/dev/fd0
pascal@17473 533 G="18 0 2 0 0 0 0 0"
pascal@17473 534 [ $J -gt 25 ] || G=""
pascal@17473 535 F=0
pascal@17473 536 for i in 1 2 3; do
pascal@17473 537 F=$((((2880-$R-$F-$F)*3+1023)/1024))
pascal@17473 538 done
pascal@17473 539 bytes2bin 0xEB $J 0x90 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20 \
pascal@17473 540 0 2 2 $(($R%256)) $(($R/256)) 2 64 0 64 11 0xF0 $F 0 \
pascal@17473 541 $G | ddq bs=1 of=/dev/fd0
pascal@17473 542 ddq if=/dev/zero bs=512 count=$((4+$F+$F)) seek=$R of=/dev/fd0
pascal@17473 543 for i in $R $(($R+$F)) ; do
pascal@17473 544 bytes2bin 0xF0 0xFF 0xFF | ddq bs=512 seek=$i of=/dev/fd0
pascal@17473 545 done
pascal@17473 546 echo -n $(basename $1) | ddq bs=1 seek=3 count=8 of=/dev/fd0
pascal@17489 547 }
pascal@17489 548
pascal@17489 549 mkfloppy()
pascal@17489 550 {
pascal@17489 551 dotwait "Create a $(basename $1) boot floppy"
pascal@17489 552 ddq if=$1 of=/dev/fd0
pascal@17489 553 mkfat12 $1
pascal@17476 554 rm -f /tmp/wait
pascal@17473 555 }
pascal@17473 556
pascal@13697 557 fdmemtest()
pascal@13697 558 {
pascal@13697 559 $DIALOG --clear \
pascal@13697 560 --title " Create a Memtest86 boot floppy " \
pascal@13697 561 --yes-label "Create floppy" --yesno \
pascal@13697 562 "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
pascal@13697 563 computers. BIOS based memory tests are a quick, cursory check and often
pascal@13697 564 miss many of the failures that are detected by Memtest86.\n\n
pascal@13697 565 Please insert a blank disk in floppy drive.\n
pascal@13697 566 " 12 70
pascal@17635 567 [ $? -eq 0 ] && gotcdfile "memtest*" && mkfloppy $file
pascal@13697 568 }
pascal@13697 569
pascal@16013 570 pxe()
pascal@13697 571 {
pascal@17635 572 gotcdfile "?pxe"
pascal@13697 573 $DIALOG --clear \
pascal@17491 574 --title " Create $(basename $file).exe ? " \
pascal@13697 575 --yes-label "Install" --yesno \
pascal@13697 576 "\nBoot your operating system from the internet and enjoy a full system
pascal@13697 577 working entirely in RAM with speed and stability in mind. The Linux Kernel
pascal@13697 578 and the complete SliTaz compressed root filesystem will be loaded into RAM
pascal@13697 579 from the Web using PXE and HTTP protocols.\n
pascal@13697 580 " 12 70
pascal@13697 581 [ $? -eq 0 ] || return
pascal@17491 582 cp $file /mnt/$(basename $file).exe
pascal@13697 583 }
pascal@13697 584
pascal@16013 585 fdpxe()
pascal@13697 586 {
pascal@13697 587 $DIALOG --clear \
pascal@13697 588 --title " Create a SliTaz Web boot floppy " \
pascal@13697 589 --yes-label "Create floppy" --yesno \
pascal@13697 590 "\nBoot your operating system from the internet and enjoy a full system
pascal@13697 591 working entirely in RAM with speed and stability in mind. The Linux Kernel
pascal@13697 592 and the complete SliTaz compressed root filesystem will be loaded into RAM
pascal@13697 593 from the Web using PXE and HTTP protocols.\n\n
pascal@13697 594 Please insert a blank disk in floppy drive.\n
pascal@13697 595 " 12 70
pascal@17635 596 [ $? -eq 0 ] && gotcdfile "?pxe" && mkfloppy $file
pascal@13697 597 }
pascal@13697 598
pascal@16041 599 gotposixovl()
pascal@16041 600 {
pascal@16041 601 mount.posixovl 2>&1 | grep -qi usage &&
pascal@16041 602 echo -en "\"$1\" \"$2\""
pascal@16041 603 }
pascal@16041 604
pascal@14271 605 xfile()
pascal@14271 606 {
pascal@17454 607 [ "$(which $1)" ] && echo -en "\"$2\" \"$3\""
pascal@14271 608 }
pascal@14271 609
pascal@13697 610 cdfile()
pascal@13697 611 {
pascal@17489 612 gotcdfile "$1" && echo -en "\"$2\" \"$3\""
pascal@17476 613 }
pascal@17476 614
pascal@17659 615 isbzImage()
pascal@17659 616 {
pascal@17659 617 [ $(get 514 $file 4) -eq 1400005704 ] &&
pascal@17659 618 [ $(($(get 529 $file 1) & 1)) -eq 1 ]
pascal@17659 619 }
pascal@17659 620
pascal@17476 621 cdfilex()
pascal@17476 622 {
pascal@17659 623 gotcdfile "$1" &&
pascal@17659 624 [ "$(which kexec)" ] &&
pascal@17659 625 isbzImage &&
pascal@17659 626 echo -en "\"$2\" \"$3\""
pascal@14271 627 }
pascal@14271 628
pascal@17491 629 cdfilef()
pascal@17491 630 {
pascal@17491 631 [ -e /sys/block/fd0 ] && cdfile "$@"
pascal@17491 632 }
pascal@17491 633
pascal@16022 634 cdexe()
pascal@16022 635 {
pascal@17489 636 gotcdfile "$1" &&
pascal@17489 637 [ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
pascal@16022 638 echo -en "\"$2\" \"$3\""
pascal@16022 639 }
pascal@16022 640
pascal@14271 641 fddata()
pascal@14271 642 {
pascal@17491 643 [ -e /sys/block/fd0 ] &&
pascal@18771 644 [ $(get 26 /mnt/$ISO 1 2> /dev/null || echo 0) -ne 0 ] &&
pascal@14271 645 echo -en "\"$1\" \"$2\""
pascal@13697 646 }
pascal@13697 647
pascal@17491 648 ishybrid()
pascal@17491 649 {
pascal@19510 650 [ $(get 510 $ISO 2> /dev/null || echo 0) -eq 43605 ] || return
pascal@17491 651 C=$((2048*$(get $(((17*2048) + 71)) /mnt/$ISO 4)))
pascal@17491 652 [ $(get $C /mnt/$ISO 4) -eq 1 ] || return
pascal@17491 653 [ $(get $(($C+30)) /mnt/$ISO 4) -eq $((0x88AA55)) ] || return
pascal@17491 654 C=$((2048*$(get $(($C+40)) /mnt/$ISO 4)))
pascal@17491 655 [ $(get $(($C+64)) /mnt/$ISO 4) -eq 1886961915 ] &&
pascal@17491 656 echo -en "\"$1\" \"$2\""
pascal@17491 657 }
pascal@17491 658
pascal@18034 659 burnable()
pascal@18034 660 {
pascal@19510 661 [ "$(sed '/Can wr.*1$/!d' /proc/sys/dev/cdrom/info 2> /dev/null)" ] &&
pascal@18034 662 [ "$(which wodim)" ] && echo -en "\"$1\" \"$2\""
pascal@18034 663 }
pascal@18034 664
pascal@18034 665 blankable()
pascal@18034 666 {
pascal@19510 667 [ "$(sed '/Can wr.*RW.*1$/!d' /proc/sys/dev/cdrom/info 2> /dev/null)" ] &&
pascal@18034 668 [ "$(which wodim)" ] && echo -en "\"$1\" \"$2\""
pascal@18034 669 }
pascal@18034 670
pascal@18034 671 burniso()
pascal@18034 672 {
pascal@18034 673 wodim -v speed=$(fgrep "drive speed" /proc/sys/dev/cdrom/info | cut -f3) \
pascal@18034 674 -eject -multi "$ISO"
pascal@18034 675 }
pascal@18034 676
pascal@18034 677 blankcd()
pascal@18034 678 {
pascal@18034 679 wodim -v -blank=fast
pascal@18034 680 }
pascal@18034 681
pascal@18771 682 customsector()
pascal@18771 683 {
pascal@19324 684 echo $(get 32848 "/mnt/$ISO" 4)
pascal@18771 685 }
pascal@18771 686
pascal@18771 687 hascustomconf()
pascal@18771 688 {
pascal@18771 689 [ "$(ddq bs=2k skip=$(customsector) if="/mnt/$ISO" | ddq bs=1 count=6)" \
pascal@18771 690 == "#!boot" ]
pascal@18771 691 }
pascal@18771 692
pascal@18771 693 gotcustomconf()
pascal@18771 694 {
pascal@18774 695 hascustomconf && echo -en "\"$1\" \"$2\""
pascal@18771 696 }
pascal@18771 697
pascal@18771 698 getcustomconf()
pascal@18771 699 {
pascal@18774 700 cd ${1:-/mnt}
pascal@18774 701 ddq bs=2k skip=$(customsector) if="/mnt/$ISO" | while read line; do
pascal@18771 702 case "$line" in
pascal@18771 703 \#!boot*) ;;
pascal@18771 704 append=*) echo ${line#append=} > cmdline && ls -l cmdline ;;
pascal@18771 705 initrd:*) cnt=${line#initrd:}
pascal@18771 706 { ddq bs=512 count=$(($cnt / 512));
pascal@18771 707 ddq bs=1 count=$(($cnt % 512)); } > initrd &&
pascal@18771 708 ls -l initrd
pascal@18771 709 break ;;
pascal@18771 710 *) break ;;
pascal@18771 711 esac
pascal@18771 712 done
pascal@18771 713 cd - > /dev/null
pascal@18774 714 [ -z "$1" ] && echo -e "\rPress RETURN to continue." && read n
pascal@18771 715 }
pascal@18771 716
pascal@17492 717 gotisomd5()
pascal@17492 718 {
pascal@17562 719 [ "$(which md5sum 2> /dev/null)" ] &&
pascal@17635 720 [ $(get 0 /mnt/$ISO) -eq 23117 ] &&
pascal@17635 721 [ $(get 18 /mnt/$ISO) -ne 0 ] && echo -en "\"$1\" \"$2\""
pascal@17492 722 }
pascal@17492 723
pascal@17492 724 isomd5()
pascal@17492 725 {
pascal@17492 726 dotwait "Checking iso image"
pascal@17635 727 [ "$(ddq if=/mnt/$ISO bs=2k skip=16 \
pascal@19323 728 count=$(($(get 32848 /mnt/$ISO 4)-16)) | md5sum)" == \
pascal@17635 729 "$(ddq if=/mnt/$ISO bs=16 count=1 skip=2047 | od -N 16 -t x1 -An | \
pascal@17496 730 sed 's/ //g') -" ] && echo "OK" || echo "ERROR"
pascal@17635 731 echo -en "\rChecking iso hybrid boot..."
pascal@17635 732 n=$(($(get 2 /mnt/$ISO)-1+($(get 4 /mnt/$ISO)-1)*512))
pascal@17635 733 if [ $n -lt 40000 -a $n -gt 32768 ]; then
pascal@17635 734 s=$(get 0 /mnt/$ISO 2 $n | awk '{ i+= $0 } END { print i }')
pascal@17635 735 [ $(((1+$s+$(get $(($n+1)) /mnt/$ISO 1)) % 65536)) -eq 0 ] &&
pascal@17635 736 echo "OK" || echo "ERROR"
pascal@17635 737 fi
pascal@18771 738 if hascustomconf; then
pascal@18771 739 echo -en "\rChecking iso custom config..."
pascal@18771 740 TMP=/tmp/$(basename $0)$$md5
pascal@18771 741 md5="$(ddq bs=2k skip=$(customsector) if=/mnt/$ISO | while read line; do
pascal@18771 742 case "$line" in
pascal@18771 743 \#!boot*) echo ${line#*boot } > $TMP ;;
pascal@18771 744 append=*) echo $line ;;
pascal@18771 745 initrd:*) echo $line
pascal@18771 746 cnt=${line#initrd:}
pascal@18771 747 ddq bs=512 count=$((cnt / 512))
pascal@18771 748 ddq bs=1 count=$((cnt % 512))
pascal@18771 749 break ;;
pascal@18771 750 *) break ;;
pascal@18771 751 esac
pascal@18771 752 done | md5sum | cut -c1-32)"
pascal@18771 753 [ "$md5" == "$(cat $TMP)" ] && echo "OK" || echo "ERROR"
pascal@18771 754 rm -f $TMP
pascal@18771 755 fi
pascal@17492 756 rm -f /tmp/wait
pascal@17562 757 echo -e "\rPress RETURN to continue."
pascal@17496 758 read n
pascal@17492 759 }
pascal@17492 760
pascal@18771 761 if [ "$1" == "--build" ]; then #install-begin
pascal@18771 762 uuencode -m - < ifmem.bin | sed -e '/^ifmemcode$/r/dev/stdin' \
pascal@18771 763 -e '/^ifmemcode$/d' -i $0
pascal@18771 764 uuencode -m - < bootloader.bin | sed -e '/^bootloader$/r/dev/stdin' \
pascal@18771 765 -e '/^bootloader$/d' -e '/install-begin$/,/install-end$/d' -i $0
pascal@18771 766 exit
pascal@18771 767 fi #install-end
pascal@18771 768 parse_isolinux()
pascal@18771 769 {
pascal@18771 770 awk 'BEGIN { IGNORECASE=1 }
pascal@18771 771 function multi(n)
pascal@18771 772 {
pascal@18771 773 auto=$n
pascal@18771 774 for (--n; n < NF; n+=2) {
pascal@18771 775 s=$n
pascal@18771 776 if (s ~ /M$/) s = substr(s,0,length(s)-1)
pascal@18771 777 else s /= 1024
pascal@18771 778 sizes=int(s) " " sizes
pascal@18771 779 }
pascal@18771 780 next
pascal@18771 781 }
pascal@18771 782 {
pascal@18771 783 if ($1 == "LABEL") {
pascal@18771 784 label=$2
pascal@18771 785 if (auto == "") auto=label
pascal@18771 786 }
pascal@18771 787 if ($1 == "KERNEL" || $1 == "COM32") kernel[label]=$2
pascal@18771 788 if ($1 == "INITRD") initrd[label]=$2
pascal@18771 789 if ($1 == "APPEND") {
pascal@18771 790 i=2
pascal@18771 791 if (kernel[label] ~ "ifmem.c32") multi(3)
pascal@18771 792 if (kernel[label] ~ "c32box.c32") {
pascal@18771 793 if ($2 == "linux") { kernel[label]=$3; i=4 }
pascal@18771 794 if ($2 == "ifmem") multi(4)
pascal@18771 795 }
pascal@18771 796 if (kernel[label] ~ "ifcpu64.c32") { auto=$4; next }
pascal@18771 797 while (i <= NF) {
pascal@18771 798 if ($i ~ "^initrd=") initrd[label]=substr($i,8)
pascal@18771 799 else cmdline[label]=cmdline[label] " " $i
pascal@18771 800 i++
pascal@18771 801 }
pascal@18771 802 }
pascal@18771 803 }
pascal@18771 804 END {
pascal@18771 805 print "KERNEL=\"" kernel[auto] "\""
pascal@18771 806 print "INITRD=\"" initrd[auto] "\""
pascal@18771 807 print "CMDLINE=\"" substr(cmdline[auto],2) "\""
pascal@18771 808 print "SIZES=\"" sizes "\""
pascal@18771 809 }'
pascal@18771 810 }
pascal@18771 811
pascal@18771 812 locase()
pascal@18771 813 {
pascal@18771 814 echo "$1" | tr [A-Z] [a-z]
pascal@18771 815 }
pascal@18771 816
pascal@18771 817 ifmemcode()
pascal@18771 818 {
pascal@18771 819 uudecode <<EOT
pascal@18771 820 ifmemcode
pascal@18771 821 EOT
pascal@18771 822 }
pascal@18771 823
pascal@18771 824 floppyset()
pascal@18771 825 {
pascal@18771 826 gotcdfile isolinux.cfg
pascal@18771 827 parse_isolinux < $file > /tmp/var$$
pascal@18771 828 . /tmp/var$$
pascal@19877 829 for i in /media/cdrom/$KERNEL $(dirname $file)/$KERNEL /media/cdrom/$(locase $KERNEL) \
pascal@18771 830 $(dirname $file)/$(locase $KERNEL); do
pascal@18771 831 [ -s $i ] && KERNEL=$i && break
pascal@18771 832 done
pascal@18771 833 rm -f /tmp/var$$
pascal@18771 834 [ $(get 514 $KERNEL 4) -eq 1400005704 ] || return
pascal@18771 835 n=$(($(get 497 $KERNEL 1)+1))
pascal@18771 836 ddq bs=512 count=$n if=$KERNEL of=/tmp/fd$$
pascal@18771 837 uudecode <<EOT | ddq of=/tmp/fd$$ conv=notrunc
pascal@18771 838 bootloader
pascal@18771 839 EOT
pascal@18771 840 pos=$(($n*512))
pascal@18771 841 if [ -n "$CMDLINE" ]; then
pascal@18771 842 echo -n "$CMDLINE" | ddq bs=512 count=1 conv=sync >> /tmp/fd$$
pascal@18771 843 bytes2bin $n | ddq conv=notrunc \
pascal@18771 844 bs=1 seek=497 count=1 of=/tmp/fd$$
pascal@18771 845 words2bin $pos | ddq conv=notrunc \
pascal@18771 846 bs=1 seek=34 count=2 of=/tmp/fd$$
pascal@18771 847 [ $(get 518 $KERNEL 4) -ge 514 ] &&
pascal@18771 848 words2bin 32768 9 | ddq conv=notrunc \
pascal@18771 849 bs=1 seek=552 count=4 of=/tmp/fd$$
pascal@18771 850 fi
pascal@18771 851 syssize=$(echo $(get 500 /tmp/fd$$ 4))
pascal@18771 852 ddq bs=512 skip=$n if=$KERNEL | cat - /dev/zero | \
pascal@18771 853 ddq bs=512 count=$((($syssize+31)/32)) conv=sync >> /tmp/fd$$
pascal@18771 854 base=$(stat -c %s /tmp/fd$$)
pascal@18771 855 len=
pascal@18771 856 if [ "$INITRD" ]; then
pascal@18771 857 l=0
pascal@18771 858 for i in ${INITRD//,/ }; do
pascal@19877 859 for j in /media/cdrom/$i $(dirname $KERNEL)/$i /media/cdrom/$(locase $i) \
pascal@18771 860 $(dirname $KERNEL)/$(locase $i); do
pascal@18771 861 [ -s $j ] && i=$j && break
pascal@18771 862 done
pascal@18771 863 ddq if=$i >> /tmp/fd$$
pascal@18771 864 l=$(($l+$(stat -c %s $i)))
pascal@18771 865 r=$((4 - ($l % 4)))
pascal@18771 866 if [ $r -ne 4 ]; then
pascal@18771 867 ddq if=/dev/zero bs=1 count=$r >> /tmp/fd$$
pascal@18771 868 l=$(($l + $r))
pascal@18771 869 fi
pascal@18771 870 case "$i:$INITRD" in
pascal@18771 871 *rootfs.gz:*rootfs.gz,*) continue # loram
pascal@18771 872 esac
pascal@18771 873 len="$len $l"; l=0
pascal@18771 874 done
pascal@18771 875 rdadrs=${RDADRS:-$(((($syssize*16)+0x1F0000) & -4096))}
pascal@18771 876 words2bin $(($rdadrs & 0xFFFF)) $(($rdadrs >> 16)) | ddq \
pascal@18771 877 conv=notrunc bs=1 seek=536 count=4 of=/tmp/fd$$
pascal@18771 878 fi
pascal@18771 879 n=$(echo $len | wc -w)
pascal@18771 880 if [ $((494 - $(get 494 /tmp/fd$$))) -ge $(($n * 4)) ]; then
pascal@18771 881 i=$(($(get 494 /tmp/fd$$)))
pascal@18771 882 bytes2bin $(($i + ($n*4) - 256)) | ddq bs=1 conv=notrunc \
pascal@18771 883 seek=496 count=1 of=/tmp/fd$$
pascal@18771 884 else
pascal@18771 885 i=$(($pos + 0x1FC - ($n*4)))
pascal@18771 886 bytes2bin $(($i % 256)) $((i / 256)) 252 | ddq bs=1 \
pascal@18771 887 conv=notrunc seek=494 count=3 of=/tmp/fd$$
pascal@18771 888 s=$(($i - 2*$(echo "$SIZES" | wc -w)))
pascal@18771 889 p=$(($s - $(ifmemcode | wc -c)))
pascal@18771 890 ifmemcode | ddq bs=1 conv=notrunc seek=$p of=/tmp/fd$$
pascal@18771 891 words2bin $SIZES | ddq bs=1 conv=notrunc seek=$s of=/tmp/fd$$
pascal@18771 892 bytes2bin 154 $(($p%256)) $(($p/256)) 0 144 | \
pascal@18771 893 ddq bs=1 conv=notrunc seek=60 of=/tmp/fd$$
pascal@18771 894 fi
pascal@18771 895 for r in $len ; do
pascal@18771 896 words2bin $(($r & 0xFFFF)) $(($r >> 16)) | ddq conv=notrunc \
pascal@18771 897 bs=1 seek=$i count=4 of=/tmp/fd$$
pascal@18771 898 i=$(($i + 4))
pascal@18771 899 done
pascal@18771 900 split -b 1440k /tmp/fd$$ fd$$
pascal@18771 901 rm -f /tmp/fd$$
pascal@18771 902 n=1; i=0; r=0
pascal@18771 903 set -- $len
pascal@18771 904 ls fd$$* | while read file ; do
pascal@18771 905 if [ $i -gt $(($1+$base)) ]; then
pascal@18771 906 shift
pascal@18771 907 r=$(($r+100)); n=0; i=0; base=0
pascal@18771 908 fi
pascal@18771 909 ddq of=$file bs=18k seek=80 count=0
pascal@18771 910 i=$(($i+1474560))
pascal@18771 911 printf "mv %s fd%03d.img\n" $file $(($r+$n))
pascal@18771 912 n=$(($n+1))
pascal@18771 913 done | sh
pascal@18771 914 ls fd???.img
pascal@19878 915 mv fd???.img /mnt
pascal@18771 916 }
pascal@18771 917
pascal@14257 918 fdbootstrap()
pascal@14257 919 {
pascal@18771 920 sz=$((512 * $(echo $(get 26 /mnt/$ISO 1))))
pascal@14271 921 $DIALOG --clear \
pascal@14271 922 --title " Create a floppy bootstrap " \
pascal@14271 923 --yes-label "Continue" --yesno \
paul@14263 924 "\nThe floppy will install a driver to access the ISO file
pascal@14257 925 on your hard disk and will emulate a CD-ROM during the boot process.\n\n
pascal@14257 926 Please insert a floppy in drive now.\n
pascal@14257 927 " 10 70
pascal@14271 928 [ $? -eq 0 ] || return
pascal@17474 929 ddq if=/mnt/$ISO of=/tmp/bootiso bs=1 count=512 \
pascal@17810 930 skip=$(( $(get 64 /mnt/$ISO) - $sz ))
pascal@17474 931 echo "$ISO" | ddq of=/tmp/bootiso bs=512 seek=1 count=1
pascal@17474 932 ddq if=/mnt/$ISO of=/tmp/bootiso bs=1 count=$sz seek=2 \
pascal@17810 933 skip=$(( $(get 64 /mnt/$ISO) - $sz + 512 ))
pascal@17474 934 mkfloppy /tmp/bootiso
pascal@17474 935 rm -f /tmp/bootiso
pascal@14257 936 }
pascal@14257 937
pascal@14257 938 usbdev()
pascal@14257 939 {
pascal@17476 940 dotwait "Wait 5 seconds for USB devices"
pascal@14257 941 sleep 5
pascal@17476 942 rm -f /tmp/wait
pascal@14257 943 DEV="$(grep -l 1 /sys/block/*/removable | \
pascal@14257 944 sed 's|/sys/block/\(.*\)/removable|\1|')"
pascal@17491 945 grep -qs 1 /sys/block/$DEV/ro && return
pascal@17454 946 [ "$DEV" ] || return
pascal@17491 947 cat > /tmp/dialog <<EOT
pascal@17491 948 $DIALOG --clear \
pascal@14257 949 --title " Select your USB key " \
pascal@14257 950 --menu "\nPlease select the USB key according to its known size.\n\n" \
pascal@14257 951 14 70 4 \
pascal@14257 952 $(for i in $DEV ; do
pascal@17491 953 echo -n "/dev/$i \"$(($(cat /sys/block/$i/size)/2048))MB $(cat /sys/block/$i/device/model 2> /dev/null)\" "
pascal@14257 954 done) \
pascal@17491 955
pascal@17491 956 EOT
pascal@17491 957 exec 3>&1
pascal@17491 958 device=$(. /tmp/dialog 2>&1 1>&3)
pascal@14257 959 retval=$?
pascal@14257 960 exec 3>&-
pascal@14257 961 [ $retval -eq 0 ]
pascal@14257 962 }
pascal@14257 963
pascal@17491 964 tazusbmsg()
pascal@17491 965 {
pascal@17491 966 [ "$(which tazusb 2> /dev/null)" ] || return
pascal@17491 967 echo "You should choose 'USB key read/write installation' to be
pascal@17491 968 able to save the package updates or your own configuration and data files.\n\n"
pascal@17491 969 }
pascal@17491 970
pascal@14257 971 usbbootkey()
pascal@14257 972 {
pascal@14257 973 $DIALOG --clear \
pascal@14257 974 --title " Create a USB boot key " \
pascal@14257 975 --yes-label "Continue" --yesno \
pascal@14257 976 "\nThe USB key will be used like a CD-ROM. You will not be able to write
pascal@17454 977 any data on the boot partition.\n\n
pascal@17454 978 An extra FAT32 partition will be created with the remaining free space.\n\n
pascal@17491 979 $(tazusbmsg)Please plug your USB stick in now.\n
pascal@17454 980 " 16 70
pascal@14257 981 [ $? -eq 0 ] || return
pascal@14257 982 usbdev || return
pascal@17454 983
paul@17671 984 # perform dd in progress bar
pascal@17491 985 max=$(($(cat /sys/block/loop0/size)/2048))
pascal@17454 986 i=0; ddq if=/mnt/$ISO bs=1024k | (
pascal@17455 987 while ddq bs=1024k count=1 ; do
pascal@17454 988 i=$(($i + 1))
pascal@17454 989 [ $i -gt $max ] && break
pascal@17455 990 echo $((($i*100)/$max)) | dialog --gauge \
pascal@17455 991 " The ISO image transfer can be long. Please wait..." \
pascal@17476 992 6 70 0 > /dev/tty0 2>&1
pascal@17454 993 done ) > $device
pascal@17454 994
paul@17671 995 # partition + fat32 format for the remaining space
pascal@17860 996 for p in 0 16; do
pascal@17860 997 get $((450+$p)) $device 2 12 | xargs echo | {
pascal@17860 998 read dx cx ol oh ll lh
pascal@17860 999 [ $dx -eq $((0x3F17)) ] || continue
pascal@17454 1000 cx=$(($cx & 0xFF00))
pascal@17454 1001 ofs=$(($ll+($lh<<16)))
pascal@17454 1002 n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
pascal@17454 1003 m=$(($cx+($n/8)))
pascal@17454 1004 [ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
pascal@17454 1005 m=$((($m & 0xFF00)+(($m>>16)<<6)))
pascal@17454 1006 words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
pascal@17454 1007 $ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
pascal@17860 1008 ddq bs=1 seek=$((462-$p)) of=$device
pascal@17454 1009 if [ "$(which mkdosfs 2> /dev/null)" ]; then
pascal@17562 1010 losetup -o $((512*$ofs)) /dev/loop2 $device
pascal@17562 1011 mkdosfs -n "SLITAZ BOOT" /dev/loop2
pascal@17454 1012 words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
pascal@17562 1013 ddq bs=1 seek=28 of=/dev/loop2
pascal@17860 1014 sync
pascal@17562 1015 losetup -d /dev/loop2
pascal@17454 1016 fi
pascal@17860 1017 }
pascal@17860 1018 done
pascal@14257 1019 }
pascal@14257 1020
pascal@13697 1021 usbkey()
pascal@13697 1022 {
pascal@13697 1023 $DIALOG --clear \
pascal@13697 1024 --title " Create a SliTaz USB key " \
pascal@13697 1025 --yes-label "Continue" --yesno \
pascal@13697 1026 "\nUnlike a hard drive install, the filesystem is kept in a compressed
pascal@13697 1027 rootfs.gz. The filesystem is loaded entirely into memory upon boot.
pascal@13697 1028 This should increase responsiveness, protect the filesystem against
pascal@13697 1029 accidental corruption and reduce read/writes to the USB drive.
pascal@13697 1030 Once setup, the tazusb utility can rewrite the root filesystem
pascal@13697 1031 with any changes you have made since booting up,
pascal@13697 1032 giving the effective benefits of a hard drive install.\n\n
pascal@13697 1033 /home is mounted on boot using the UUID of your particular flash drive.
pascal@13697 1034 Unlike a device name, the UUID has the benefit of never changing from machine
pascal@13697 1035 to machine.\n\n
pascal@13697 1036 Please plug your USB stick in now.\n
pascal@14257 1037 " 19 70
pascal@14271 1038 [ $? -eq 0 ] || return
pascal@14257 1039 usbdev || return
pascal@13697 1040 exec 3>&1
pascal@13697 1041 format=`$DIALOG --clear \
pascal@13697 1042 --title " Select the filesystem " \
pascal@13733 1043 --radiolist "\nPlease select the filesystem type to create.\n\n\
paul@13698 1044 The filesystem creation will erase all the data \
pascal@13699 1045 in the USB key." 14 70 4 \
pascal@13733 1046 "none" "Do not erase the USB key" on \
pascal@13733 1047 "ext3" "Ext3 journaling filesystem" off \
pascal@13733 1048 "ext2" "Ext2 filesystem" off \
pascal@13733 1049 "fat32" "Windows FAT32 filesystem" off \
pascal@13697 1050 2>&1 1>&3`
pascal@13697 1051 retval=$?
pascal@13697 1052 exec 3>&-
pascal@14257 1053 [ $retval -eq 0 ] || return
pascal@13697 1054 [ "$format" != "none" ] && tazusb format $device "SliTaz" $format
pascal@13697 1055 tazusb gen-iso2usb /mnt/$ISO $device
pascal@13697 1056 }
pascal@13697 1057
pascal@13713 1058 mount_loram()
pascal@13713 1059 {
pascal@13713 1060 is_loram || return
pascal@13713 1061 insmod /lib/squashfs.ko* 2> /dev/null
pascal@13713 1062 if [ -d /media/cdrom/fs ]; then
pascal@13713 1063 ln -s /media/cdrom/fs /sqfs
pascal@13713 1064 else
pascal@13713 1065 mkdir /sqfs
pascal@13713 1066 mount -o loop,ro -t squashfs /rootfs*.gz /sqfs
pascal@13713 1067 fi
pascal@13713 1068 ln -s /sqfs/lib/* lib
pascal@13713 1069 ln -s /sqfs/usr /sqfs/var /
pascal@13713 1070 for i in dmesg basename tr od reboot poweroff getty sync ; do
pascal@13713 1071 ln -s /sqfs/bin/busybox /bin/$i
pascal@13713 1072 done
pascal@13713 1073 }
pascal@13713 1074
pascal@13713 1075 umount_loram()
pascal@13713 1076 {
pascal@13713 1077 is_loram || return
pascal@13713 1078 rm /var /usr
pascal@13713 1079 umount -d /sqfs
pascal@13713 1080 rmdir /sqfs
pascal@13713 1081 }
pascal@13713 1082
pascal@17569 1083 dosync()
pascal@13691 1084 {
pascal@17569 1085 sync
pascal@13713 1086 umount_loram
pascal@13691 1087 umount -d /media/cdrom
pascal@16073 1088 rm -f /dev/cdrom
pascal@13691 1089 umount /mnt
pascal@16041 1090 umount_proc
pascal@17569 1091 }
pascal@17569 1092
pascal@17569 1093 text()
pascal@17569 1094 {
pascal@18774 1095 init=
pascal@18774 1096 cmdline="$(cat /proc/cmdline)"
pascal@18774 1097 if hascustomconf; then
pascal@18774 1098 getcustomconf /tmp > /dev/null
pascal@18774 1099 [ -s /tmp/cmdline ] &&
pascal@18774 1100 cmdline="$cmdline $(cat /tmp/cmdline)" &&
pascal@18774 1101 init="$(sed '/rdinit=/!d;s/.*rdinit=\([^ ]*\).*/\1/' < /tmp/cmdline)"
pascal@18774 1102 [ -s /tmp/initrd ] && uncpio /tmp/initrd
pascal@18774 1103 fi
pascal@17569 1104 dosync
pascal@18774 1105 exec ${init:-/init} $cmdline
pascal@13691 1106 }
pascal@13691 1107
pascal@13691 1108 live()
pascal@13691 1109 {
pascal@13691 1110 n=0
pascal@17476 1111 dotwait "Extract filesystem..."
pascal@17562 1112 for i in $(ls_r /media/cdrom/boot/rootfs*gz); do
pascal@17562 1113 grep -q ' lm ' /proc/cpuinfo && [ -s ${i}64 ] && i=${i}64
pascal@13691 1114 [ $((n++)) -eq 0 ] || uncpio $i
pascal@13691 1115 done
pascal@17476 1116 rm -f /tmp/wait
pascal@13691 1117 text
pascal@13691 1118 }
pascal@13691 1119
pascal@13713 1120 restart()
pascal@13691 1121 {
pascal@17476 1122 dosync
pascal@13713 1123 reboot -f
pascal@13691 1124 }
pascal@13691 1125
pascal@13713 1126 stop()
pascal@13691 1127 {
pascal@17476 1128 dosync
pascal@13713 1129 poweroff -f
pascal@13691 1130 }
pascal@13691 1131
pascal@17489 1132 dokexec()
pascal@17476 1133 {
pascal@17659 1134 kexec -l $file || return
pascal@17476 1135 dosync
pascal@17476 1136 kexec -e
pascal@17476 1137 }
pascal@17476 1138
pascal@17489 1139 runmemtest()
pascal@17489 1140 {
pascal@17635 1141 gotcdfile "memtest*" && dokexec
pascal@17489 1142 }
pascal@17489 1143
pascal@17476 1144 runpxe()
pascal@17476 1145 {
pascal@17635 1146 gotcdfile "?pxe" && dokexec
pascal@17476 1147 }
pascal@17476 1148
pascal@17931 1149 flavdata()
pascal@17931 1150 {
pascal@19510 1151 ddq if=/mnt/$ISO bs=512 skip=$((1+$(get 417 /mnt/$ISO 1))) \
pascal@19510 1152 count=20 | zcat 2>/dev/null
pascal@17931 1153 }
pascal@17931 1154
pascal@17931 1155 hasflavinfo()
pascal@17931 1156 {
pascal@19510 1157 [ "$(flavdata | ddq bs=1 count=8)" == "07070100" ] &&
pascal@19510 1158 echo -en "\"$1\" \"$2\""
pascal@17931 1159 }
pascal@17931 1160
pascal@17931 1161 showfavinfo()
pascal@17931 1162 {
pascal@17931 1163 mkdir -p /tmp/data
pascal@17931 1164 flavdata | ( cd /tmp/data ; cpio -i )
pascal@17931 1165 file=/tmp/data/info
pascal@17931 1166 cat /tmp/data/*desc > $file
pascal@17931 1167 for i in /tmp/data/*list* ; do
pascal@17931 1168 echo "=== extra ${i#*list} files"
pascal@17931 1169 cat $i
pascal@17931 1170 done >> $file
pascal@17931 1171 $DIALOG --clear \
paul@17935 1172 --title " Flavor info " \
pascal@17931 1173 --textbox $file 24 78
pascal@17931 1174 rm -rf /tmp/data
pascal@17931 1175 }
pascal@17931 1176
pascal@18771 1177 flavor()
pascal@18771 1178 {
pascal@18771 1179 cd /mnt
pascal@18771 1180 name="$(flavdata | cpio -t 2> /dev/null | sed 's/.[a-z]*$//;q')"
pascal@18771 1181 echo "Create ${name:=flavor}.flavor..."
pascal@18771 1182 tazlito iso2flavor "/mnt/$ISO" $name
pascal@18771 1183 ls -l $name.flavor 2> /dev/null || sleep 5
pascal@18771 1184 cd - > /dev/null
pascal@18771 1185 }
pascal@18771 1186
pascal@13697 1187 shell()
pascal@13697 1188 {
pascal@17491 1189 trap text 2
pascal@13713 1190 getty -n -l /bin/ash 38400 tty1 || sh
pascal@13697 1191 }
pascal@13697 1192
pascal@14247 1193 BIN=bin/mount.posixovl
pascal@14247 1194 [ -x /usr/s$BIN ] || mv /bin/mount.posixovl.iso2exe \
pascal@17489 1195 /usr/s$BIN 2> /dev/null || mv /bin/mount.posixovl.iso2exe /$BIN 2> /dev/null
pascal@16041 1196 mount_proc
pascal@18804 1197 for i in /sys/block/*/dev /sys/block/*/*/dev ; do
pascal@18804 1198 [ -s "$i" ] || continue
pascal@18804 1199 n=${i%/dev}
pascal@18804 1200 n=/dev/${n##*/}
pascal@18804 1201 [ -e $n ] && continue
pascal@18804 1202 mknod $n b $(sed 's/:/ /' < $i)
pascal@18804 1203 done
pascal@17489 1204 ISO="$(getarg bootfrom | sed 's/.://;s|\\|/|g')"
pascal@19510 1205 getiso || text 2> /dev/null
pascal@13713 1206 mount_loram
pascal@16041 1207 case "${ISO##*/}$(getarg mode)" in
pascal@16047 1208 *install*|*INSTALL*) install ;;
pascal@16047 1209 *live*|*LIVE*) live ;;
pascal@16047 1210 *text*|*TEXT*) text ;;
pascal@13691 1211 esac
pascal@17489 1212 which $DIALOG 2> /dev/null || DIALOG=tinydialog
pascal@13713 1213 dmesg > /tmp/dmesg
pascal@13691 1214
pascal@18778 1215 isotitle="$(blkid /mnt/$ISO | sed 's/.*LABEL="\([^"]*\).*/\1/') $(stat \
pascal@18778 1216 -c %y /media/cdrom | sed 's/ .*//') $(basename $ISO)"
pascal@13691 1217 while true; do
pascal@17491 1218 trap shell 2
pascal@16055 1219 keymap="$(cat /etc/keymap.conf 2> /dev/null)"
pascal@16055 1220 locale="$(sed '/^LANG=/!d;s/.*=//' /etc/locale.conf 2> /dev/null)"
pascal@14271 1221 cat > /tmp/dialog <<EOT
pascal@14271 1222 $DIALOG --clear \
pascal@18289 1223 --title " ${isotitle:-Welcome to Linux} " \
pascal@17454 1224 --menu "" 23 70 17 \
pascal@17489 1225 $(xfile tazkeymap "tazkeymap" "Select keyboard (${keymap:-none})") \
pascal@17489 1226 $(xfile tazlocale "tazlocale" "Select locale (${locale:-none})") \
pascal@17489 1227 $(cdfile boot/bzImage "live" "Linux RAM boot (full desktop)") \
pascal@17489 1228 "text" "Linux RAM boot" \
pascal@17635 1229 $(cdfile "README*" "readme" "Show the README file") \
pascal@18771 1230 $(gotcustomconf "getcustomconf" "Get custom config") \
pascal@17492 1231 $(gotisomd5 "isomd5" "Check the ISO image") \
pascal@17635 1232 $(cdfile "md5sum*" "md5" "Check the ISO files") \
pascal@17635 1233 $(cdfile "sha*sum*" "sha" "Check the ISO files") \
pascal@18034 1234 $(burnable "burniso" "Burn the ISO image") \
pascal@18034 1235 $(blankable "blankcd" "Blank the CD/DVD") \
pascal@16041 1236 $(gotposixovl "install" "Hard disk installation (UMSDOS way)") \
pascal@16041 1237 $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \
pascal@14271 1238 $(xfile tazusb "usbkey" "USB key read/write installation") \
pascal@17491 1239 $(ishybrid "usbbootkey" "USB boot key (read only)") \
paul@17935 1240 $(hasflavinfo "showfavinfo" "Show flavor extra info") \
pascal@18771 1241 $(xfile tazlito "flavor" "Get flavor file") \
pascal@17476 1242 $(fddata "fdbootstrap" "Create a floppy bootstrap") \
pascal@18771 1243 $(cdfile isolinux.cfg "floppyset" "Boot floppy set") \
pascal@17491 1244 "tazboot" "Get tazboot.exe Linux loader" \
pascal@17476 1245 $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \
pascal@17635 1246 $(cdexe "memtest*" "memtest" "Get Memtest86 DOS/EXE file") \
pascal@17635 1247 $(cdfilef "memtest*" "fdmemtest" "Create a Memtest86 boot floppy") \
pascal@18771 1248 $(:||cdfilex "memtest*" "runmemtest" "Start Memtest86") \
pascal@17635 1249 $(cdexe "?pxe" "pxe" "Get SliTaz Web boot DOS/EXE utility") \
pascal@17635 1250 $(cdfilef "?pxe" "fdpxe" "Create a SliTaz Web boot floppy") \
pascal@18771 1251 $(:||cdfilex "?pxe" "runpxe" "Start the SliTaz Web boot utility") \
pascal@14271 1252 $(xfile reboot "restart" "Restart the computer") \
pascal@14271 1253 $(xfile poweroff "stop" "Power off") \
pascal@13697 1254 "bootlog" "Linux boot messages" \
pascal@13697 1255 "shell" "Shell prompt" \
pascal@14271 1256
pascal@14271 1257 EOT
pascal@14271 1258 exec 3>&1
pascal@17489 1259 value=$(. /tmp/dialog 2>&1 1>&3)
pascal@13691 1260 retval=$?
pascal@13691 1261 exec 3>&-
pascal@13691 1262 [ $retval -eq 0 ] || continue
pascal@13691 1263 $value
pascal@13691 1264 done