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

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

if [ "$DISPLAY" ]; then
  for WEBBROWSER in browser firefox mozilla konqueror dillo; do
     if which $WEBBROWSER &> /dev/null; then
        break
     fi  
  done
else
  WEBBROWSER=lynx
fi

if [ -z "$WEBBROWSER" ]; then
   errorbox "Cannot find web browser"
   clean_exit 1
fi

DIMENSION="12 60"
TITLE="SAMBA ADMINISTRATION"
TEXT="\n
SAMBA server allows file and printer sharing\n
between Windows as well as Linux computers.\n
This configurator will launch a browser to set up the\n
SAMBA through SWAT. It is recomended to run this\n
from GUI environment, so I can launch GUI browser like\n
Mozilla or Firefox. TUI browser may not good enough.\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
SWAT=`nmap 127.0.0.1 | grep samba-swat`
if [ ! "$SWAT" ]; then
    yesnobox "Hmmm ... SWAT is not running.\nLaunch it, shall we ?"
    [ $? != 0 ] && clean_exit 0
    clear
    service inetd start
    echo -n "Waiting for SWAT ..."
    for II in 1 2 3 4 5; do
       sleep 1
       SWAT=`nmap 127.0.0.1 | grep samba-swat`
       if [ -z "$SWAT" ]; then 
         echo -n "$II "
         continue
       fi
       break
    done
    if [ ! "$SWAT" ]; then
       errorbox "Sorry, cannot launch SWAT.\nPlease check your SAMBA installation"
       clean_exit 0
    fi    
fi

PORT=${SWAT%%/*}
clean_tmp
exec $WEBBROWSER 127.0.0.1:$PORT


