#!/bin/bash
#
# Server Wizard - A wizard for settings and features in Porteus Kiosk Server
# Author: T.Jokiel <http://porteus-kiosk.org>

## ====================================================================
## variables
## ====================================================================

## We need to export these variables so they are available to gtkdialog
ICONS=/usr/share/pixmaps
export PCID=`grep ^ID: /etc/version | cut -d" " -f2`-`grep ^MBID: /etc/version | cut -d" " -f2`

## Create temporary working directory
rm -rf /tmp/kwiz.* 2>/dev/null
export TMPDIR=/tmp/kwiz.$$
mkdir -p $TMPDIR

## ====================================================================
## Main dialog
## ====================================================================

################# Setup required files
export IMAGEONE="/usr/share/icons/oxygen/22x22/actions/gtk-no.png"
export IMAGETWO="/usr/share/icons/oxygen/22x22/actions/gtk-ok.png"
export IMGPASS=$TMPDIR/img.png
cp -L $IMAGEONE $TMPDIR/img.png

## Set some text files that should exist before the main
## gtkdialog is rendered
echo 0 > $TMPDIR/.knetPage
lsblk -o NAME,TYPE,MODEL,SIZE | egrep -v 'NAME|loop|part|rom' | tr -s ' ' | sed -e 's/ /_/g' -e 's/_/|/1' -e 's/_/|/1' -e 's/\(.*\)_/\1|/' > $TMPDIR/block.txt
echo 22 > $TMPDIR/sshport.txt
echo "1024" > $TMPDIR/swap.txt
echo "debug acpi=force reboot=pci,force" > $TMPDIR/kparam.txt

## Setup browser:
if [ -e /mnt/ISO/xzm/002-chrome.xzm ]; then
    mkdir -p /dev/shm && chmod 1777 /dev/shm
    ln -sf /usr/bin/chrome /usr/bin/firefox
    chflag="-"
    ln -sf /usr/share/pixmaps/chrome-48.png /usr/share/pixmaps/browser-48.png
else
    ln -sf /usr/share/pixmaps/firefox-48.png /usr/share/pixmaps/browser-48.png
fi

# Launch wizard:
WIZARD_MAIN='
<window title="Server Wizard" icon-name="kiosk" resizable="false" width-request="780" height-request="580" decorated="true">
<vbox>

## <------- FIRST PAGE CONFIGURATIONS
<notebook page="0" show-tabs="false" show-border="false" labels="configurations|report|autoupdates|device"  height-request="540">

################## PAGE 0 SERVER CHOICE
<vbox margin="10">
        <text use-markup="true" yalign="1"><label>"<span weight='"'bold'"' size='"'x-large'"'>Server version</span>"</label></text>
        <hseparator></hseparator>
        <text xalign="0" width-request="740" wrap="true"><label>Select Porteus Kiosk Server version you would like to install. Variant '"'Basic'"' is available for free, '"'Premium'"' requires paid subscription (€300/year) and offers many more features.</label></text>
        <text><label>""</label></text>
        <hbox>
	    <text xalign="0" width-request="641" wrap="true"><label>Click on the '"'Visit webpage'"' button to find complete description and comparison of the systems:</label></text>
	    <button>
		<label>Visit webpage</label>
		<action>su '$chflag' guest -c "DISPLAY=:0 firefox http://porteus-kiosk.org/server.html#pricing &"; sleep 3</action>
	    </button>
	</hbox>
        <text><label>""</label></text>
        <text xalign="0" width-request="740" wrap="true"><label>Before buying the subscription you are entitled to 30 days free trial of the '"'Premium'"' version of the Server. Please contact sales@porteus-kiosk.org in order to activate the trial and provide Server ID printed below.</label></text>
        <hbox>
	    <text xalign="0" width-request="631" wrap="true"><label>Please use the '"'Ctrl+c'"' keyboard shortcut to copy the Server ID then send us the trial request.</label></text>
	    <button>
		<label>Launch browser</label>
		<action>su '$chflag' guest -c "DISPLAY=:0 firefox http://porteus-kiosk.org &"; sleep 3</action>
	    </button>
	</hbox>
        <text><label>""</label></text>
        <hseparator></hseparator>
        <text xalign="1" width-request="640" use-markup="true" selectable="true"><label>"<span weight='"'bold'"'>Server identification number (Server ID): '$PCID'</span>"</label></text>
        <hseparator></hseparator>
        <text><label>""</label></text>
        <text><label>""</label></text>
        <hbox>
                <button image-position="2" tooltip-text="Porteus Kiosk Server version Basic">
                        <width>170</width>
                        <height>170</height>
                        <input file>'$ICONS'/server-basic-128.png</input>
                        <action>echo "Basic" > /tmp/server-choice</action>
                        <action>echo 2 > '$TMPDIR'/.knetPage</action>
                        <action function="refresh">nPage</action>
                        <action function="show">butBurn</action>
                </button>
                <text width-request="80"><label>" "</label></text>
                <button image-position="2" tooltip-text="Porteus Kiosk Server version Premium">
                        <width>170</width>
                        <height>170</height>
                        <input file>'$ICONS'/server-premium-128.png</input>
                        <action>echo "Premium" > /tmp/server-choice</action>
                        <action>echo 1 > '$TMPDIR'/.knetPage</action>
                        <action function="refresh">nPage</action>
                        <action function="show">butNextWizard</action>
                </button>
                <text width-request="140"><label>" "</label></text>
        </hbox>
