wok rev 17924

syslinux/taziso: batch mode
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Apr 11 11:09:49 2015 +0200 (2015-04-11)
parents 36278632a653
children 1df528a60782
files syslinux/stuff/iso2exe/taziso
line diff
     1.1 --- a/syslinux/stuff/iso2exe/taziso	Fri Apr 10 16:29:03 2015 +0200
     1.2 +++ b/syslinux/stuff/iso2exe/taziso	Sat Apr 11 11:09:49 2015 +0200
     1.3 @@ -256,8 +256,11 @@
     1.4  
     1.5  windev()
     1.6  {
     1.7 -	DEV="$(blkid | grep -iE "(msdos|vfat|ntfs)" | sed 's/:.*//;s|/dev/||')"
     1.8 -	[ "$DEV" ] || return
     1.9 +	if [ -b "$1" ]; then
    1.10 +		device=$1
    1.11 +	else
    1.12 +		DEV="$(blkid | grep -iE "(msdos|vfat|ntfs)" | sed 's/:.*//;s|/dev/||')"
    1.13 +		[ "$DEV" ] || return
    1.14  	cat > /tmp/dialog$$ <<EOT
    1.15  $DIALOG --clear \
    1.16  	--title " Select your Windows partition " \
    1.17 @@ -269,11 +272,12 @@
    1.18  		echo -n "/dev/$i \"$(($(cat /sys/block/*/$i/size)/2048))MB $label\" "
    1.19  	done)
    1.20  EOT
    1.21 -	exec 3>&1
    1.22 -	[ $? -eq 0 ] || return
    1.23 -	device=$(. /tmp/dialog$$ 2>&1 1>&3)
    1.24 -	exec 3>&-
    1.25 -	rm -f /tmp/dialog$$
    1.26 +		exec 3>&1
    1.27 +		[ $? -eq 0 ] || return
    1.28 +		device=$(. /tmp/dialog$$ 2>&1 1>&3)
    1.29 +		exec 3>&-
    1.30 +		rm -f /tmp/dialog$$
    1.31 +	fi
    1.32  	mnt=/tmp/mnt$$
    1.33  	mkdir -p $mnt && mount $device $mnt
    1.34  }
    1.35 @@ -419,17 +423,25 @@
    1.36  
    1.37  install()
    1.38  {
    1.39 -	windev || return
    1.40 +	windev $1 || return
    1.41  	packages_list=
    1.42  	packages_dir=
    1.43 -	_install && bootinstalled /sbin/init
    1.44 +	if [ "$1" ]; then
    1.45 +		doinstall
    1.46 +	else
    1.47 +		_install && bootinstalled /sbin/init
    1.48 +	fi
    1.49  	umount $mnt
    1.50  	rm -rf $mnt
    1.51  }
    1.52  
    1.53  inst2zip()
    1.54  {
    1.55 -	mkzip _install
    1.56 +	if [ "$1" ]; then
    1.57 +		doinstall
    1.58 +	else
    1.59 +		mkzip _install
    1.60 +	fi
    1.61  }
    1.62  
    1.63  _installtaz()
    1.64 @@ -453,17 +465,25 @@
    1.65  
    1.66  installtaz()
    1.67  {
    1.68 -	windev || return
    1.69 +	windev $1 || return
    1.70  	packages_list=
    1.71  	packages_dir=
    1.72 -	_installtaz && bootinstalled /boot/bzimage
    1.73 +	if [ "$1" ]; then
    1.74 +		doinstall tazusblike
    1.75 +	else
    1.76 +		_installtaz && bootinstalled /boot/bzimage
    1.77 +	fi
    1.78  	umount $mnt
    1.79  	rm -rf $mnt
    1.80  }
    1.81  
    1.82  insttaz2zip()
    1.83  {
    1.84 -	mkzip _installtaz
    1.85 +	if [ "$1" ]; then
    1.86 +		doinstall tazusblike
    1.87 +	else
    1.88 +		mkzip _installtaz
    1.89 +	fi
    1.90  }
    1.91  
    1.92  bootiso()
    1.93 @@ -512,9 +532,13 @@
    1.94  	dotwait "Checking files"
    1.95  	( cd /media/cdrom ; ${1:-md5sum -c md5sum*} ) > /tmp/data
    1.96  	rm -f /tmp/wait
    1.97 -	$DIALOG --clear \
    1.98 -		--title " Checked files " \
    1.99 -		--textbox /tmp/data 24 78
   1.100 +	if [ "$1 "]; then
   1.101 +		cat /tmp/data
   1.102 +	else
   1.103 +		$DIALOG --clear \
   1.104 +			--title " Checked files " \
   1.105 +			--textbox /tmp/data 24 78
   1.106 +	fi
   1.107  	rm -f /tmp/data
   1.108  }
   1.109  
   1.110 @@ -531,41 +555,50 @@
   1.111  {
   1.112  	gotcdfile 'sha*sum*'
   1.113  	sha=$(basename $file)
   1.114 -	md5 "${sha%sum*}sum -c ${file#/media/cdrom/}"
   1.115 +	md5 "${sha%sum*}sum -c ${file#/media/cdrom/}" $@
   1.116  }
   1.117  
   1.118  readme()
   1.119  {
   1.120  	gotcdfile 'README*'
   1.121 -	$DIALOG --clear \
   1.122 -		--title " Readme " \
   1.123 -		--textbox $file 24 78
   1.124 +	if [ "$1" ]; then
   1.125 +		cat $file
   1.126 +	else
   1.127 +		$DIALOG --clear \
   1.128 +			--title " Readme " \
   1.129 +			--textbox $file 24 78
   1.130 +	fi
   1.131  }
   1.132  
   1.133  bzimage()
   1.134  {
   1.135 -	$DIALOG --clear \
   1.136 -		--title " Create linux.exe ? " \
   1.137 -		--yes-label "Install" --yesno \
   1.138 +	if [ "$1" ]; then
   1.139 +		$DIALOG --clear \
   1.140 +			--title " Create linux.exe ? " \
   1.141 +			--yes-label "Install" --yesno \
   1.142  "\nLinux.exe launches the linux kernel under DOS (in real mode only).
   1.143  The cmdline arguments are supported except initrd=,
   1.144  vga= (you can try 'rdev -v') and mem= (partially).
   1.145  \nExample:\nC:\\> linux.exe root=/dev/hda2 ro panic=60\n
   1.146  " 12 70
   1.147 -	[ $? -eq 0 ] || return
   1.148 +		[ $? -eq 0 ] || return
   1.149 +	fi
   1.150  	cp /media/cdrom/boot/bzImage linux.exe
   1.151  }
   1.152  
   1.153  memtest()
   1.154  {
   1.155 -	$DIALOG --clear \
   1.156 -		--title " Create memtest.exe ? " \
   1.157 -		--yes-label "Install" --yesno \
   1.158 +	if [ -z "$1" ]; then
   1.159 +		$DIALOG --clear \
   1.160 +			--title " Create memtest.exe ? " \
   1.161 +			--yes-label "Install" --yesno \
   1.162  "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
   1.163  computers. BIOS based memory tests are a quick, cursory check and often
   1.164  miss many of the failures that are detected by Memtest86.\n
   1.165  " 12 70
   1.166 -	[ $? -eq 0 ] && gotcdfile 'memtest*' && cp $file memtest.exe
   1.167 +		[ $? -eq 0 ] || return
   1.168 +	fi
   1.169 +	gotcdfile 'memtest*' && cp $file memtest.exe
   1.170  }
   1.171  
   1.172  mkfat12()
   1.173 @@ -602,15 +635,18 @@
   1.174  
   1.175  fdmemtest()
   1.176  {
   1.177 -	$DIALOG --clear \
   1.178 -		--title " Create a Memtest86 boot floppy " \
   1.179 -		--yes-label "Create floppy" --yesno \
   1.180 +	if [ -z "$1" ]; then
   1.181 +		$DIALOG --clear \
   1.182 +			--title " Create a Memtest86 boot floppy " \
   1.183 +			--yes-label "Create floppy" --yesno \
   1.184  "\nMemtest86 is a thorough, stand alone memory test for x86 architecture
   1.185  computers. BIOS based memory tests are a quick, cursory check and often
   1.186  miss many of the failures that are detected by Memtest86.\n\n
   1.187  Please insert a blank disk in floppy drive.\n
   1.188  " 12 70
   1.189 -	[ $? -eq 0 ] && gotcdfile 'memtest*' && mkfloppy $file
   1.190 +		[ $? -eq 0 ] || return
   1.191 +	fi
   1.192 +	gotcdfile 'memtest*' && mkfloppy $file
   1.193  }
   1.194  
   1.195  pxe()
   1.196 @@ -630,22 +666,30 @@
   1.197  
   1.198  fdpxe()
   1.199  {
   1.200 -	$DIALOG --clear \
   1.201 -		--title " Create a SliTaz Web boot floppy " \
   1.202 -		--yes-label "Create floppy" --yesno \
   1.203 +	if [ -z "$1" ]; then
   1.204 +		$DIALOG --clear \
   1.205 +			--title " Create a SliTaz Web boot floppy " \
   1.206 +			--yes-label "Create floppy" --yesno \
   1.207  "\nBoot your operating system from the internet and enjoy a full system
   1.208  working entirely in RAM with speed and stability in mind. The Linux Kernel
   1.209  and the complete SliTaz compressed root filesystem will be loaded into RAM
   1.210  from the Web using PXE and HTTP protocols.\n\n
   1.211  Please insert a blank disk in floppy drive.\n
   1.212  " 12 70
   1.213 -	[ $? -eq 0 ] && gotcdfile '?pxe' && mkfloppy $file
   1.214 +		[ $? -eq 0 ] || return
   1.215 +	fi
   1.216 +	gotcdfile '?pxe' && mkfloppy $file
   1.217 +}
   1.218 +
   1.219 +menuitem()
   1.220 +{
   1.221 +	[ "$3" ] && shift
   1.222 +	echo -en "\"$1\"	\"$2\""
   1.223  }
   1.224  
   1.225  gotposixovl()
   1.226  {
   1.227 -	mount.posixovl 2>&1 | grep -qi usage && 
   1.228 -	echo -en "\"$1\"	\"$2\""
   1.229 +	mount.posixovl 2>&1 | grep -qi usage && menuitem "$@"
   1.230  }
   1.231  
   1.232  gotposixovlzip()
   1.233 @@ -655,12 +699,12 @@
   1.234  
   1.235  xfile()
   1.236  {
   1.237 -	[ "$(which $1)" ] && echo -en "\"$2\"	\"$3\""
   1.238 +	[ "$(which $1)" ] && menuitem "$@"
   1.239  }
   1.240  
   1.241  cdfile()
   1.242  {
   1.243 -	gotcdfile "$1" && echo -en "\"$2\"	\"$3\""
   1.244 +	gotcdfile "$1" && menuitem "$@"
   1.245  }
   1.246  
   1.247  isbzImage()
   1.248 @@ -671,10 +715,7 @@
   1.249  
   1.250  cdfilex()
   1.251  {
   1.252 -	gotcdfile "$1" &&
   1.253 -	[ "$(which kexec)" ] &&
   1.254 -	isbzImage &&
   1.255 -	echo -en "\"$2\"	\"$3\""
   1.256 +	gotcdfile "$1" && [ "$(which kexec)" ] && isbzImage && menuitem "$@"
   1.257  }
   1.258  
   1.259  cdfilef()
   1.260 @@ -686,15 +727,14 @@
   1.261  {
   1.262  	gotcdfile "$1" &&
   1.263  	[ $(get 0 $file 2>/dev/null || echo 0) -eq 23117 ] &&
   1.264 -	echo -en "\"$2\"	\"$3\""
   1.265 +	menuitem "$@"
   1.266  }
   1.267  
   1.268  misspkg()
   1.269  {
   1.270  	for i in zip kexec-tools posixovl ; do
   1.271  		[ -d /var/lib/tazpkg/installed/$i/ ] && continue
   1.272 -		[ "$1" != "install" ] &&
   1.273 -		echo -en "\"$1\"	\"$2\"" && return
   1.274 +		[ "$1" != "install" ] && menuitem "$@" && return
   1.275  		tazpkg get-install $i
   1.276  	done
   1.277  }
   1.278 @@ -710,21 +750,19 @@
   1.279  	[ $(get $C $ISO 4) -eq 1 ] || return
   1.280  	[ $(get $(($C+30)) $ISO 4) -eq $((0x88AA55)) ] || return
   1.281  	C=$((2048*$(get $(($C+40)) $ISO 4)))
   1.282 -	[ $(get $(($C+64)) $ISO 4) -eq 1886961915 ] &&
   1.283 -	echo -en "\"$1\"	\"$2\""
   1.284 +	[ $(get $(($C+64)) $ISO 4) -eq 1886961915 ] && menuitem "$@"
   1.285  }
   1.286  
   1.287  isiso()
   1.288  {
   1.289 -	[ $(get 32769 $ISO 4) -eq 808469571 ] &&
   1.290 -	echo -en "\"$1\"	\"$2\""
   1.291 +	[ $(get 32769 $ISO 4) -eq 808469571 ] && menuitem "$@"
   1.292  }
   1.293  
   1.294  gotisomd5()
   1.295  {
   1.296  	[ "$(which md5sum 2> /dev/null)" ] &&
   1.297  	[ $(get 0 $ISO) -eq 23117 ] &&
   1.298 -	[ $(get 18 $ISO) -ne 0 ] && echo -en "\"$1\"	\"$2\""
   1.299 +	[ $(get 18 $ISO) -ne 0 ] && menuitem "$@"
   1.300  }
   1.301  
   1.302  isomd5()
   1.303 @@ -742,6 +780,7 @@
   1.304  		echo "OK" || echo "ERROR"
   1.305  	fi
   1.306  	rm -f /tmp/wait
   1.307 +	[ "$1" ] || return 0
   1.308  	echo -e "\rPress RETURN to continue."
   1.309  	read n
   1.310  }
   1.311 @@ -783,27 +822,31 @@
   1.312  
   1.313  usbbootkey()
   1.314  {
   1.315 -	$DIALOG --clear \
   1.316 -		--title " Create a USB boot key " \
   1.317 -		--yes-label "Continue" --yesno \
   1.318 +	if [ -b "$1" ]; then
   1.319 +		device=$1
   1.320 +	else
   1.321 +		$DIALOG --clear \
   1.322 +			--title " Create a USB boot key " \
   1.323 +			--yes-label "Continue" --yesno \
   1.324  "\nThe USB key will be used like a CD-ROM. You will not be able to write
   1.325  any data on the boot partition.\n\n
   1.326  An extra FAT32 partition will be created with the remaining free space.\n\n
   1.327  $(tazusbmsg)Please plug your USB stick in now.\n 
   1.328  " 16 70
   1.329 -	[ $? -eq 0 ] || return
   1.330 -	usbdev || return
   1.331 +		[ $? -eq 0 ] || return
   1.332 +		usbdev || return
   1.333  	
   1.334 -	# perform dd in progress bar
   1.335 -	max=$(($(stat -c %s $ISO)/2048))
   1.336 -	i=0; ddq if=$ISO bs=1024k | ( 
   1.337 -	while ddq bs=1024k count=1 ; do 
   1.338 -		i=$(($i + 1))
   1.339 -		[ $i -gt $max ] && break
   1.340 -		echo $((($i*100)/$max)) | dialog --gauge \
   1.341 -			" The ISO image transfer can be long. Please wait..." \
   1.342 -			6 70 0 > /dev/tty 2>&1
   1.343 -	done ) > $device
   1.344 +		# perform dd in progress bar
   1.345 +		max=$(($(stat -c %s $ISO)/2048))
   1.346 +		i=0; ddq if=$ISO bs=1024k | ( 
   1.347 +		while ddq bs=1024k count=1 ; do 
   1.348 +			i=$(($i + 1))
   1.349 +			[ $i -gt $max ] && break
   1.350 +			echo $((($i*100)/$max)) | dialog --gauge \
   1.351 +				" The ISO image transfer can be long. Please wait..." \
   1.352 +				6 70 0 > /dev/tty 2>&1
   1.353 +		done ) > $device
   1.354 +	fi
   1.355  
   1.356  	# partition + fat32 format for the remaining space
   1.357  	for p in 0 16; do
   1.358 @@ -895,6 +938,17 @@
   1.359  [ -z "$(isiso 2> /dev/null)" ] && echo "Usage : $0 file.iso" && exit 1
   1.360  mount -o loop,ro $ISO /media/cdrom
   1.361  
   1.362 +if grep -q "^$2()" $0; then
   1.363 +	exe=$2
   1.364 +	shift 2
   1.365 +	if [ "$(eval $(grep "\"$exe\"" $0 | \
   1.366 +		sed '/^\$/!d;s/.(\(.*\)[\t ]*".*"[\t ]*".*/\1/'))" ]; then
   1.367 +		grep "\"$exe\"" $0 | sed '/^\$/!d;s/.*"[\t ]*"\(.*\)".*/\1/'
   1.368 +		$exe "$@"
   1.369 +	fi
   1.370 +	quit
   1.371 +fi
   1.372 +
   1.373  while true; do
   1.374  	cat > /tmp/dialog$$ <<EOT
   1.375  $DIALOG  --clear \
   1.376 @@ -911,7 +965,7 @@
   1.377  $(gotposixovlzip	"insttaz2zip"	"ZIP installation archive (TAZUSB way)") \
   1.378  $(xfile tazusb		"usbkey"	"USB key read/write installation") \
   1.379  $(ishybrid		"usbbootkey"	"USB boot key (read only)") \
   1.380 -			"tazboot"	"Get tazboot.exe Linux loader" \
   1.381 +$(menuitem		"tazboot"	"Get tazboot.exe Linux loader") \
   1.382  $(cdexe boot/bzImage	"bzimage"	"Get linux DOS/EXE file") \
   1.383  $(cdexe 'memtest*'	"memtest"	"Get Memtest86 DOS/EXE file") \
   1.384  $(cdfilef 'memtest*'	"fdmemtest"	"Create a Memtest86 boot floppy") \
   1.385 @@ -920,7 +974,7 @@
   1.386  $(cdfilef '?pxe'	"fdpxe"		"Create a SliTaz Web boot floppy") \
   1.387  $(cdfilex '?pxe'	"runpxe"	"Start the SliTaz Web boot utility") \
   1.388  $(misspkg		"missing"	"Install packages to get more options") \
   1.389 -			"quit"		"Quit this utility"
   1.390 +$(menuitem		"quit"		"Quit this utility")
   1.391  EOT
   1.392  	exec 3>&1
   1.393  	value=$(. /tmp/dialog$$ 2>&1 1>&3)