#!/bin/sh
#BK 2007, original idea from sunburnt
#Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html). 2007 www.puppylinux.com
#written for Puppy 2.16.
#/etc/rc.d/BOOTCONFIG has variable EXTRASFSLIST='kde.sfs devx_216.sfs'
# ...space-delimited list of .sfs files to be loaded.
# ...must be located at same place as the pup_save file (in /mnt/home)
#    or at '/' for full hd installation.
#v2.17
#/etc/rc.d/MODULESCONFIG has variables PCI_OVERRIDES, SKIPLIST
#that are read and managed by the BootManager.
#v4.02 bugfix, modules now .ko.gz.
#v4.02 /lib/modules/modules.dep.<kernver> no more.
#v403 yeslist_func, parameters may be added to modules.
#v409 bugfix, list of sfs files was picking up non-sfs files.
#v411 bugfix, when choose to add more than one module.
#v412 /etc/DISTRO_SPECS, renamed pup_xxx.sfs, pup_save.2fs etc.
#w001 pup files renamed to woofr001.sfs, woofsave.2fs.
#w007 renamed to woof-007.sfs
#w015 allow 6 extra sfs files, up from 3. w020 zdrv fix.
#w478 file prefix 'pup2' got screened out.
#v423 need to check sfs 3.x or 4.x.
#v424 do away with checkbox that overrides user choice and loads _nnn.sfs only.
#v424 advise of sfs-version-converter.
#100125 manage system services at bootup.
#100221 slight change to a message. 100301 add msg for lameSMBxplorer.
#100518 fixed showed wrong partition for /mnt/home.
#100607 kernel 2.6.27.47 has squashfs4.
#100710 if pupsave file is in a subdirectory, only look for extra sfs's in that subdirectory.
#100711 modify to look in both top dir and subdirectory.
#100809 some inappropriate sfs files were displaying as candidates in dual-pane window.
#100831 fix KERNELSUBVER for olpc people, have 'uname -r' returning version with '_'.
#100913 new simplified puppy filenames.
#101219 add gettext rodin.s
#101221 yaf-splash fix.
#101222 add changes to gettext-script rodin.s
# 4jan11 shinobar: notebook
export TEXTDOMAIN=usr_sbin
export TEXTDOMAINDIR=/usr/share/locale
export OUTPUT_CHARSET=UTF-8
eval_gettext () {
  local myMESSAGE=$(gettext "$1")
  eval echo \"$myMESSAGE\"
}
#. gettext.sh

export LANGORG=$LANG

#reentrant.
#$1='' then run the main window.
#$1=extrasfs then run the extrasfs_func.
CLPARAM1="$1"
CLPARAM2="$2"

CURRDIR="`pwd`"
. /etc/rc.d/PUPSTATE
. /etc/DISTRO_SPECS
#PUPPYVERSION="`cat /etc/puppyversion`"
KERNVER="`uname -r`"

#v424 remove...
#EXTRASFSAUTO='off' #user choices.
#if [ -f /etc/rc.d/BOOTCONFIG ];then
# . /etc/rc.d/BOOTCONFIG
# [ "`cat /etc/rc.d/BOOTCONFIG | grep 'EXTRASFSLIST'`" = "" ] && EXTRASFSAUTO='on'
#else
# EXTRASFSAUTO='on'
#fi
[ ! -f /etc/rc.d/BOOTCONFIG ] && touch /etc/rc.d/BOOTCONFIG #v424
. /etc/rc.d/BOOTCONFIG #v424

KERNELSUBVER=`echo -n "$KERNVER" | cut -f 3 -d '.' | cut -f 1 -d '-' | cut -f 1 -d '_'` #v423 100831
SUB_SUB_KERNELVER=`echo -n "$KERNVER" | cut -f 1 -d '-' | cut -f 4 -d '.'` #100607
SFSSTR='squashfs, version 3' #v423
[ $KERNELSUBVER -gt 28 ] && SFSSTR='squashfs, version 4' #v423
[ $KERNELSUBVER -eq 27 ] && [ $SUB_SUB_KERNELVER -gt 46 ] && SFSSTR='squashfs, version 4' #100607