</vbox>

################## PAGE 1 WIZARD
<vbox scrollable="true" margin="8" hscrollbar-policy="2">
## <------- PAGE TITLE
        <text use-markup="true" yalign="1"><label>"<span weight='"'bold'"' size='"'x-large'"'>Server Wizard</span>"</label></text>
        <hseparator></hseparator>
        <text xalign="0" use-markup="true"><label>"<span weight='"'bold'"'>Scroll down for more options.</span>"</label></text>
        <text><label>""</label></text>

######### ICMP PROTOCOL
        <frame ICMP protocol>
                <hbox>
                        <pixmap><input file>'$ICONS'/icmp-48.png</input><variable>pixIcmp</variable></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Allow incoming ICMP. This is useful when you want to check if the Server is up and running from another computer using the ping utility">
                                        <label>Enable</label>
                                        <variable>rbutIcmpEn</variable>
                                        <default>false</default>
                                        <action>if true echo allow_icmp_protocol=yes > $TMPDIR/icmp.tmp</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Disable the ability to ping the Server from other computers" file-monitor="true" auto-refresh="true">
                                        <label>Disable</label>
                                        <variable>rbutIcmpDis</variable>
                                        <default>true</default>
                                        <input file>'$TMPDIR'/icmpDisable.mon</input>
                                        <action>if true rm $TMPDIR/icmp.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
## <------- This text is blank padding to put space after radiobuttons
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <variable>txtIcmp</variable>
                                <label>"Answer incoming ICMP queries. This is useful when you want to check if the Server is up and running from another computer using the ping utility."</label>
                        </text>
                </hbox>
        </frame>

######### SWAP FILE
	<frame SWAP file>
		<hbox>
			<pixmap><input file>'$ICONS'/swap-48.png</input></pixmap>
			<vbox>
				<radiobutton tooltip-text="Create and use swap file">
					<label>Enable</label>
					<default>false</default>
					<action>if true echo swapfile=1024 > '$TMPDIR'/swap.tmp</action>
					<action>if true get_input "Swap file" "Enter the size (in megabytes) of the swap file. Your installation device must be large enough to hold system partition: 900 MB and the swap file." 830 '$TMPDIR'/swap.tmp swapfile '$TMPDIR'/swap.txt</action>
				</radiobutton>
				<radiobutton tooltip-text="Do not use the swap file">
					<label>Disable</label>
					<default>true</default>
					<action>if true rm '$TMPDIR'/swap.tmp 2>/dev/null</action>
				</radiobutton>
			</vbox>
			<text width-request="10"><label>""</label></text>
			<text yalign="0" width-request="560">
				<label>Create and use a swap file, the virtual memory extension of PCs real memory (RAM). Swap file will be created on a persistent partition of the booting device. Only enable this option on servers with low amount of RAM.</label>
			</text>
		</hbox>
    </frame>

######### REMOVABLE DEVICES
        <frame Removable devices>
                <hbox>
                        <pixmap><input file>'$ICONS'/removable-media-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Enable support for removable devices">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <action>if true echo "removable_devices=yes" > '$TMPDIR'/removable.tmp</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Do not allow removable devices">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <action>if true rm '$TMPDIR'/removable.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>Enable support for removable devices like usb sticks or flash cards. The only accepted filesystems are: FAT16/32, NTFS and XFS. Devices are mounted with write access under the /media folder. Its necessary to eject removable devices safely by clicking on relevant button in the bottom panel. This feature allows to copy files from external storage media or save e.g. system logs on them.</label>
                        </text>
                </hbox>
        </frame>

