#!/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

check_root

BROWSER=lynx
if [ "$DISPLAY" ]; then
  BROWSER="browser"
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 have problem.\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 ?"
    clear
    service inet 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
       msgbox "Sorry, cannot launch SWAT.\nPlease check your SAMBA installation"
       clean_exit
    fi    
fi

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