#v3.02
. /etc/rc.d/MODULESCONFIG
DEFAULT_SERIAL="false"
DEFAULT_FAST="false"
[ "$BYPASSSERIALPROBING" = "yes" ] && DEFAULT_SERIAL="true"
[ "$FASTBOOTMODULESLIST" != "" ] && DEFAULT_FAST="true"

if [ "$PUPMODE" = "5" ];then
 xmessage "$(gettext 'ERROR. Must shutdown and create a personal save file first.')"
 exit
fi

xEXTRASFSMNTPTx="" #100711
if [ "$PUP_HOME" = "" ];then #defined in PUPSTATE.
 EXTRASFSMNTPT='/'
 MSGx="`eval_gettext \"Note2: These files are at '/' (in \\\$PDEV1 partition)\"`"
 MSGz='/'
else
 EXTRASFSMNTPT="/initrd${PUP_HOME}"
 xHOMEPART="$PDEV1" #100518
 [ "$PUPSAVE" ] && xHOMEPART="`echo -n "$PUPSAVE" | cut -f 1 -d ','`" #100518
 #MSGx="Note2: These files are at /mnt/home (same as '${DISTRO_FILE_PREFIX}save')"
 MSGz='/mnt/home'
 #100711 modify to look in both top dir and subdirectory...
 #100710 if pupsave is in a subdirectory, only look in that...
 if [ "$PUPSAVE" ];then #this test probably not needed
  xPSUBDIR="`echo -n "$PUPSAVE" | cut -f 3 -d ',' | sed -e 's%/[^/]*$%%'`" #ex: sda3,ext2,/pup220/spupsave.2fs will return /pup220
  if [ "$xPSUBDIR" ];then
   MSGz="/mnt/home or /mnt/home${xPSUBDIR}"
   xEXTRASFSMNTPTx="/initrd${PUP_HOME}${xPSUBDIR}"'/*.sfs' #100711
  fi
 fi
 MSGx="`eval_gettext \"Note2: These files are at \\\${MSGz} (in \\\${xHOMEPART} partition)\"`" #100221 100518 100710
fi
#for multisession cd, extra sfs files have to be on the cd...
#v3.97 sfs files are at '/', saved with a session...
if [ "$PUPMODE" = "77" ];then
# MPATTERN="/dev/${PDEV1} "
# EXTRASFSMNTPT="`mount | grep "$MPATTERN" | cut -f 3 -d ' '`"
# #...it may not be mounted, then gets mounted below.
# MSGx="Note2: These files are on the Puppy boot CD"
 MSGz='/'
# if [ "$EXTRASFSMNTPT" = "" ];then
  EXTRASFSMNTPT='/'
 xEXTRASFSMNTPTx="" #100711
  MSGx="$(gettext 'Note2: All SFS files have to get loaded into RAM from CD')"
# fi
fi