######### TIME ZONE
        <frame Time zone>
                <hbox>
                        <pixmap><input file>'$ICONS'/timezone-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Enable custom timezone">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <action>if true gtk_list "Choose a timezone" "Choose a timezone from the list below:" 830 timezone /opt/scripts/files/wizard/timezones.txt '$TMPDIR'/timezone.tmp ntpserver</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Use Factory as default timezone">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <action>if true rm '$TMPDIR'/timezone.tmp '$TMPDIR'/ntp-server.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>Choose a timezone from a list of world timezones. Hardware clock will be set through the NTP protocol during every system boot if PC is connected to the network. Make sure that your company firewall is not blocking NTP protocol.</label>
                        </text>
                </hbox>
        </frame>

######### KEYBOARD LAYOUT
        <frame Primary keyboard layout>
                <hbox>
                        <pixmap><input file>'$ICONS'/keyboard-48.png</input><variable>pixKbdPri</variable></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Enable custom keyboard layout" file-monitor="true" auto-refresh="true">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <input file>'$TMPDIR'/pkbdl.mon</input>
                                        <variable>rbutKbdPriEn</variable>
                                        <action>if true gtk_list "Primary keyboard layout" "Choose a keyboard layout from the list:" 830 primary_keyboard_layout /opt/scripts/files/wizard/keyboards.txt '$TMPDIR'/keyboard1.txt keyboard1</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Use en-US as default keyboard layout" file-monitor="true" auto-refresh="true">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <variable>rbutKbdPriDis</variable>
                                        <input file>'$TMPDIR'/KbdPri.mon</input>
                                        <action>if true rm '$TMPDIR'/keyboard1.tmp 2>/dev/null</action>
                                        <action>if true sed -i /^primary_keyboard_layout/d /tmp/config 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>Choose a primary keyboard from the list of known keyboard layouts and variants. You can also choose a secondary keyboard layout below. The default layout is English (US).</label>
                                <variable>txtKbdPri</variable>
                        </text>
                </hbox>
        </frame>
	<frame Secondary keyboard layout>
                <hbox>
                        <pixmap><input file>'$ICONS'/keyboard-48.png</input><variable>pixKbdSec</variable></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Enable secondary keyboard layout">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <variable>rbutKbdSecEn</variable>
                                        <action>if true gtk_list "Secondary keyboard layout" "Choose a keyboard layout from the list:" 830 secondary_keyboard_layout /opt/scripts/files/wizard/keyboards.txt '$TMPDIR'/keyboard1.txt keyboard2</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Use only one keyboard layout" file-monitor="true" auto-refresh="true">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <variable>rbutKbdSecDis</variable>
                                        <input file>'$TMPDIR'/KbdSec.mon</input>
                                        <action>if true rm '$TMPDIR'/keyboard2.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>Choose a secondary keyboard layout. Use Ctrl+Space key combination to switch between the layouts when system is installed.</label>
                                <variable>txtKbdSec</variable>
                        </text>
                </hbox>
        </frame>

######### SCREEN
	<frame Screen resolution>
                <hbox>
                        <pixmap><input file>'$ICONS'/screenres-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Set a lower screen resolution">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <action>if true xrandr|grep [0-9].*x[0-9]|grep -v connect|tr -s "'" "'"|cut -d"'" "'" -f2 > '$TMPDIR'/res.txt</action>
                                        <action> if true gtk_list "Choose resolution" "Choose from one of the supported screen resolutions or enter your own below (provided value must be supported by the monitor)." 830 screen_resolution '$TMPDIR'/res.txt '$TMPDIR'/res.tmp res</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Use the maximum available screen resolution">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <action>if true rm '$TMPDIR'/res.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>By default the system will use maximum supported screen resolution but you may also set a custom lower resolution.</label>
                        </text>
                </hbox>
      </frame>

