#!/bin/sh
#Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
#v3.02 Nov 2007 BK: updated. handle PET pkgs only.
#v3.99 apr2008 BK: run /usr/local/petget/pkg_chooser.sh instead of petget.
#v404 add choice of Universal Installer.
#w015 march 2009 BK: update for Woof.
#110402 added button to choose and install SFS file.
#110813 fixed package-management url.
#110814 01micko: convert script from gtkdialog2 to gtkdialog3+.
#110910 BK: get a syntax error with gtkdialog3 (patriot-e version), bump to gtkdialog4.
#120201 rodin.s: internationalized.
# 26apr2013 shinobar: frugalinstaller, horisontal layout
# 10dec2013 shinobar: dotpup1, gtkdialog

export TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN=dotpup
eval_gettext () {
  local myMESSAGE=$(gettext "$1")
  eval echo \"$myMESSAGE\"
}

#how do i called
MYOPT=$1
[ "$MYOPT" ] || MYOPT=$(basename $0)
MYOPT=$(echo $MYOPT | tr -dc '0-9')

. /etc/DISTRO_SPECS

# has frugalinstaller? quickpet? # 29nov11 shinobar: sfs_load
which frugalinstaller &>/dev/null && HASFRUGAL="yes" || HASFRUGAL=""
which quickpet &>/dev/null && HASQUICKPET="yes" || HASQUICKPET=""
which sfs_load &>/dev/null && HASSFSLOAD="yes" || HASSFSLOAD=""
which f2fs-usb-installer &>/dev/null && HASF2FS="yes" || HASF2FS=""

NTOOLS=2
FRUGALBUTTON=""
if [ "$HASFRUGAL" != "" ]; then
  NTOOLS=$(($NTOOLS + 1))
  FRUGALBUTTON='
  <hbox>
    <vbox homogeneous="true">
      <vbox>
        <text use-markup="true" xalign="1"><label>"<b>'$(gettext "Frugal Installer")'</b>"</label></text>
        <text xalign="1"><label>'$(gettext "RECOMMENDED install style of Puppy")'</label></text>
      </vbox>
    </vbox>
    <button>
      '"`/usr/lib/gtkdialog/xml_button-icon puppy_install.svg big`"'
      <action>frugalinstaller &</action>
      <action>EXIT:13</action>
    </button>
  </hbox>'
fi
F2FSBUTTON=""
if [ "$HASF2FS" != "" ]; then
  NTOOLS=$(($NTOOLS + 1))
  F2FSBUTTON='
  <hbox>
    <vbox homogeneous="true">
      <vbox>
        <text use-markup="true" xalign="1"><label>"<b>'$(gettext "F2fs USB Installer")'</b>"</label></text>
        <text xalign="1"><label>'$(gettext "Install Puppy on USB flash devices using f2fs file system")'</label></text>
      </vbox>
    </vbox>
    <button>
      '"`/usr/lib/gtkdialog/xml_button-icon puppy_install.svg big`"'
      <action>f2fs-usb-installer &</action>
      <action>EXIT:13</action>
    </button>
  </hbox>'
fi

SFSBUTTON=''
if [ "$HASSFSLOAD" != "" ]; then
  SFSBUTTON='
  <hbox>
    <text><label>'$(gettext 'Load and unload SFS packages using the SFS-load')'</label></text>
    <button>
      '"`/usr/lib/gtkdialog/xml_button-icon package_sfs.svg big`"'
      <action>sfs_load &</action>
      <action>EXIT:13</action>
    </button>
  </hbox>'
fi

#make dialog

PUPFRAME=""
[ "$MYOPT" = "2" ] || PUPFRAME='
<frame '$(gettext 'Install Puppy')'>
  '"`/usr/lib/gtkdialog/xml_info fixed puppy_install.svg 60 "$(gettext 'Puppy can be installed to just about anything, including internal hard drive USB drive, and optical disc. If for example you are now running Puppy from live-CD and fancy booting Puppy off a USB Flash drive, this is the right place.')"`"'
  <vbox margin="5" space-expand="true" space-fill="true">
    <vbox space-expand="false" space-fill="false">
      '$FRUGALBUTTON'
      <hbox>
        <vbox homogeneous="true">
          <vbox>
            <text use-markup="true" xalign="1"><label>"<b>'$(gettext "Universal installer")'</b>"</label></text>
            <text xalign="1"><label>'$(gettext "Required for 'full' install")'</label></text>
          </vbox>
        </vbox>
        <button>
          '"`/usr/lib/gtkdialog/xml_button-icon puppy_install.svg big`"'
          <action>/usr/sbin/puppyinstaller &</action>
          <action>EXIT:13</action>
        </button>
      </hbox>
      <hbox>
        <vbox homogeneous="true">
          <vbox>
            <text use-markup="true" xalign="1"><label>"<b>'$(gettext "BootFlash USB installer")'</b>"</label></text>
            <text xalign="1"><label>'$(gettext "If your computer won't boot from a USB drive")'</label></text>
          </vbox>
        </vbox>
        <button>
          '"`/usr/lib/gtkdialog/xml_button-icon puppy_install.svg big`"'
          <action>/usr/sbin/bootflash &</action>
          <action>EXIT:14</action>
        </button>
      </hbox>
      '$F2FSBUTTON'
    </vbox>
    <vbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <text space-expand="true" space-fill="true"><label>""</label></text>
      </hbox>
      <vbox space-expand="false" space-fill="false">
        <hbox space-expand="true" space-fill="true">
          <button space-expand="false" space-fill="false">
            '"`/usr/lib/gtkdialog/xml_button-icon help`"'
            <label>'$(gettext 'Installation introduction webpage')'</label>
            <action>defaultbrowser file:///usr/share/doc/installation.htm & </action>
          </button>
          <text space-expand="true" space-fill="true"><label>""</label></text>
        </hbox>
      </vbox>
    </vbox>
  </vbox>