extrasfs_func() {

 UNMOUNTME=""
 #if [ "$PUPMODE" = "77" ];then
 # if [ "$EXTRASFSMNTPT" = "" ];then
 #  xmessage "Make sure Puppy CD inserted in drive /dev/$PDEV1 RIGHT NOW!"
 #  mkdir -p /mnt/$PDEV1
 #  mount -t $DEV1FS /dev/$PDEV1 /mnt/$PDEV1 #DEV1FS, PDEV1 are in PUPSTATE.
 #  [ ! $? -eq 0 ] && return 1
 #  EXTRASFSMNTPT="/mnt/$PDEV1"
 #  UNMOUNTME="/mnt/$PDEV1"
 # fi
 #fi
 	
 #cd $EXTRASFSMNTPT
 #v409 lobster gets some non-sfs files in ALLSFSLIST ...i have no idea how, but
 #need an extra grep filter here... w007 new name woof-007.sfs ... w478 fix for 'pup2' prefix... 100809 bug fix...
 ALLSFSLIST="`ls -1 $EXTRASFSMNTPT/*.sfs $xEXTRASFSMNTPTx | grep '\.sfs$' | tr "\n" " "`"
 #cd $CURRDIR
 sync
 [ "$UNMOUNTME" != "" ] && umount $UNMOUNTME
 
 #eliminate other versions from list...
 BASEFIXEDSFSLIST=""
 rm -f /tmp/bootmanager_wrong_sfs_version 2>/dev/null #v423
 for ONESFS in $ALLSFSLIST
 do
  BASEONESFS="`basename $ONESFS`" #100711
  [ "`echo "$BASEONESFS" | grep '^z'`" != "" ] && continue #100809
  [ "`echo "$BASEONESFS" | grep '^pup_'`" != "" ] && continue #100809
  [ "`echo "$BASEONESFS" | grep "^${DISTRO_FILE_PREFIX}\\-[0-9][0-9][0-9]\\.sfs$"`" != "" ] && continue #100809
  [ "`echo "$BASEONESFS" | grep "^${DISTRO_FILE_PREFIX}[rz]"`" != "" ] && continue #100809
  [ "`echo "$BASEONESFS" | grep '_[0-9][0-9][0-9]' | grep -v "$DISTRO_VERSION"`" != "" ] && continue
  [ "`echo "$BASEONESFS" | grep "^${DISTRO_PUPPYSFS}"`" != "" ] && continue #100913
  [ "`echo "$BASEONESFS" | grep "^${DISTRO_ZDRVSFS}"`" != "" ] && continue #100913
  #w020 other compat-distro sfs need to be eliminated...
  [ "`echo "$BASEONESFS" | grep '\\-[0-9][0-9][0-9]\\.sfs' | grep -v "$DISTRO_VERSION"`" != "" ] && continue
  #v423 eliminate wrong squashfs version...
  if [ "`disktype ${ONESFS} | grep "$SFSSTR"`" = "" ];then
   echo "$BASEONESFS" >> /tmp/bootmanager_wrong_sfs_version
   continue
  fi
  [ "`echo "$BASEFIXEDSFSLIST" | grep "$BASEONESFS"`" != "" ] && continue #100711 avoid duplicates.
  BASEFIXEDSFSLIST="$BASEFIXEDSFSLIST $BASEONESFS"
 done
 BASEALLSFSLIST="$BASEFIXEDSFSLIST"

 #compose list for xdialog listbox...
 for ONESFS in $BASEALLSFSLIST
 do
  if [ "$EXTRASFSLIST" = "" ];then
   DLGLIST="$DLGLIST $ONESFS $ONESFS off"
  else
   [ "`echo -n "$EXTRASFSLIST" | grep -v "$ONESFS"`" != "" ] && DLGLIST="$DLGLIST $ONESFS $ONESFS off"
  fi
 done
 for ONESFS in $EXTRASFSLIST
 do
  DLGLIST="$DLGLIST $ONESFS $ONESFS on"
 done
 
 #v423 let user know wrong sfs's...
 if [ -e /tmp/bootmanager_wrong_sfs_version ];then
  xmessage -bg '#FFC0C0' "`eval_gettext \"NOTICE: The following SFS files located in directory \\\${MSGz}
are the wrong version for the current Linux kernel:\"`

`cat /tmp/bootmanager_wrong_sfs_version`

`eval_gettext \"The above files will be ignored.
The kernel requires \\\${SFSSTR}, SFS files.
Note, there is an SFS-version-converter in the Utility menu.\"`" &
 fi
 
 if [ "$DLGLIST" = "" ];then
  [ "$CLPARAM2" = "quiet" ] && return 1
  xmessage -center -bg '#FFC0C0' "`eval_gettext \"Sorry, there are no SFS files in directory \\\$MSGz
(or they all have the wrong '*_nnn.sfs' version number)
You will need to download and place one there first.\"`"
  return 1
 fi

 # --icon \"/usr/local/lib/X11/pixmaps/module24.xpm\"
 #note, jwm will use module16.xpm as the window icon...
#v424 remove checkbox...
# EXECME="Xdialog --wmclass \"module16\" --backtitle \"Choose which SFS files are to be loaded at bootup.\n(top entry will be on top Unionfs layer)\" --title \"BootManager: SFS files\" --left --stdout --separator \" \" --check \"Ignore above user selection, load all with '_${DISTRO_VERSION}.sfs' in filename\" $EXTRASFSAUTO --help \"
 EXECME="Xdialog --wmclass \"module16\" --backtitle \"$(gettext 'Choose which SFS files are to be loaded at bootup.\n(top entry will be on top Unionfs layer)')\" --title \"$(gettext 'BootManager: SFS files')\" --left --stdout --separator \" \" --help \"
`eval_gettext \"Extra SFS files are available for your Puppy: see announcements on the Forum.\n
\n
Download to '\\\$MSGz', choose what you want using the BootManager,\n
then reboot Puppy.\n
\n
Note1: \n
BootManager is in the 'System' menu.\n
Note2: \n
When naming an SFS file, do not name it with '_nnn.sfs' where the nnn is\n
3 numeric digits, as Puppy will interpret this as a Puppy-version number, \n
and will refuse to load it if it is not '_\\\${DISTRO_VERSION}.sfs'.\n
Note3: \n
In fact, if '_nnn.sfs' is not '_\\\${DISTRO_VERSION}.sfs' then it will not even\n
be listed -- please note this!\"`\" --buildlist \"`eval_gettext \"Note1: No more than 6 SFS files in right-pane!\n\\\${MSGx}\"`\" 0 0 8 $DLGLIST >/tmp/bmrettags.txt"

 while [ 1 ];do
  eval $EXECME
  RETVAL=$?
  #if [ $RETVAL -eq 3 ];then #help
  # #exits with 3 if --help has an empty string.
  # #so, could have detailed help box here.
  # continue
  #fi
  [ ! $RETVAL -eq 0 ] && return 1
  [ $RETVAL -eq 0 ] && break
 done
 
 RETTAGS="`cat /tmp/bmrettags.txt`"

 #v424 remove...
 #if [ "`echo "$RETTAGS" | grep 'unchecked'`" = "" ];then
 # #auto mode, remove EXTRASFSLIST entry from BOOTCONFIG...
 # if [ -f /etc/rc.d/BOOTCONFIG ];then
 #  grep -v 'EXTRASFSLIST' /etc/rc.d/BOOTCONFIG > /tmp/BOOTCONFIG
 #  cat /tmp/BOOTCONFIG > /etc/rc.d/BOOTCONFIG
 # fi
 # return 0
 #fi
 #RETTAGS="`echo -n "$RETTAGS" | sed -e 's/unchecked//g' | sed -e 's/checked//g' | sed -e 's/ $//g'`"
 RETTAGS="`echo -n "$RETTAGS" | sed -e 's/ $//g'`"

 [ ! -e /etc/rc.d/BOOTCONFIG ] && touch /etc/rc.d/BOOTCONFIG
 grep -v 'EXTRASFSLIST' /etc/rc.d/BOOTCONFIG > /tmp/BOOTCONFIG
 cat /tmp/BOOTCONFIG > /etc/rc.d/BOOTCONFIG
 echo "EXTRASFSLIST='$RETTAGS'" >> /etc/rc.d/BOOTCONFIG

} #end extrasfs_func