######### SOUND CARD
        <frame Default system sound card>
                <hbox>
                        <pixmap><input file>'$ICONS'/sound-card-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Set default sound card">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <action>if true aplay -l | grep ^card > '$TMPDIR'/sound-cards.txt</action>
                                        <action>if true gtk_list "Default system sound card" "Choose default sound device from the list below:" 830 default_sound_card '$TMPDIR'/sound-cards.txt '$TMPDIR'/selected-card.txt sound-card</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Do not change default sound card">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <action>if true rm '$TMPDIR'/sound-card.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>Set default sound card in case when you have no sound in the system.</label>
                        </text>
                </hbox>
        </frame>

######### SOUND VOLUME LEVEL
        <frame Sound volume>
                <hbox>
                        <pixmap><input file>'$ICONS'/sound-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Set custom sound volume level">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <action>if true gtk_get_range "Set sound volume level" "Use the slider to select a percentage value of the sound level to use. When set to 0 the sound will be muted." 830 volume_level '$TMPDIR'/sound.tmp 100 % 90</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Set sound volume level to 90%">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <action>if true rm '$TMPDIR'/sound.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>By default the system will set the sound volume to 90% but you may also choose a custom level by enabling this option.</label>
                        </text>
                </hbox>
        </frame>

######### SESSION PASSWORD
        <frame Session password>
                <hbox>
                        <pixmap><input file>'$ICONS'/lock-48.png</input><width>48</width></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Protect the session with a password">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <action>if true get_input "Session password" "Enter the password which will be used to unlock the session for the user." 830 '$TMPDIR'/sessionp.tmp session_password '$TMPDIR'/sessionp.txt</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Keep the session unlocked">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <action>if true rm $TMPDIR/sessionp.tmp</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>"Protect the session with a password. Only authorized users can access the Administration Panel and use the Server. Session password must be used to unlock the session in case it was locked through the exit menu."</label>
                        </text>
                </hbox>
        </frame>

######### DPMS
        <frame DPMS>
                <hbox>
                        <pixmap><input file>'$ICONS'/dpms-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Enable DPMS">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <action>if true echo dpms_idle=10 > '$TMPDIR'/dpms.tmp 2>/dev/null</action>
                                        <action>if true get_input "DPMS idle" "Set the time (in minutes) of inactivity after which the monitor will be powered off." 830 '$TMPDIR'/dpms.tmp dpms_idle '$TMPDIR'/dpms.txt</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Disable DPMS">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <action>if true rm '$TMPDIR'/dpms.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>Enable DPMS (Display Power Management Signaling) which turns the monitor off after X minutes of keyboard/mouse inactivity.</label>
                        </text>
                </hbox>
        </frame>

######### UEFI
	<frame UEFI support>
                <hbox>
                        <pixmap><input file>'$ICONS'/uefi-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Add UEFI component to the ISO" file-monitor="true" auto-refresh="true">
                                        <label>Enable</label>
                                        <default>true</default>
                                        <input file>'$TMPDIR'/uefiEn.mon</input>
                                        <action>if true echo uefi.zip > '$TMPDIR'/uefi.add</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Do not add the UEFI component to the ISO" file-monitor="true" auto-refresh="true">
                                        <label>Disable</label>
                                        <default>false</default>
                                        <input file>'$TMPDIR'/uefiDis.mon</input>
                                        <action>if true rm '$TMPDIR'/uefi.add 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>UEFI component allows booting Porteus Kiosk on PCs supplied with UEFI firmware and others supplied with traditional BIOS. Disable this component if you experience booting problems.</label>
                        </text>
                </hbox>
        </frame>

######### ADDITIONAL FONTS
	<frame Additional fonts>
                <hbox>
                        <pixmap><input file>'$ICONS'/fonts-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Include additional fonts">
                                        <label>Enable</label>
                                        <default>false</default>
                                        <action>if true echo 06-fonts.xzm > '$TMPDIR'/fonts.add</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Exclude additional fonts">
                                        <label>Disable</label>
                                        <default>true</default>
                                        <action>if true rm '$TMPDIR'/fonts.add 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>Full dejavu font package and also various other fonts for displaying characters from asian (Chinese, Hindi, Korean, Japanese, Thai, Vietnamese) and other languages.</label>
                        </text>
                </hbox>
        </frame>

