tazinst rev 91

installer.cgi: make it more NetSurf-compatible (ajax don't work anyway), change page_redirection() to use HTTP redirection (no more that intermediate redirection page).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Oct 05 15:28:38 2017 +0300 (2017-10-05)
parents cf56992b574f
children f60513b03e7f
files installer.cgi
line diff
     1.1 --- a/installer.cgi	Fri Sep 29 08:45:28 2017 +0200
     1.2 +++ b/installer.cgi	Thu Oct 05 15:28:38 2017 +0300
     1.3 @@ -2,7 +2,7 @@
     1.4  #
     1.5  # Main CGI interface for Tazinst, the SliTaz installer.
     1.6  #
     1.7 -# Copyright (C) 2012-2016 SliTaz GNU/Linux - BSD License
     1.8 +# Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License
     1.9  #
    1.10  # Authors : Dominique Corbex <domcox@slitaz.org>
    1.11  #
    1.12 @@ -97,7 +97,7 @@
    1.13  
    1.14  	<footer>
    1.15  		<form>
    1.16 -			<button name="page" value="install" data-icon="slitaz"
    1.17 +			<button type="submit" name="page" value="install" data-icon="slitaz"
    1.18  				title="$(_ 'Proceed to a new SliTaz installation')"
    1.19  				>$(_ 'Install SliTaz')</button>
    1.20  		</form>
    1.21 @@ -123,7 +123,7 @@
    1.22  
    1.23  	<footer>
    1.24  		<form>
    1.25 -			<button name="page" value="upgrade" data-icon="upgrade"
    1.26 +			<button type="submit" name="page" value="upgrade" data-icon="upgrade"
    1.27  				title="$(_ 'Upgrade an existing SliTaz system')"
    1.28  				>$(_ 'Upgrade SliTaz')</button>
    1.29  		</form>
    1.30 @@ -146,7 +146,6 @@
    1.31  in the previous century..." '\slitaz')</p>
    1.32  	</div>
    1.33  
    1.34 -	<footer>
    1.35  		<form action="boot.cgi">
    1.36  			<input type="hidden" name="iso"/>
    1.37  			<input type="hidden" name="action" value="install"/>
    1.38 @@ -169,9 +168,8 @@
    1.39  	cat <<EOT
    1.40  			</select></td></tr>
    1.41  			</table>
    1.42 -			<button data-icon="install">$(_ 'Install')</button>
    1.43 +			<button type="submit" data-icon="install">$(_ 'Install')</button>
    1.44  		</form>
    1.45 -	</footer>
    1.46  </section>
    1.47  EOT
    1.48  }
    1.49 @@ -183,7 +181,7 @@
    1.50  
    1.51  exec_gparted() {
    1.52  	/bin/su - -c \
    1.53 -	"exec env DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' /usr/sbin/gparted"
    1.54 +	"exec env DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' /usr/sbin/gparted" >/dev/null 2>&1
    1.55  }
    1.56  
    1.57  
    1.58 @@ -222,7 +220,7 @@
    1.59  	<footer>
    1.60  		<!-- Launch GParted -->
    1.61  		<form>
    1.62 -			<button name="page" value="gparted" data-icon="hdd"
    1.63 +			<button type="submit" name="page" value="gparted" data-icon="hdd"
    1.64  				title="$(_ 'Launch GParted, the partition editor tool')"
    1.65  				>$(_ 'Execute GParted')</button>
    1.66  		</form>
    1.67 @@ -248,7 +246,7 @@
    1.68  	local error
    1.69  
    1.70  	# set default media
    1.71 -	[ "$media" ] || media="$(tazinst list media | cut -d ' ' -f1)"
    1.72 +	[ -n "$media" ] || media="$(tazinst list media | cut -d ' ' -f1)"
    1.73  
    1.74  	comment "Source selection"
    1.75  	# cdrom
    1.76 @@ -799,8 +797,8 @@
    1.77  	cat <<EOT
    1.78  <hr/>
    1.79  <form>
    1.80 -	<button name="page" value="$back_page" data-icon="back" >$back_msg</button>
    1.81 -	<button name="page" value="$next_page" data-icon="start">$next_msg</button>
    1.82 +	<button type="submit" name="page" value="$back_page" data-icon="back" >$back_msg</button>
    1.83 +	<button type="submit" name="page" value="$next_page" data-icon="start">$next_msg</button>
    1.84  </form>
    1.85  EOT
    1.86  }
    1.87 @@ -809,7 +807,7 @@
    1.88  moveto_home() {
    1.89  	cat <<EOT
    1.90  <form>
    1.91 -	<button name="page" value="home" data-icon="back"
    1.92 +	<button type="submit" name="page" value="home" data-icon="back"
    1.93  	>$(_ 'Back to Installer Start Page')</button>
    1.94  </form>
    1.95  EOT
    1.96 @@ -819,6 +817,12 @@
    1.97  page_redirection() {
    1.98  	local page="$1"
    1.99  	cat <<EOT
   1.100 +HTTP/1.1 301 Moved Permanently
   1.101 +Location: $SCRIPT_NAME?page=$1
   1.102 +
   1.103 +EOT
   1.104 +
   1.105 +	true || cat <<EOT
   1.106  <!DOCTYPE html>
   1.107  <html>
   1.108  <head>
   1.109 @@ -843,14 +847,18 @@
   1.110  #----------
   1.111  
   1.112  check_ressources() {
   1.113 -	local errorcode=0
   1.114 -	comment "check_ressources"
   1.115 -	if ! [ -x /usr/sbin/tazinst ] ; then
   1.116 +	local errorcode=0 buffer=$(mktemp)
   1.117 +	{
   1.118 +		header; xhtml_header; comment "check_ressources"
   1.119 +	} > $buffer
   1.120 +	if ! [ -x /usr/sbin/tazinst ]; then
   1.121 +		{
   1.122  		h4 $(_ 'Tazinst Error')
   1.123  		p $(_ '%s, the backend to %s is missing.' '<strong>tazinst</strong>' 'slitaz-installer';
   1.124  		_ 'Any installation can not be done without %s.' 'tazinst')
   1.125  		p $(_ "Check %s permissions, or reinstall the %s package." \
   1.126  		'tazinst' 'slitaz-installer')
   1.127 +		} >> $buffer
   1.128  		errorcode=1
   1.129  	else
   1.130  		# check tazinst minimum version
   1.131 @@ -858,12 +866,14 @@
   1.132  		r=$TAZINST_MINIMUM_VERSION
   1.133  		if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
   1.134  				'{v=$v+0}{ if (v < r) exit 1}') ; then
   1.135 +			{
   1.136  			h4 $(_ 'Tazinst Error')
   1.137  			p $(_ '%s, the %s backend, is not at the minimum required version.' \
   1.138  			'<strong>tazinst</strong>' 'slitaz-installer';
   1.139  			_ 'Any installation can not be done without %s.' 'tazinst')
   1.140  			p $(_ 'Reinstall the %s package, or use %s in CLI mode.' \
   1.141  			'slitaz-installer' 'tazinst')
   1.142 +			} >> $buffer
   1.143  			errorcode=1
   1.144  		fi
   1.145  		# check tazinst maximum version
   1.146 @@ -871,15 +881,19 @@
   1.147  		r=$TAZINST_MAXIMUM_VERSION
   1.148  		if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
   1.149  				'{v=$v+0}{ if (v > r) exit 1}') ; then
   1.150 +			{
   1.151  			h4 $(_ 'Tazinst Error')
   1.152  			p $(_ "%s, the %s backend, is at a higher version than the maximum authorized \
   1.153  by the %s." '<strong>tazinst</strong>' 'slitaz-installer' 'slitaz-installer';
   1.154  			_ 'Any installation cannot be done.')
   1.155  			p $(_ 'Reinstall the %s package, or use %s in CLI mode.' \
   1.156  			'slitaz-installer' 'tazinst')
   1.157 +			} >> $buffer
   1.158  			errorcode=1
   1.159  		fi
   1.160  	fi
   1.161 +	[ "$errorcode" -eq 1 ] && cat $buffer
   1.162 +	rm $buffer
   1.163  	return $errorcode
   1.164  }
   1.165  
   1.166 @@ -1169,27 +1183,24 @@
   1.167  # main
   1.168  #
   1.169  
   1.170 -header
   1.171 -
   1.172  case "$(GET page)" in
   1.173  	home)
   1.174 -		xhtml_header
   1.175 +		header; xhtml_header
   1.176  		select_action
   1.177  		select_install
   1.178  		select_upgrade
   1.179  		select_evaluate
   1.180  		;;
   1.181  	evaluate)
   1.182 -		xhtml_header
   1.183 +		header; xhtml_header
   1.184  		select_evaluate
   1.185  		;;
   1.186  	install)
   1.187 -		xhtml_header
   1.188  		/usr/sbin/tazinst set mode install "$INSTFILE"
   1.189  		page_redirection partitioning
   1.190  		;;
   1.191  	partitioning)
   1.192 -		xhtml_header
   1.193 +		header; xhtml_header
   1.194  		form_start
   1.195  		display_mode
   1.196  		select_gparted
   1.197 @@ -1198,16 +1209,14 @@
   1.198  		;;
   1.199  	gparted)
   1.200  		exec_gparted
   1.201 -		xhtml_header
   1.202  		page_redirection partitioning
   1.203  		;;
   1.204  	upgrade)
   1.205 -		xhtml_header
   1.206  		/usr/sbin/tazinst set mode upgrade "$INSTFILE"
   1.207  		page_redirection input
   1.208  		;;
   1.209  	input)
   1.210 -		xhtml_header
   1.211 +		header; xhtml_header
   1.212  		add_style
   1.213  		form_start
   1.214  		display_mode
   1.215 @@ -1216,15 +1225,23 @@
   1.216  		form_end
   1.217  		;;
   1.218  	execute)
   1.219 -		xhtml_header
   1.220 -		form_start
   1.221 -		display_mode
   1.222 -		save_settings
   1.223 +		buffer=$(mktemp)
   1.224 +		{
   1.225 +			header; xhtml_header
   1.226 +			form_start
   1.227 +			display_mode
   1.228 +			save_settings
   1.229 +		} > $buffer
   1.230  		if ! (/usr/sbin/tazinst check all $INSTFILE > /dev/null); then
   1.231 +			rm $buffer
   1.232  			page_redirection "input&CHECK=yes"
   1.233  		else
   1.234 -			tazinst_run && moveto_page home reboot \
   1.235 -						|| moveto_page input failed
   1.236 +			cat $buffer; rm $buffer
   1.237 +			if tazinst_run; then
   1.238 +				moveto_page home reboot
   1.239 +			else
   1.240 +				moveto_page input failed
   1.241 +			fi
   1.242  		fi
   1.243  		form_end
   1.244  		;;
   1.245 @@ -1232,14 +1249,13 @@
   1.246  		/usr/sbin/tazinst clean "$INSTFILE"
   1.247  		reboot ;;
   1.248  	failed)
   1.249 -		xhtml_header
   1.250 +		header; xhtml_header
   1.251  		form_start
   1.252  		tazinst_log
   1.253  		moveto_home
   1.254  		form_end
   1.255  		;;
   1.256  	*)
   1.257 -		xhtml_header
   1.258  		if check_ressources; then
   1.259  			/usr/sbin/tazinst new "$INSTFILE"
   1.260  			page_redirection home