blacklist_func() {
 #blacklisting of modules at bootup.
 . /etc/rc.d/MODULESCONFIG
 MODLIST=""
 LOADEDMODULES="`lsmod | grep -v '^Module' | cut -f 1 -d ' ' | tr '\n' ' '`"
 for ONEMOD in $LOADEDMODULES
 do
  MODLIST="$MODLIST $ONEMOD $ONEMOD off"
 done
 for ONEMOD in $SKIPLIST
 do
  MODLIST="$MODLIST $ONEMOD $ONEMOD on"
 done
 EXECME="Xdialog --wmclass \"module16\" --title \"$(gettext 'BootManager: Module blacklist manager')\" --left --stdout --separator \" \" --buildlist \"$(gettext 'On the left pane are modules that are currently loaded.\n
On the right pane is the complete list of blacklisted modules.\n
If you want to prevent a module from loading, move it to the right\n
side, click OK, then reboot.\n
Note, if you want to find out further information about any module,\n
run PupScan (look in the System menu)')\" 0 0 8 $MODLIST >/tmp/skiprettags.txt"
 eval $EXECME
 RETVAL=$?
 [ ! $RETVAL -eq 0 ] && return 1
 SKIPLIST=" `cat /tmp/skiprettags.txt | tr '\n' ' '`"
 #now update /etc/rc.d/MODULESCONFIG...
 grep -v '^SKIPLIST' /etc/rc.d/MODULESCONFIG > /tmp/MODULESCONFIG
 mv -f /tmp/MODULESCONFIG /etc/rc.d/MODULESCONFIG
 echo "SKIPLIST='${SKIPLIST}'" >> /etc/rc.d/MODULESCONFIG
} #end blacklist_func