</frame>'
 
APPFRAME=""
[ "$MYOPT" = "1" ] || APPFRAME='
<frame '$(gettext 'Install applications')'>
  '"`/usr/lib/gtkdialog/xml_info fixed package_add.svg 60 "$(eval_gettext "The Puppy Package Manager is a tool for installing and uninstalling packages (applications). There are online repositories of ${DISTRO_BINARY_COMPAT} and Puppy packages -- the latter are known as PET packages and are identified by '.pet' on the end of their filename. Note that apart from the official ${DISTRO_BINARY_COMPAT} and PET repositories, Puppy enthusiasts have created many PETs at other locations, and all you need to do is download one and click on it to install it.")" " " "$(gettext 'SFS files are application combo-packs, very easy to install and uninstall.')"`"'
  <vbox margin="5" space-expand="true" space-fill="true">
    <vbox space-expand="false" space-fill="false">
    <hbox>
      <text><label>'$(gettext 'Puppy Package Manager')'</label></text>
      <button tooltip-text="PET Packages">
        '"`/usr/lib/gtkdialog/xml_button-icon package_add.svg big`"'
        <action>/usr/local/petget/pkg_chooser.sh &</action>
        <action>EXIT:14</action>
      </button>
    </hbox>
    <hbox>
      <text><label>'$(gettext 'Choose an SFS file from the official repo')'</label></text>
      <button tooltip-text="SFS Modular Packages">
        '"`/usr/lib/gtkdialog/xml_button-icon package_sfs.svg big`"'
        <action>/usr/sbin/sfsget &</action>
        <action>EXIT:14</action>
      </button>
    </hbox>
    '$SFSBUTTON'
    </vbox>
    <vbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <text space-expand="true" space-fill="true"><label>""</label></text>
      </hbox>
      <vbox space-expand="false" space-fill="false">
        <hbox space-expand="true" space-fill="true">
          <button space-expand="false" space-fill="false">
          '"`/usr/lib/gtkdialog/xml_button-icon help`"'
          <label>'$(gettext 'Package Manager introduction webpage')'</label>
          <action>defaultbrowser http://puppylinux.com/development/package-management.htm & </action>
          </button>
          <text space-expand="true" space-fill="true"><label>""</label></text>
        </hbox>
      </vbox>
    </vbox>
  </vbox>
</frame>'


if [ "$PUPFRAME" ] && [ "$APPFRAME" ]; then
	export Puppy_Install='
	<window title="'$(gettext 'Install')'" icon-name="gtk-preferences">
	<vbox>
	  <vbox space-expand="false" space-fill="false">
	    <hbox space-expand="true" space-fill="true">
	      <vbox space-expand="false" space-fill="false">
	        '"`/usr/lib/gtkdialog/xml_pixmap info.svg icon`"'
	      </vbox>
	      <vbox>
	        <text xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>" '$(gettext "The word 'install' can mean two different things, either to")'"</label></text>
	        <text xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>" <b>1.)</b> '$(gettext "Install additional applications in the current Puppy.")'"</label></text>
	        <text xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>" <b>2.)</b> '$(gettext "Install Puppy to some other media.")'"</label></text>
	        <text width-request="5" space-expand="false" space-fill="false"><label>""</label></text>
	      </vbox>
	    </hbox>
	  </vbox>
	  <notebook labels="'$(gettext 'Install Puppy')'|'$(gettext 'Install applications')'" space-expand="true" space-fill="true">
	    <vbox>
	      '$PUPFRAME'
	    </vbox>
	    <vbox>
	      '$APPFRAME'
	    </vbox>
	  </notebook>
	  <hbox space-expand="false" space-fill="false">
	    <button>
	      '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
	      <label>'$(gettext 'Quit')'</label>
	    </button>
	  </hbox>
	</vbox>
	</window>'
else
	export Puppy_Install='
	<window title="'$(gettext 'Install')'" icon-name="gtk-preferences">
	<vbox>
	  '$PUPFRAME'
	  '$APPFRAME'
	  <hbox space-expand="false" space-fill="false">
	    <button>
	      '"`/usr/lib/gtkdialog/xml_button-icon quit`"'
	      <label>'$(gettext 'Quit')'</label>
	    </button>
	  </hbox>
	</vbox>
	</window>'
fi

. /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
gtkdialog -p Puppy_Install || echo "$Puppy_Install" >&2

###END###