#!/bin/sh

if [ ! $DISPLAY = "" ]; then
DCMD="Xdialog --wrap" 
CMD="rxvt -e "
else
DCMD="dialog"
CMD=""
fi

while [ 0 ]; do 

if [ -x /etc/rc.d/init.d/log ]; then
logstate="on"
else
logstate="off"
fi

if [ -x /etc/rc.d/init.d/xfstt ]; then
xfsttstate="on"
else
xfsttstate="off"
fi

if [ -x /etc/rc.d/init.d/cron ]; then
cronstate="on"
else
cronstate="off"
fi

if [ -x /etc/rc.d/init.d/inet ]; then
inetstate="on"
else
inetstate="off"
fi

if [ -x /etc/rc.d/init.d/sendmail ]; then
sendmailstate="on"
else
sendmailstate="off"
fi

if [ -x /etc/rc.d/init.d/gpm ]; then
gpmstate="on"
else
gpmstate="off"
fi

if [ -x /etc/rc.d/init.d/at ]; then
atstate="on"
else
atstate="off"
fi

if [ -x /etc/rc.d/init.d/rpc ]; then
rpcstate="on"
else
rpcstate="off"
fi

if [ -x /etc/rc.d/init.d/dhcpd ]; then
dhcpdstate="on"
else
dhcpdstate="off"
fi

if [ -x /etc/rc.d/init.d/hotplug ]; then
hotplugstate="on"
else
hotplugstate="off"
fi

if [ -x /etc/rc.d/init.d/sshd ]; then
sshdstate="on"
else
sshdstate="off"
fi

if [ -x /etc/rc.d/init.d/portsentry ]; then
portsentrystate="on"
else
portsentrystate="off"
fi

if [ -x /etc/rc.d/init.d/lp ]; then
lpstate="on"
else
lpstate="off"
fi




$DCMD --backtitle "Vector Linux Software LTD." \
	--title "SERVICES MENU" \
        --checklist "Hi, this is the startup service selection menu." 20 78 7 \
log  "The system and kernel loggers. Should be left on." $logstate \
xfstt    "TrueType font server for X. Not needed for XFree 4." $xfsttstate \
cron "schedule computer activities at delegated times." $cronstate \
inet    "Activates inet services as described in /etc/inetd.conf" $inetstate \
sendmail  "Starts the sendmail daemon." $sendmailstate \
gpm  "Starts console mouse daemon." $gpmstate \
at  "Automatic schedule daemon." $atstate \
rpc  "Sun portmap services." $rpcstate \
dhcpd  "Supply dhcp services to your network." $dhcpdstate \
hotplug  "Enable hot plugging of USB devices." $hotplugstate \
sshd  "Activate  the secure shell daemon." $sshdstate \
portsentry  "Protect ports from outside attack." $portsentrystate \
lp  " Starts line printer daemon." $lpstate 2>/tmp/menu

nochoice=`ls /etc/rc.d/init.d`
if [ "$CMD" = "" ]; then
choice=`cat /tmp/menu | sed -e 's/"/ /g p'`
else
choice=`cat /tmp/menu | sed -e 's!/! !g'`
fi
if [ "$choice" = "" ]; then
exit
fi
#rm -f /tmp/menu
sleep 1
retval=$?
case $retval in
  0)
    cd /etc/rc.d/init.d
    chmod -x *
    for i in $choice; do
    chmod +x $i
    done
    for n in $nochoice; do
    if [ $? `grep -q $n $choice` == 1 ]; then
    chmod -x $n
    fi
    done
    ;;
  1)
        clear
    exit 0
    ;;
  255)
    clear && exit 0
    ;;
esac
sleep 1
$DCMD --title "Services activated" --msgbox "The selections: '$choice' \n\
have been activated. \n\
They will start on your next boot." 10 62
done
clear
exit 0