yeslist_func() {
 #choose extra modules to load at bootup.
# yaf-splash -font "8x16" -outline 0 -margin 4 -bg orange -text "$(gettext 'Please wait, processing...')" &
yaf-splash -close never -bg orange -text "$(gettext 'Please wait, processing...')" &
 X1PID=$!
 . /etc/rc.d/MODULESCONFIG
 MODLIST=""
 #note, lsmod will show all modules with '-' as '_'...
 LOADEDMODULES=" `lsmod | grep -v '^Module' | cut -f 1 -d ' ' | tr '\n' ' '`"
 #v403 handles both .ko and .ko.gz modules...
 ALLMODULES="`cat /lib/modules/$KERNVER/modules.dep | cut -f 1 -d ':' | grep -o '[a-zA-Z0-9_-]*\.ko' | tr '\-' '_' | sort - | tr '\n' ' '`"
 for ONEMOD in $ALLMODULES
 do
  NAMEONLY="`basename $ONEMOD .ko`"
  MODPATTERN=" $NAMEONLY "
  #leave off list if already loaded...
  [ "`echo "$LOADEDMODULES" | grep "$MODPATTERN"`" != "" ] && continue
  MODPATTERN=' '"$NAMEONLY"'[ :]'
  #leave off left pane if already on right pane...
  [ "`echo "$ADDLIST" | grep "$MODPATTERN"`" != "" ] && continue
  MODLIST="$MODLIST $NAMEONLY $NAMEONLY off"  
 done
 for ONEMOD in $ADDLIST
 do
  NAMEONLY="$ONEMOD"
  xONEMOD="$ONEMOD"
  if [ `echo -n "$ONEMOD" | tr ':' ' ' | wc -w` -gt 1 ];then
   MPARAMS="`echo -n "$ONEMOD" | cut -f 2-9 -d ':' | tr ':' ' '`"
   NAMEONLY="`echo -n "$ONEMOD" | cut -f 1 -d ':'`"
   xONEMOD="$NAMEONLY $MPARAMS"
  fi
  MODPATTERN=" $NAMEOLY "
  #leave off list if already loaded...
  [ "`echo "$LOADEDMODULES" | grep "$MODPATTERN"`" != "" ] && continue
  MODLIST="$MODLIST $ONEMOD \"$xONEMOD\" on"
 done
 kill $X1PID
 EXECME="Xdialog --wmclass \"module16\" --title \"$(gettext 'BootManager: Module add-list manager')\" --left --stdout --separator \" \" --buildlist \"$(gettext 'On the left pane is the complete list of modules available to be\nused by Puppy (and not currently loaded).\nOn the right pane are modules that you have explicitly chosen to\nbe loaded at bootup (not auto-loaded by default).\nIf you want to force a module to load, move it to the right pane,\nclick OK button, then reboot Puppy.\nNote, if you want to find out further information about any module,\nrun PupScan (look in the System menu)')\" 0 0 8 $MODLIST >/tmp/yesrettags.txt"
 eval $EXECME
 RETVAL=$?
 [ ! $RETVAL -eq 0 ] && return 1
 cat /tmp/yesrettags.txt | tr ' ' '\n' | tr ':' ' ' > /tmp/modules_addlist_edit #v411
 Xdialog --backtitle "`gettext \"If you wish, add any required parameters to these modules\nExample: mmc_block major=179\nIf you don't know what this means, just click 'OK' button\"`"  --wmclass "module16" --title "$(gettext 'BootManager: Edit module addlist')" --left --stdout --no-cancel --editbox /tmp/modules_addlist_edit 0 0 > /tmp/modules_addlist_edit_out
 [ $? -ne 0 ] && return 1
 ADDLIST="`cat /tmp/modules_addlist_edit_out`"
 ADDLIST=' '"`echo "$ADDLIST" | tr ' ' ':' | tr '\n' ' ' | tr -s ' '`"
 #ADDLIST=" `cat /tmp/yesrettags.txt | tr '\n' ' '`"
 #now update /etc/rc.d/MODULESCONFIG...
 grep -v '^ADDLIST' /etc/rc.d/MODULESCONFIG > /tmp/MODULESCONFIG
 mv -f /tmp/MODULESCONFIG /etc/rc.d/MODULESCONFIG
 echo "ADDLIST='${ADDLIST}'" >> /etc/rc.d/MODULESCONFIG
} #end yeslist_func

