tiny-slitaz rev 29

No hard coded boot menu
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Sep 20 21:20:45 2019 +0200 (2019-09-20)
parents 912635ac019d
children 11629aa4d9a4
files download.php helper step4.php step5.php
line diff
     1.1 --- a/download.php	Tue Sep 17 10:24:42 2019 +0200
     1.2 +++ b/download.php	Fri Sep 20 21:20:45 2019 +0200
     1.3 @@ -2,6 +2,8 @@
     1.4  
     1.5  function download($file,$name='')
     1.6  {
     1.7 +	$files = explode(" ",$file);
     1.8 +	$file = $files[0];
     1.9  	if ($name == '')
    1.10  		$name = basename($file);
    1.11  	if (isset($_POST['tmp_dir']))
    1.12 @@ -18,14 +20,12 @@
    1.13  if (isset($_POST['download'])) {
    1.14  	switch (substr($_POST['download'],0,6)) {
    1.15  	case "Kernel" : download("fs/boot/bzImage","kernel");
    1.16 -	case "Memtes" : download("fs/boot/memtest");
    1.17 -	case "GPXE (" : download("fs/boot/gpxe");
    1.18 -	case "IPXE (" : download("fs/boot/ipxe");
    1.19  	case "Rootfs" : download("rootfs.gz");
    1.20  	case "packag" : download("fs/etc/packages.conf");
    1.21  	case "Config" : shell_exec("sudo ./helper --mkcfg ".$_POST['tmp_dir']); 
    1.22  			download("config_files.cpio.gz");
    1.23  	case "Floppy" : $n=substr($_POST['download'],6,1);
    1.24 +			if ($n == " ") $n="1";
    1.25  			shell_exec("./helper --mkimg ".$_POST['tmp_dir']." ".
    1.26  			$_POST['fdsize']." ".$n); 
    1.27  			download("floppy".$n.".img");
    1.28 @@ -37,6 +37,7 @@
    1.29  	case "linux." : download("fs/boot/config","linux.config");
    1.30  	case "busybo" : download("fs/boot/config-busybox","busybox.config");
    1.31  	case "post_i" : download("post_install.log");
    1.32 +	default       : download("fs/boot/".strtolower($_POST['download']));
    1.33  	}
    1.34  }
    1.35  if (isset($_GET['dl'])) {
     2.1 --- a/helper	Tue Sep 17 10:24:42 2019 +0200
     2.2 +++ b/helper	Fri Sep 20 21:20:45 2019 +0200
     2.3 @@ -213,14 +213,67 @@
     2.4  
     2.5  
     2.6  
     2.7 -get_suggested()
     2.8 +list_suggested()
     2.9  {
    2.10  	local pkg
    2.11  	pkg=pkgs/$1/receipt
    2.12 -	[ -s $pkg ] || pkg=$2/pkgs/$1/receipt
    2.13 +	TMPDIR=$2
    2.14 +	[ -s $pkg ] || pkg=$TMPDIR/pkgs/$1/receipt
    2.15  	[ -s $pkg ] || pkg=$(get_receipt $@)
    2.16 +	SUGGESTED=
    2.17  	. $pkg
    2.18 -	echo -n $SUGGESTED
    2.19 +	SUGG=
    2.20 +	for i in $SUGGESTED; do
    2.21 +		case " $@ " in
    2.22 +		*\ $i\ *);;
    2.23 +		*) SUGG="$SUGG $i";;
    2.24 +		esac
    2.25 +	done
    2.26 +	if [ "$SUGG" ]; then
    2.27 +		cat <<EOT
    2.28 +	<hr />
    2.29 +	<p>
    2.30 +	You may want to install the following package(s) too:
    2.31 +	</p>
    2.32 +<div class="large">
    2.33 +<table>
    2.34 +	<thead>
    2.35 +		<tr>
    2.36 +			<th> </th>
    2.37 +			<th>Package</th>
    2.38 +			<th>Version</th>
    2.39 +			<th>Description</th>
    2.40 +			<th>Disk</th>
    2.41 +			<th>Memory</th>
    2.42 +			<th> </th>
    2.43 +		</tr>
    2.44 +	</thead>
    2.45 +	<tbody>
    2.46 +EOT
    2.47 +		checked='checked="checked" '
    2.48 +		[ $TMPDIR/uploadconf ] && checked=
    2.49 +		for i in $SUGG; do
    2.50 +			i=$(grep -l "PACKAGE=\"$i\"" pkgs/*/receipt)
    2.51 +			. $i
    2.52 +			cat <<EOT
    2.53 +		<!-- $GROUP -->
    2.54 +		<tr>
    2.55 +			<td><input type="checkbox" name="suggested[]" value="$PACKAGE" $checked /></td>
    2.56 +			<td><a href="?dl=$PACKAGE-$VERSION&amp;tmp=$TMPDIR">$PACKAGE</a></td>
    2.57 +			<td>$VERSION</td>
    2.58 +			<td>$SHORT_DESC</td>
    2.59 +			<td>$PACKED_SIZE</td>
    2.60 +			<td>$UNPACKED_SIZE</td>
    2.61 +			<td>$(grep -qs ^config_form $i && echo '&raquo;')</td>
    2.62 +		</tr>
    2.63 +EOT
    2.64 +		done
    2.65 +		cat <<EOT
    2.66 +	</tbody>
    2.67 +</table>
    2.68 +</div>
    2.69 +EOT
    2.70 +	fi
    2.71  }
    2.72  
    2.73  
    2.74 @@ -374,6 +427,15 @@
    2.75  }
    2.76  
    2.77  
    2.78 +boot_files()
    2.79 +{
    2.80 +	[ -s $1/fs/boot/bootmenu ] && while read bin button text; do
    2.81 +		cat <<EOT
    2.82 +		<input name="download" value="${button%%,*} ($(du -h \
    2.83 +$1/fs/boot/$bin | awk '{ printf "%s",$1 }'))" type="submit" />
    2.84 +EOT
    2.85 +	done < $1/fs/boot/bootmenu
    2.86 +}
    2.87  
    2.88  
    2.89  lzma_set_size()
    2.90 @@ -395,19 +457,20 @@
    2.91  
    2.92  
    2.93  case "$1" in
    2.94 -	--list-modules)	list_modules $@ ;;
    2.95 -	--list-kernels)	list_kernels $@ ;;
    2.96 -	--list-pkgs)	list_pkgs $@ ;;
    2.97 +	--list-modules)		list_modules $@ ;;
    2.98 +	--list-kernels)		list_kernels $@ ;;
    2.99 +	--list-pkgs)		list_pkgs $@ ;;
   2.100  	--get-form)		get_form $2 $3 ;;
   2.101  	--get-note)		get_note $2 $3 ;;
   2.102 -	--pre-install)	do_pre_install $2 $3 ;;
   2.103 -	--post-install)	do_post_install $2 $3 ;;
   2.104 +	--pre-install)		do_pre_install $2 $3 ;;
   2.105 +	--post-install)		do_post_install $2 $3 ;;
   2.106  	--depends)		get_depends $@ ;;
   2.107 -	--pkgs-extract)	pkgs_extract $2 $3 ;;
   2.108 +	--pkgs-extract)		pkgs_extract $2 $3 ;;
   2.109  	--remove)		rm -rf $2; exit ;;
   2.110  	--get-pkg)		get_package $2 $3 ;;
   2.111 -	--get-suggested)	get_suggested $2 $3 ;;
   2.112 +	--list-suggested)	list_suggested $2 $3 $@ ;;
   2.113  	--init)			init ;;
   2.114 +	--boot-files)		boot_files $2 ;;
   2.115  esac
   2.116  
   2.117  
   2.118 @@ -445,20 +508,16 @@
   2.119  	append initrd=/boot/rootfs rw root=/dev/null vga=normal
   2.120  
   2.121  EOT
   2.122 -	while read bin keys; do
   2.123 -		[ -s $tmp/fs/boot/$bin ] &&
   2.124 -		cp $tmp/fs/boot/$bin $tmp/iso/boot/ &&
   2.125 -		KEY="$KEY ${keys%% *}" &&
   2.126 +	[ -s $tmp/fs/boot/bootmenu ] && while read bin keys text; do
   2.127 +		keys=${keys#*,}
   2.128 +		KEY="$KEY ${keys%%,*}"
   2.129 +		cp $tmp/fs/boot/$bin $tmp/iso/boot/$bin
   2.130  		cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
   2.131 -label $keys
   2.132 +label ${keys//,/ } $bin
   2.133  	kernel /boot/$bin
   2.134  
   2.135  EOT
   2.136 -	done <<EOT
   2.137 -memtest		test memtest mem
   2.138 -ipxe		web zeb ipxe pxe
   2.139 -EOT
   2.140 -	[ -s $tmp/fs/boot/ipxe ] && cp $tmp/fs/boot/ipxe $tmp/iso/boot/ &&
   2.141 +	done < $tmp/fs/boot/bootmenu
   2.142  	[ "$KEY" ] && echo "say You can boot: slitaz (default)$KEY" >> \
   2.143  		$tmp/iso/boot/isolinux/isolinux.cfg
   2.144  	cat >> $tmp/iso/boot/isolinux/isolinux.cfg <<EOT
   2.145 @@ -488,19 +547,14 @@
   2.146  	if [ ! -s out ]; then
   2.147  		cp fs/boot/bzImage slitaz.img
   2.148  		sh fs/boot/bundle slitaz.img rootfs.gz
   2.149 -		if [ -s fs/boot/ipxe ] && [ -s fs/boot/memtest ]; then
   2.150 -			sh fs/boot/bundle out "   SliTaz boot menu" slitaz.img \
   2.151 -				"Tiny SliTaz" fs/boot/ipxe "SliTaz web boot" \
   2.152 -				fs/boot/memtest "Check memory"
   2.153 -		elif [ -s fs/boot/ipxe ]; then
   2.154 -			sh fs/boot/bundle out "   SliTaz boot menu" slitaz.img \
   2.155 -				"Tiny SliTaz" fs/boot/ipxe "SliTaz web boot"
   2.156 -		elif [ -s fs/boot/memtest ]; then
   2.157 -			sh fs/boot/bundle out "   SliTaz boot menu" slitaz.img \
   2.158 -				"Tiny SliTaz" fs/boot/memtest "Check memory"
   2.159 -		else
   2.160 -			mv slitaz.img out
   2.161 -		fi
   2.162 +		if [ -s fs/boot/bootmenu ]; then
   2.163 +			echo -n "sh fs/boot/bundle out '   SliTaz boot menu'"
   2.164 +			echo -n " slitaz.img 'Tiny SliTaz'"
   2.165 +			while read bin button text; do
   2.166 +				echo -n " fs/boot/$bin '$text'"
   2.167 +			done < fs/boot/bootmenu
   2.168 +		fi | sh
   2.169 +		[ -s out ] || mv slitaz.img out
   2.170  	fi
   2.171  	rm -f xa* 2> /dev/null
   2.172  	split -b ${3:-1474560} out
     3.1 --- a/step4.php	Tue Sep 17 10:24:42 2019 +0200
     3.2 +++ b/step4.php	Fri Sep 20 21:20:45 2019 +0200
     3.3 @@ -34,32 +34,8 @@
     3.4  				$_POST['tmp_dir']); 
     3.5  		unset($pkgs[$key]);
     3.6  		$_POST['toconfigure'] = implode(" ", $pkgs);
     3.7 -		$suggested = shell_exec("./helper --get-suggested $pkg ".
     3.8 -					$_POST['tmp_dir']); 
     3.9 -		if ($suggested != "") {
    3.10 -			$sugghead = <<<EOT
    3.11 -	<hr />
    3.12 -	<p>
    3.13 -	You may want to install the following package(s) too:
    3.14 -	</p>
    3.15 -	<ol>
    3.16 -EOT;
    3.17 -			$checked = "checked=\"checked\" ";
    3.18 -			if (file_exists($_POST["tmp_dir"]."uploadconf")) $checked = "";
    3.19 -			foreach (explode(" ", $suggested) as $sug)
    3.20 -				if (!strstr(" ".$_POST['packages']." ",
    3.21 -				    " ".$sug." ")) {
    3.22 -					$output .= $sugghead ;
    3.23 -					$sugghead = "";
    3.24 -					$output .= <<<EOT
    3.25 -		<li>
    3.26 -		<input type="checkbox" name="suggested[]" value="$sug" $checked/>$sug
    3.27 -		</li>
    3.28 -EOT;
    3.29 -			}
    3.30 -			if ($sugghead == "")
    3.31 -				$output .= "	</ol>\n";
    3.32 -		}
    3.33 +		$output .= shell_exec("./helper --list-suggested $pkg ".
    3.34 +			$_POST['tmp_dir']." ".$_POST['packages']); 
    3.35  		if ($output == "") {
    3.36  			shell_exec("sudo ./helper --post-install $pkg ".
    3.37  				   $_POST['tmp_dir']); 
     4.1 --- a/step5.php	Tue Sep 17 10:24:42 2019 +0200
     4.2 +++ b/step5.php	Fri Sep 20 21:20:45 2019 +0200
     4.3 @@ -21,7 +21,6 @@
     4.4  <table>
     4.5  	<tr><td class="first">Bootable images:</td><td>
     4.6  		<div id="floppyset">
     4.7 -		</div>
     4.8  		<select name="fdsize" id="fdsize" onchange="floppy_form()">
     4.9  <?php
    4.10        $title="Neither Windows nor emm386 supported. Needs a real mode DOS";
    4.11 @@ -36,6 +35,7 @@
    4.12  	  echo ">$nm</option>\n";
    4.13        } ?>
    4.14  		</select>
    4.15 +		</div>
    4.16  		<input name="download" value="DOS/EXE" type="submit"
    4.17  		       title="<?php echo $title; ?>" />
    4.18  <?php if (file_exists("/boot/isolinux/isolinux.bin")) {
    4.19 @@ -55,18 +55,7 @@
    4.20  					 ?>)" type="submit" />
    4.21  		<input name="download" value="Rootfs (<?php echo show_size("rootfs.gz");
    4.22  			 ?>)" title="For the initrd= parameter" type="submit" />
    4.23 -<?php if (show_size("fs/boot/memtest") != "") { ?>
    4.24 -		<input name="download" value="Memtest (<?php echo show_size("fs/boot/memtest");
    4.25 -					 ?>)" type="submit" />
    4.26 -<?php } ?>
    4.27 -<?php if (show_size("fs/boot/gpxe") != "") { ?>
    4.28 -		<input name="download" value="GPXE (<?php echo show_size("fs/boot/gpxe");
    4.29 -					 ?>)" type="submit" />
    4.30 -<?php } ?>
    4.31 -<?php if (show_size("fs/boot/ipxe") != "") { ?>
    4.32 -		<input name="download" value="IPXE (<?php echo show_size("fs/boot/ipxe");
    4.33 -					 ?>)" type="submit" />
    4.34 -<?php } ?>
    4.35 +<?php echo shell_exec("sudo ./helper --boot-files ".$_POST['tmp_dir']); ?>
    4.36  	</td></tr>
    4.37  
    4.38  
    4.39 @@ -101,6 +90,7 @@
    4.40  <script>
    4.41  function floppy_form()
    4.42  {
    4.43 +	var element;
    4.44  	var fds=document.getElementById("fdsize");
    4.45  	for (i=1;;i++) {
    4.46  		element=document.getElementById("Floppy"+i);
    4.47 @@ -108,13 +98,14 @@
    4.48  		else break;
    4.49  	}
    4.50  	for (i=<?php echo filesize($_POST['tmp_dir']."out"); ?>, j=1; i > 0; j++, i -= fds.value) {
    4.51 -		var element = document.createElement("input");
    4.52 +		element = document.createElement("input");
    4.53  		element.name = "download";
    4.54  		element.type = "submit";
    4.55  		element.value = element.id = "Floppy"+j;
    4.56  		element.title = "You can use dd or rawrite to create the floppy disk";
    4.57  		document.getElementById("floppyset").appendChild(element);
    4.58  	}
    4.59 +	if (j == 2) element.value = "Floppy image";
    4.60  }
    4.61  
    4.62  floppy_form();