######### SSH COMPONENT
	<frame SSH service>
                <hbox>
                        <pixmap><input file>'$ICONS'/ssh-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Include SSH service" file-monitor="true" auto-refresh="true">
                                        <label>Enable</label>
                                        <variable>rbutSSHEn</variable>
                                        <default>false</default>
                                        <input file>'$TMPDIR'/enablessh.mon</input>
                                        <action>if true echo 08-ssh.xzm > '$TMPDIR'/ssh.add</action>
                                        <action>if true gtk_password "Root Password" "Enter a root password that will be used to connect to Porteus Kiosk Server through SSH." "root"</action>
                                        <action>if true get_input "SSH Port" "Enter a port number for the SSH service (optional)" 830 $TMPDIR/sshport.tmp ssh_port $TMPDIR/sshport.txt</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Exclude SSH service" file-monitor="true" auto-refresh="true">
                                        <label>Disable</label>
                                        <variable>rbutSSHDis</variable>
                                        <default>true</default>
                                        <input file>'$TMPDIR'/disablessh.mon</input>
                                        <action>if true rm '$TMPDIR'/ssh.* 2>/dev/null</action>
                                        <action>if true rm '$TMPDIR'/sshport.tmp 2>/dev/null</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>SSH (Secure shell) service allows to connect/communicate to Porteus Kiosk Server via the SSH protocol. Selected port will be opened in the system firewall configuration.</label>
                        </text>
                </hbox>
	</frame>

######### VNC SERVER
	<frame VNC service>
                <hbox>
                        <pixmap><input file>'$ICONS'/vnc-48.png</input></pixmap>
                        <vbox>
                                <radiobutton tooltip-text="Include VNC service" file-monitor="true" auto-refresh="true">
                                        <label>Enable</label>
                                        <variable>rbutVNCEn</variable>
                                        <default>false</default>
                                        <input file>'$TMPDIR'/enablevnc.mon</input>
                                        <action>if true echo 09-x11vnc.xzm > '$TMPDIR'/vnc.add</action>
                                        <action>if true gtk_password "VNC Password" "Enter a VNC password (must be 8 characters or less) that will be used to connect to Porteus Kiosk Server through VNC." vnc</action>
                                        <action>if true echo "vnc_interactive=yes" > '$TMPDIR'/vnc-control.tmp</action>
                                        <action>if true get_vnc_server</action>
                                </radiobutton>
                                <radiobutton tooltip-text="Exclude VNC service" file-monitor="true" auto-refresh="true">
                                        <label>Disable</label>
                                        <variable>rbutVNCDis</variable>
                                        <default>true</default>
                                        <input file>'$TMPDIR'/disablevnc.mon</input>
                                        <action>if true rm '$TMPDIR'/vnc.* '$TMPDIR'/vncport.tmp '$TMPDIR'/vnc-control.tmp '$TMPDIR'/vnc-localhost.tmp '$TMPDIR'/vnc-key.tmp</action>
                                </radiobutton>
                        </vbox>
                        <text width-request="10"><label>""</label></text>
                        <text yalign="0" width-request="560">
                                <label>VNC service allows to connect to the graphical interface of Porteus Kiosk Server from another computer via the VNC protocol. Useful for monitoring or controlling Porteus Kiosk Server remotely. Port 5900 will be opened in the system firewall configuration.</label>
                        </text>
                </hbox>
	</frame>

######### KERNEL PARAMETERS
	<frame Kernel parameters>
		<hbox>
			<pixmap><input file>'$ICONS'/tux-48.png</input></pixmap>
			<vbox>
				<radiobutton tooltip-text="Enter additional kernel parameters to the bootloader">
					<label>Enable</label>
					<default>false</default>
					<action>if true get_input "Additional kernel parameters" "Provide kernel parameters below:" 830 '$TMPDIR'/kparam.tmp kernel_parameters '$TMPDIR'/kparam.txt</action>
				</radiobutton>
				<radiobutton tooltip-text="Run the system without additional kernel parameters">
					<label>Disable</label>
					<default>true</default>
					<action>if true rm $TMPDIR/kparam.tmp</action>
				</radiobutton>
			</vbox>
			<text width-request="10"><label>""</label></text>
			<text yalign="0" selectable="true" width-request="560">
			    <label>"Enter Linux kernel parameters which will be added to the system bootloader configuration. Enable this option only if you are are having problems with the hardware, e.g. power management does not work, wifi speed is slow, system hangs on a reboot. Full list of supported kernel parameters can be find here: https://www.kernel.org/doc/Documentation/kernel-parameters.txt."</label>
			</text>
		</hbox>
	</frame>

