#!/bin/sh
# @vasm : vcupset
# @level: root
# @description: cup administration
# 
# (c) Eko M. Budi, 2003
# (c) Vector Linux, 2003
#
# Released under GNU GPL

if [ ! "$VASM_FUNCTIONS" ]; then
  . /sbin/vasm-functions
fi

check_root

BROWSER=lynx
if [ "$DISPLAY" ]; then
  BROWSER="browser"
fi

DIMENSION="10 50"
TITLE="CUPS CONFIGURATOR"
TEXT="\n
CUPS is the printing service for Linux.\n 
This configurator will launch a browser to set up\n
the CUPS. You better do this from GUI environment,\n
so I can launch GUI browser like Mozilla or Firefox.\n
TUI browser may not suitable.\n
If asked, use your root account to login.\n"

$DCMD --backtitle "$BACKTITLE" --title "$TITLE" --msgbox "$TEXT" $DIMENSION 2> $freply
[ ! $? = 0 ] && clean_exit

## Check if swat is already running
SERVER=`nmap 127.0.0.1 | grep ipp`
if [ ! "$SWAT" ]; then
    yesnobox "Hmmm ... CUPS is not running.\nLaunch it, shall we ?"
    clear
    service cups start
    echo -n "Waiting for CUPS ..."
    for II in 1 2 3 4 5; do
       sleep 1
       SERVER=`nmap 127.0.0.1 | grep ipp`
       if [ -z "$SERVER" ]; then 
         echo -n "$II "
         continue
       fi
       break
    done
    if [ ! "$SERVER" ]; then
       errorbox "Sorry, cannot launch CUPS.\nPlease check your CUPS installation."
       clean_exit
    fi    
fi

PORT=${SERVER%%/*}
clean_tmp
exec $BROWSER 127.0.0.1:$PORT


