#!/bin/sh
# vim:set sw=4 ts=4:
#
# $Id: make_samba,v 1.7 2005/04/11 14:14:39 fabian Exp $
#
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000-2002 SuSE Linux Solutions AG, Eschborn, Germany
#               2002-2004 SuSE Linux AG, Eschborn, Germany
#               2005           SUSE GmbH, Nuernberg, Germany
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: Fabian Herschel
#
#############################################################################
#
# make_samba
# configures the samba server
# TODO: Check if it configures samba completly or if we need make_config_files
#
# Sections: samba
# Tags:     SMB_CONF, WIN_CLIENTS, WIN_USERS
#
test -n "$alice_dir" || alice_dir="/usr/lib/alice2/"
export alice_dir

while [ $# -gt 0 ]
do
   case $1 in
       -h | --help | -? ) usage
                          exit 1
                          ;;
       -fqhn ) export fqhn=$2; shift
            ;;

   esac
   shift
done   

. $alice_dir/lib/alicerc

WELCOME

# Does this really work??
#suse_release=67
#std_samba_conf=/etc/smb.conf
#if [ grep "VERSION = [891]" /etc/SuSE-release ] then
#suse_release=89
#std_samba_conf=/etc/samba/smb.conf
#fi

suse_release=`awk -F" " '$1=="SuSE"{print $2}' /etc/SuSE-release`

case $suse_release in
    SuSE-6|SuSE-7)    std_samba_conf=/etc/smb.conf
    ;;
    SuSE-8|SUSE-9)    std_samba_conf=/etc/samba/smb.conf
    ;;
    *)      std_samba_conf=/etc/samba/smb.conf
    ;;
esac

############################################################################
#
# save the old configuration
#
BACKUP --error ${std_samba_conf} 
#
# First priority is on a special file
#
#config_file=$(get_config_file smb.conf) || FATAL NOCFG smb.conf
#. ${config_file}
GET_CONFIGURATION --require samba $CFG_DEBUG
if [ -z "$SMB_CONF" ]
then
   FATAL NOVALUE SMB_CONF $config_file
fi
(
    echo "# ${std_samba_conf}"
    echo "# generated by alice $(date)"   
    echo "${SMB_CONF}" 
)> ${std_samba_conf}.alice
CHANGED ${std_samba_conf} || {
   BACKUP ${std_samba_conf}
   mv ${std_samba_conf}.alice ${std_samba_conf}
   #
   # Now we invite smbd to reload the information
   #
   if [ -x $rc_d_dir/smb ]
   then
	#  if [ $suse_release = 67 ] then
    #  		if [ "$($rc_d_dir/smb status)" = "Checking for service smb: OK OK" ]
	#  elif
	#		if [ "$($rc_d_dir/smb status)" = "Checking for service smb: OK" ]
	#  fi
    #  then
         $rc_d_dir/smb reload
    #  fi
   else
      FATAL NOEXE $rc_d_dir/smb
   fi
}
#
############################################################################
#
# TEST/CREATE SAMBA-MACHINE USERS 
# TEST/CREATE SAMBA (WIN) USERS
#
if [ -n "$WIN_CLIENTS" ]
then
   #
   # do something
   #
else
   #
   # no clients??
   #
fi
#
#
if [ -n "$WIN_USER" ]
then
   #
   # test/create
   #
else
   #
   # no user?
   #
fi
#
############################################################################
# Thats all
GOOD_BYE 