</vbox>

################## PAGE 2 BURN
<vbox margin="10">
        <text use-markup="true" yalign="1"><label>"<span weight='"'bold'"' size='"'x-large'"'>Server installation</span>"</label></text>
        <hseparator></hseparator>
        <text xalign="0" width-request="740" wrap="true" use-markup="true"><label>"Please choose the target device (must have at least <span weight='"'bold'"' color='"'red'"'>2 GB</span> size) to which you will be installing Porteus Kiosk Server."</label></text>
        <text><label>""</label></text>
        <text xalign="0" width-request="740"><label>"Installation options:"</label></text>
        <vbox>
                <radiobutton>
                        <label>Preserve persistent partition (client data, configs, logs, custom Server startup scripts, etc)</label>
                        <default>true</default>
                        <action>if true rm -f /tmp/format_device /tmp/zero_device</action>
                </radiobutton>
                <radiobutton>
                        <label>Quick formatting</label>
                        <default>false</default>
                        <action>if true touch /tmp/format_device && rm -f /tmp/zero_device</action>
                </radiobutton>
                <radiobutton>
                        <label>Erase the device '"'byte after byte'"' (completion time depends on size and speed of selected device)</label>
                        <default>false</default>
                        <action>if true touch /tmp/zero_device && rm -f /tmp/format_device</action>
                </radiobutton>
        </vbox>
        <text><label>""</label></text>
        <text xalign="0" width-request="740" wrap="true" use-markup="true"><label>"<span weight='"'bold'"' color='"'red'"'>WARNING:</span> when you click the '"'Install system'"' button then the installation process will start immediately. Any existing operating system (Windows, Linux, OS X) or other data will be replaced with Porteus Kiosk Server image. This action is irreversible and you can not blame us for any potential data loss. Be careful when selecting the device!"</label></text>
        <text><label>""</label></text>
        <hseparator></hseparator>        <table>
                <variable>tblTarget</variable>
                <width>700</width>
                <label>"NAME               |TYPE           |MODEL                                              |SIZE"</label>
                <height>250</height>
                <input file>'$TMPDIR'/block.txt</input>
                <action>echo $tblTarget > '$TMPDIR'/target.txt</action>
        </table>
</vbox>


######### END OF PAGES
<variable>nPage</variable>
<input file>'$TMPDIR'/.knetPage</input>
</notebook>

######### BUTTONS
<hbox>
        <button visible="false" tooltip-text="Proceed">
                <label>Next</label>
                <variable>butNextWizard</variable>
                <input file stock="gtk-yes"></input>
                <action>process_settings</action>
                <action>echo 2 > '$TMPDIR'/.knetPage</action>
                <action function="refresh">nPage</action>
                <action condition="command_is_true( [ `grep 2 '$TMPDIR'/.knetPage` ] && echo true )">show:butBurn</action>
                <action condition="command_is_true( [ `grep 2 '$TMPDIR'/.knetPage` ] && echo true )">hide:butNextWizard</action>
        </button>
	<button visible="false" tooltip-text="Burn Server ISO on selected device">
		<label>Install Server</label>
		<variable>butBurn</variable>
		<input file>/usr/share/icons/oxygen/16x16/devices/drive-harddisk.png</input>
		<action condition="command_is_true( [ ! -f '$TMPDIR'/target.txt ] && echo true )">gtk_warning "Missing parameter" "You must choose a target device to burn the ISO to." 600</action>
		<action>test -e '$TMPDIR'/target.txt && { test $(lsblk -b -o TYPE,SIZE /dev/$tblTarget | egrep -v "SIZE|part" | rev | cut -d" " -f1 | rev | sed s/......$//) -gt 1950 || { rm -f '$TMPDIR'/target.txt; gtk_warning "Device too small" "You must choose a target device which is at least 2 GB in size." 600; }; }</action>
		<action condition="command_is_true( [ ! -f '$TMPDIR'/target.txt ] && echo true )" function="break">break</action>
		<action>echo "burn_dev=$tblTarget" >> /tmp/config</action>
		<action function="exit">finished</action>
	</button>
</hbox>

</vbox>
</window>'

echo "$WIZARD_MAIN" | sed '/^##/d' | gtkdialog -i /opt/scripts/files/wizard/wizard-functions -s -c > $TMPDIR/output