#  \"Sometimes two modules are eligible for the same hardware, and you need to choose\none of them. An example is the rt2500usb and rt73usb wireless networking modules\n-- with some hardware these are both eligible however our experience has been that\nthe rt73usb works better. For such a situation, create a line here, of format\nmodule1:module2, where you want module2 to have preference over module1.\nNote: an alternative approach is to blacklist the rt2500usb module (see main menu)\nhowever that is gross as it always prevents rt2500usb from loading.\"

preflist_func() {
 xPREFLIST="`echo -n "$PREFLIST" | sed -e 's/^ //' | tr ' ' '\n'`"
 echo "$xPREFLIST" > /tmp/bootmanager_preflist
 xxPREFLIST="`Xdialog --backtitle \"$(gettext 'Sometimes two modules are eligible for the same hardware,\n
and you need to choose one of them. Create a line here,\nof format module1:module2, where you want module2 to\nhave preference over module1.')\" --wmclass \"module16\" --title \"$(gettext 'BootManager: Module preference-list manager')\" --left --stdout --help \"$(gettext 'Sometimes two modules are eligible for the same hardware, and you need to choose\none of them. An example is the rt2500usb and rt73usb wireless networking modules\n-- with some hardware these are both eligible however our experience has been that\nthe rt73usb works better. For such a situation, create a line here, of format\nmodule1:module2, where you want module2 to have preference over module1.\nNote: an alternative approach is to blacklist the rt2500usb module (see main menu)\nhowever that is gross as it always prevents rt2500usb from loading.')\" --editbox /tmp/bootmanager_preflist 0 0`"
 if [ $? -eq 0 ];then
  NEWPREFLIST="`echo "$xxPREFLIST" | tr '\n' ' ' | sed -e 's/^/ /' | tr -s ' '`"
  grep -v '^PREFLIST' /etc/rc.d/MODULESCONFIG > /tmp/MODULESCONFIG
  mv -f /tmp/MODULESCONFIG /etc/rc.d/MODULESCONFIG
  echo "PREFLIST='${NEWPREFLIST}'" >> /etc/rc.d/MODULESCONFIG
 fi
} #end preflist_func

