Skip to content

Commit 13f8652

Browse files
authored
sample script file
sample script file for running the script
1 parent 5675a1e commit 13f8652

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
domainName=$1
2+
userName=$2
3+
4+
if [[ -z "$domainName" ]]; then
5+
echo "Domain name is a required parameter"
6+
exit
7+
fi
8+
9+
if [[ -z "$userName" ]]; then
10+
echo "User name is a required parameter"
11+
exit
12+
fi
13+
14+
echo -n Password:
15+
read -s password
16+
echo
17+
18+
echo $password
19+
20+
echo "Domain join $domainName"
21+
22+
ping -q -c 1 $domainName
23+
pingStatus=$?
24+
25+
if [ $pingStatus -eq 0 ]; then
26+
echo "Ping for domain $domainName succeeded"
27+
else
28+
echo "Domain controller for $domainName was not resolvable"
29+
exit
30+
fi
31+
32+
shortDomainName="${domainName%%.*}"
33+
shortUserName="${userName%%@*}"
34+
sambaConfFileName="/etc/samba/smb.conf"
35+
36+
echo "Preparing the $sambaConfFileName file"
37+
cp $sambaConfFileName "$sambaConfFileName.bak"
38+
echo "[global]" > $sambaConfFileName
39+
echo " security = ads" >> $sambaConfFileName
40+
echo " realm = ${domainName^^}" >> $sambaConfFileName
41+
echo "# If the system doesn't find the domain controller automatically, you may need the following line" >> $sambaConfFileName
42+
echo " password server = *" >> $sambaConfFileName
43+
echo "# note that workgroup is the 'short' domain name" >> $sambaConfFileName
44+
echo " workgroup = ${shortDomainName^^}" >> $sambaConfFileName
45+
echo "# winbind separator = +" >> $sambaConfFileName
46+
echo " winbind enum users = yes" >> $sambaConfFileName
47+
echo " winbind enum groups = yes" >> $sambaConfFileName
48+
echo " template homedir = /home/%D/%U" >> $sambaConfFileName
49+
echo " template shell = /bin/bash" >> $sambaConfFileName
50+
echo " client use spnego = yes" >> $sambaConfFileName
51+
echo " client ntlmv2 auth = yes" >> $sambaConfFileName
52+
echo " encrypt passwords = yes" >> $sambaConfFileName
53+
echo " restrict anonymous = 2" >> $sambaConfFileName
54+
echo " log level = 2" >> $sambaConfFileName
55+
echo " log file = /var/log/samba/sambadebug.log.%m" >> $sambaConfFileName
56+
echo " debug timestamp = yes" >> $sambaConfFileName
57+
echo " max log size = 50" >> $sambaConfFileName
58+
echo " winbind use default domain = yes" >> $sambaConfFileName
59+
echo " nt pipe support = no" >> $sambaConfFileName
60+
echo >> $sambaConfFileName
61+
echo "# Placeholder for domains" >> $sambaConfFileName
62+
echo "idmap config ${shortDomainName^^} : backend = rid" >> $sambaConfFileName
63+
echo "idmap config ${shortDomainName^^} : schema_mode = rid" >> $sambaConfFileName
64+
echo "idmap config ${shortDomainName^^} : range = 100000-1100000" >> $sambaConfFileName
65+
echo "idmap config ${shortDomainName^^} : base_rid = 0" >> $sambaConfFileName
66+
echo "idmap config * : backend = tdb" >> $sambaConfFileName
67+
echo "idmap config * : schema_mode = rid" >> $sambaConfFileName
68+
echo "idmap config * : range = 10000-99999" >> $sambaConfFileName
69+
echo "idmap config * : base_rid = 0" >> $sambaConfFileName
70+
71+
export KRB5_TRACE=/tmp/krb.log
72+
reformattedUserName="$shortUserName@${domainName^^}"
73+
echo net ads join -w $domainName -U $reformattedUserName%$password
74+
75+
netJoinResult=$?
76+
77+
if [ $netJoinResult -ne 0 ]
78+
then
79+
echo "Net join failed with result: $netJoinResult"
80+
exit
81+
fi
82+
83+
echo "Net join succeeded"
84+
85+
net ads info

0 commit comments

Comments
 (0)