forked from myrjola/docker-samba-ad-dc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
77 lines (66 loc) · 1.83 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -e
SAMBA_DOMAIN=${SAMBA_DOMAIN:-samdom}
SAMBA_REALM=${SAMBA_REALM:-samdom.example.com}
if [[ $SAMBA_HOST_IP ]]; then
SAMBA_HOST_IP="--host-ip=${SAMBA_HOST_IP}"
fi
appSetup () {
touch /etc/samba/.alreadysetup
# Generate passwords
ROOT_PASSWORD=$(pwgen -c -n -1 12)
SAMBA_ADMIN_PASSWORD=$(pwgen -cny 10 1)
export KERBEROS_PASSWORD=$(pwgen -cny 10 1)
echo "root:$ROOT_PASSWORD" | chpasswd
echo Root password: $ROOT_PASSWORD
echo Samba administrator password: $SAMBA_ADMIN_PASSWORD
echo Kerberos KDC database master key: $KERBEROS_PASSWORD
# Provision Samba
rm -f /etc/samba/smb.conf
rm -rf /var/lib/samba/private/*
samba-tool domain provision --use-rfc2307 --domain=$SAMBA_DOMAIN --realm=$SAMBA_REALM --server-role=dc\
--dns-backend=BIND9_DLZ --adminpass=$SAMBA_ADMIN_PASSWORD $SAMBA_HOST_IP
cp /var/lib/samba/private/krb5.conf /etc/krb5.conf
# Create Kerberos database
expect kdb5_util_create.expect
# Export kerberos keytab for use with sssd
samba-tool domain exportkeytab /etc/krb5.keytab --principal ${HOSTNAME}\$
sed -i "s/SAMBA_REALM/${SAMBA_REALM}/" /etc/sssd/sssd.conf
}
appStart () {
[ -f /etc/samba/.alreadysetup ] && echo "Skipping setup..." || appSetup
# Start the services
/usr/bin/supervisord
}
appHelp () {
echo "Available options:"
echo " app:start - Starts all services needed for Samba AD DC"
echo " app:setup - First time setup."
echo " app:help - Displays the help"
echo " [command] - Execute the specified linux command eg. /bin/bash."
}
case "$1" in
app:start)
appStart
;;
app:setup)
appSetup
;;
app:help)
appHelp
;;
*)
if [ -x $1 ]; then
$1
else
prog=$(which $1)
if [ -n "${prog}" ] ; then
shift 1
$prog $@
else
appHelp
fi
fi
;;
esac
exit 0