sysdaemons_func() { #100125
 osdcnt=0
 echo -n "" > /tmp/bootmanager_osd
 for ONESYSDAEMON in `find /etc/init.d -maxdepth 1 -type f | grep -v -E 'txt|pcmcia|alsa'`
 do
  osdcnt=`expr $osdcnt + 1`
  OSDNAME="`basename $ONESYSDAEMON`"
  xOSDNAME="`echo -n "$OSDNAME" | sed -e 's%^[0-9]%%' -e 's%^[0-9]%%'`" #remove any leading number.
  OSDDIR="`dirname $ONESYSDAEMON`"
  OSDDEFAULT='false'
  [ -x $ONESYSDAEMON ] && OSDDEFAULT='true'
  OSDDESCR=''
  case $xOSDNAME in
   alsa) OSDDESCR=$(gettext '(ALSA sound server, required to play audio)') ;;
   cups) OSDDESCR=$(gettext '(CUPS printing, required to print)') ;;
   messagebus) OSDDESCR=$(gettext '(DBUS interprocess messaging, required by some apps)') ;;
   rc.acpi) OSDDESCR=$(gettext '(ACPI management, not essential)') ;;
   slmodem) OSDDESCR=$(gettext '(Only needed for certain Internet dialup modems)') ;;
   sys_logger) OSDDESCR=$(gettext '(Logs kernel & app. info. & error messages, not essential)') ;;
   rc.smbqmsvc) OSDDESCR=$(gettext '(only needed for quick mounting Samba shares in lameSMBxplorer)') ;;
  esac
  OSDBOXES="${OSDBOXES} <checkbox><label>${xOSDNAME} ${OSDDESCR}</label><default>${OSDDEFAULT}</default><variable>OSDCHK_${osdcnt}_</variable></checkbox>"
  echo "OSDCHK_${osdcnt}_|${OSDDIR}|${OSDNAME}" >> /tmp/bootmanager_osd
 done
 if [ "`grep '/etc/rc.d/rc.firewall' /etc/rc.d/rc.local`" != "" ];then
  osdcnt=`expr $osdcnt + 1`
  OSDDEFAULT='false'
  [ -x /etc/rc.d/rc.firewall ] && OSDDEFAULT='true'
  OSDBOXES="${OSDBOXES} <checkbox><label>rc.firewall ($(gettext 'Firewall important security on Internet'))</label><default>${OSDDEFAULT}</default><variable>OSDCHK_${osdcnt}_</variable></checkbox>"
  echo "OSDCHK_${osdcnt}_|/etc/rc.d|rc.firewall" >> /tmp/bootmanager_osd
 fi
 #also offer udev management...
 osdcnt=`expr $osdcnt + 1`
 OSDDEFAULT='false'
 [ "`grep '^BACKENDON' /etc/eventmanager | grep 'true'`" != "" ] && OSDDEFAULT='true'
 OSDBOXES="${OSDBOXES} <checkbox><label>udev (`gettext \"Hardware hotplug detection -- see 'HELP'\"`)</label><default>${OSDDEFAULT}</default><variable>OSDCHK_${osdcnt}_</variable></checkbox>"
 echo "OSDCHK_${osdcnt}_||udev" >> /tmp/bootmanager_osd
 
 export MAIN_DIALOG="
<window title=\"$(gettext 'BootManager: Manage system services')\" icon-name=\"gtk-cdrom\">
<vbox>
 <text use-markup=\"true\"><label>\"<b>$(gettext 'Untick a checkbox to prevent service from running at startup')</b>\"</label></text>
 ${OSDBOXES}
 <hbox>
  <button ok></button>
  <button cancel></button>
  <button><input file>/usr/local/lib/X11/mini-icons/mini-question.xpm</input><label>$(gettext 'HELP')</label><action>defaulttextviewer /etc/init.d/README.txt & </action></button>
 </hbox>
</vbox>
</window>
"
 RETSTRING="`gtkdialog3 --program=MAIN_DIALOG --center`" 
 [ "`echo "$RETSTRING" | grep 'EXIT' | grep 'OK'`" = "" ] && return
 while [ $osdcnt -gt 0 ];do
  OSDVAR="OSDCHK_${osdcnt}_"
  OSDDIR="`grep "$OSDVAR" /tmp/bootmanager_osd | cut -f 2 -d '|'`"
  OSDNAME="`grep "$OSDVAR" /tmp/bootmanager_osd | cut -f 3 -d '|'`"
  if [ "$OSDNAME" = "udev" ];then
   if [ "`echo "$RETSTRING" | grep "$OSDVAR" | grep 'true'`" != "" ];then
    if [ "`grep '^BACKENDON' /etc/eventmanager | grep 'false'`" != "" ];then
     xmessage -center -bg orange "`gettext \"The EventManager will now be run, so that you can enable 'udev'.
You will need to tick the 'hotplug module/firmware loading' checkbox...\"`"
     eventmanager &
    fi
   else
    if [ "`grep '^BACKENDON' /etc/eventmanager | grep 'true'`" != "" ];then
     xmessage -center -bg orange "`gettext \"The EventManager will now be run, so that you can disable 'udev'.
