#!/bin/sh
CONF_SRC=/usr/lib/samba/lib/smb.conf.default
CONF=/usr/lib/samba/lib/smb.conf
getyn () {
while true; do
echo "$1 [$2] \c"
read answer
[ -z "$answer" ] && answer=$2
case $answer in
[Yy]*) echo; return 0;
;;
[Nn]*) echo; return 1;
;;
*) echo "Please answer yes or no."
continue
;;
esac
done
}
conf_replace () {
sed -e 's/^;*\(.*\)'$1'\(.*\)$/\1'$2'\2/' < $CONF > /tmp/smb.conf.$$
cp -f /tmp/smb.conf.$$ $CONF
rm -f /tmp/smb.conf.$$
}
if [ -f $CONF ]; then
cmp -s $CONF_SRC $CONF || {
echo "The file $CONF appears to have been previously edited.
If you continue, this file will be restored to its original
state and any changes you have made may be lost.\n"
if getyn "Continue?" No; then
echo "Backing up $CONF to ${CONF}-\n"
cp -f $CONF ${CONF}-
cp -f $CONF_SRC $CONF
else
exit 0
fi
}
else
cp -f $CONF_SRC $CONF
fi
while true; do
default=MYGROUP
echo "Enter Workgroup/NT-Domain name: [$default] \c"
read workgroup
if [ -z "$workgroup" ]; then
workgroup=$default
fi
set -- $workgroup
if [ $ echo "ERROR: Workgroup names cannot contain spaces or punctuation.\n"
continue
fi
workgroup=`echo $workgroup | tr a-z A-Z | tr -d [:punct:]`
if expr "$workgroup" : '[^A-Z]' >&-; then
echo "ERROR: Workgroup name must begin with an alphabetic character.\n"
continue
fi
echo "Workgroup name set to \"$workgroup\".\n"
break
done
while true; do
default=`uname -n | tr a-z A-Z | tr -d [:punct:]`
echo "Enter Machine name: [$default] \c"
read name
if [ -z "$name" ]; then
name=$default
fi
set -- $name
if [ $ echo "ERROR: Machine names cannot contain spaces or punctuation.\n"
continue
fi
name=`echo $name | tr a-z A-Z | tr -d [:punct:]`
if expr "$name" : '[^A-Z]' >&-; then
echo "ERROR: Machine name must begin with an alphabetic character.\n"
continue
fi
echo "Machine name set to \"$name\".\n"
break
done
wins=false
if getyn "Will this system use WINS (recommended)?" Yes; then
wins=true
fi
if [ "$wins" = "true" ]; then
echo "NOTE: A workgroup can have only one WINS server."
wins_svr=false
if getyn "Will this system be the WINS server for your workgroup?" No; then
wins_svr=true
fi
if [ "$wins_svr" = "false" ]; then
while true; do
echo "Enter the address of the primary WINS server for your workgroup: \c"
read wins_addr
if expr "$wins_addr" : '[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*$' >&- ; then
echo
break
fi
echo "ERROR: Invalid IP address format.\n"
done
fi
fi
iflist=`ifconfig -a | grep -v LOOPBACK | grep '^[^ ]*:' | cut -f1 -d:`
set -- $iflist
if [ "$#" -eq 0 ]; then
echo "FATAL ERROR: No network interfaces"
exit 1
elif [ "$#" -eq 1 ]; then
interfaces=$1
else
while true; do
interfaces=""
echo "Which of the following interfaces should Samba run on?\n"
for i in $iflist; do
addr=`ifconfig $i | grep "inet " | sed 's/inet \([^ ]*\) .*$/\1/'`
echo "\t$i:\t$addr"
done
echo "\nList all interfaces to activate (e.g., net0, net1, etc): \c"
read response
for i in $response; do
found=false
for j in $iflist; do
if [ "$i" = "$j" ]; then
found=true
break
fi
done
if [ "$found" = "true" ]; then
interfaces="$interfaces $j"
else
echo "ERROR: Invalid interface name $i\n"
continue 2
fi
done
interfaces="$interfaces lo0 atl0"
break
done
fi
domain_exists=false
if getyn "Will this system be part of a currently existing Microsoft Security\n\
Domain or Active Directory?" No; then
domain_exists=true
fi
if [ "$domain_exists" = "true" ]; then
default='*'
echo "Enter the name of the Primary Domain Controller: [*] \c"
read pdc
if [ -z "$pdc" ]; then
pdc=$default
else
pdc=`echo $pdc | tr a-z A-Z | tr -d [:punct:]`
fi
echo "Primary Domain Controller set to \"$pdc\".\n"
else
domain_master=false
if getyn "Will this system be the domain controller for a new Microsoft\n\
Security Domain?" No; then
domain_master=true
fi
fi
conf_replace %%WORKGROUP%% "$workgroup"
conf_replace %%NBNAME%% "$name"
if [ "$wins" = true ]; then
if [ "$wins_svr" = true ]; then
conf_replace %%WINSSUPPORT%% yes
else
conf_replace %%WINSSERVER%% $wins_addr
fi
fi
conf_replace %%INTERFACES%% "$interfaces"
conf_replace %%BINDONLY%% yes
if [ "$domain_exists" = true ]; then
conf_replace %%SECURITY%% domain
conf_replace %%PWSERVER%% "$pdc"
else
conf_replace %%SECURITY%% user
fi
if [ "$domain_master" = true ]; then
conf_replace %%DOMAINMASTER%% yes
conf_replace %%DOMAINLOGONS%% yes
conf_replace %%OSLEVEL%% 33
else
conf_replace %%OSLEVEL%% 20
fi