You will need to untick the 'hotplug module/firmware loading' checkbox...\"`"
     eventmanager &
    fi
   fi
  fi
  if [ "$OSDDIR" = "/etc/init.d" -o "$OSDDIR" = "/etc/rc.d" ];then
   if [ "`echo "$RETSTRING" | grep "$OSDVAR" | grep 'true'`" != "" ];then
    chmod 755 ${OSDDIR}/${OSDNAME}
   else
    chmod 644 ${OSDDIR}/${OSDNAME}
   fi
  fi
  osdcnt=`expr $osdcnt - 1`
 done
 
} #end sysdaemons_func

if [ "$CLPARAM1" = "extrasfs" ];then
 extrasfs_func
 exit
fi

if [ "$CLPARAM1" = "blacklist" ];then
 blacklist_func
 exit
fi

if [ "$CLPARAM1" = "yeslist" ];then
 yeslist_func
 exit
fi

if [ "$CLPARAM1" = "preflist" ];then
 preflist_func
 exit
fi

if [ "$CLPARAM1" = "sysdaemons" ];then #100125
 sysdaemons_func
 exit
fi

#######################################################

export MAIN_DIALOG="
<window title=\"$(gettext 'BootManager')\" icon-name=\"gtk-cdrom\">
 <vbox>
 <text use-markup=\"true\">
 <label>\"<b>$(gettext 'Puppy Boot Configuration')</b>\"</label></text>
 <notebook labels=\"$(gettext 'Load SFS files')|$(gettext 'Load kernel modules')|$(gettext 'Manage system services')\">
 <frame>
  <text><label>`eval_gettext \"Puppy has a file named '\\\${DISTRO_PUPPYSFS}' that is always loaded. However, extra SFS files can be loaded at bootup, for example 'kde.sfs' to provide KDE applications, and 'devx.sfs' to provide everything for compiling C/C++ source. These can be thought of as 'combo packs' of many packages in one file.\"`</label></text>
  <hbox>
   <text><label>$(gettext 'Choose which extra SFS files to load at bootup:')</label></text>
    <button>
     <input file>/usr/local/lib/X11/pixmaps/module24.xpm</input>
     <action>bootmanager extrasfs</action>
    </button>
  </hbox>
 </frame>
 
 <frame>
  <text><label>`gettext \"If a driver module did not get loaded, or the wrong one got loaded, or you want to 'blacklist' a module, this is the place. A common scenario is a driver got auto-loaded, for say your wireless network card, but you cannot or do not want to use it, and want some other module or want to use Ndiswrapper (to use the Windows driver).\"`</label></text>
  <hbox>
   <text><label>`gettext \"Click here to 'blacklist' a module:\"`</label></text>
    <button>
     <input file>/usr/local/lib/X11/pixmaps/module24.xpm</input>
     <action>bootmanager blacklist</action>
    </button>
  </hbox>
  <hbox>
   <text><label>$(gettext 'Click here to add a new module:')</label></text>
    <button>
     <input file>/usr/local/lib/X11/pixmaps/module24.xpm</input>
     <action>bootmanager yeslist</action>
    </button>
  </hbox>
  <hbox>
   <text><label>$(gettext 'Give preference to one module over another:')</label></text>
    <button>
     <input file>/usr/local/lib/X11/pixmaps/module24.xpm</input>
     <action>bootmanager preflist</action>
    </button>
  </hbox>
 </frame>

 <frame>
   <text><label>$(gettext 'These are processes (applications) that are started at bootup and run continuously in the background. On slow PCs it may help to not run some of these.')</label></text>
  <hbox>
   <text><label>$(gettext 'Choose which system services to run at startup:')</label></text>
    <button>
     <input file>/usr/local/lib/X11/mini-icons/so.xpm</input>
     <action>bootmanager sysdaemons</action>
    </button>
  </hbox>
 </frame>
 </notebook>
 <hbox>
  <button><input file stock=\"gtk-quit\"></input><label>$(gettext 'QUIT')</label></button>
 </hbox>
</vbox>
</window>
"

RETSTRING="`gtkdialog3 --program=MAIN_DIALOG --center`"

eval "$RETSTRING"

[ "$EXIT" = "abort" ] && exit


###END###
