~ubuntu-branches/ubuntu/natty/sadms/natty

« back to all changes in this revision

Viewing changes to bin/conf/join-domain.sh

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2010-02-22 20:14:54 UTC
  • Revision ID: james.westby@ubuntu.com-20100222201454-up4zkzo13w9091i0
Tags: upstream-2.0.14~CVS20100222
ImportĀ upstreamĀ versionĀ 2.0.14~CVS20100222

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# bbou@ac-toulouse.fr
 
3
# 2007-06-24 07:46:04  
 
4
# conf/join-domain.sh 
 
5
 
 
6
### P A R A MS
 
7
MYVERBOSE=
 
8
redirection='> /dev/null'
 
9
if [ "$1" = "-v" ]; then
 
10
        MYVERBOSE="True"
 
11
        redirection=
 
12
        shift
 
13
fi
 
14
MYREALM="$1"
 
15
MYADMIN="$2"
 
16
MYADMINPWD="$3"
 
17
MYOU="$4"
 
18
# organizational unit to put computer in
 
19
#echo "realm=${MYREALM}"
 
20
#echo "ou=${MYOU}"
 
21
#echo "admin=${MYADMIN}"
 
22
#echo "admin password=${MYADMINPWD}"
 
23
 
 
24
### I N C L U D E S
 
25
. ./_include.sh
 
26
 
 
27
### S T A R T
 
28
 
 
29
function dokinit()
 
30
{
 
31
        if echo "${MYADMINPWD}" | ${KINIT} ${MYADMIN}@${MYREALM} > /dev/null; then
 
32
                echo "kerberos authentication of ${MYADMIN}@${MYREALM} succeeded"
 
33
                return 0
 
34
        else
 
35
                echo "kerberos authentication of ${MYADMIN}@${MYREALM} failed"
 
36
                return 1
 
37
        fi
 
38
}
 
39
 
 
40
function indomain()
 
41
{
 
42
        echo "+test domain membership"
 
43
        e="net ads testjoin 2>&1  ${redirection}"
 
44
        if eval ${e}; then
 
45
                echo "in domain"
 
46
                return 0
 
47
        else
 
48
                echo "not in domain"
 
49
                return 1
 
50
        fi
 
51
}
 
52
 
 
53
# different net ads join OU syntax as of 3.0.23
 
54
echo "+get current samba version for join domain syntax"
 
55
sambapkg="${SAMBAPKG}"
 
56
sambaversion=`${PACKAGEVERSION} ${sambapkg} | sed 's/^[^:]://'`
 
57
sambamajorversion=`echo "${sambaversion}" | sed 's/^\([0-9]\).*$/\1/g'`
 
58
sambaminorversion=`echo "${sambaversion}" | sed 's/^[0-9]*\.[0-9]*\.\([0-9]*\).*$/\1/g'`
 
59
echo "samba minor version is ${sambaminorversion}"
 
60
if (( $((sambaminorversion)) < 23 )); then
 
61
        ouswitch=
 
62
else
 
63
        ouswitch=createcomputer=
 
64
fi
 
65
#echo "ouswitch=${ouswitch}"
 
66
#echo net ads join ${ouswitch}"${MYOU}"
 
67
 
 
68
# J O I N   D O M A I N
 
69
#echo "+get administrator credentials"
 
70
#if ! dokinit; then
 
71
#       exit 1
 
72
#fi
 
73
 
 
74
if [ ! -z "${MYOU}" ]; then
 
75
        echo "+join domain to ${MYOU}"
 
76
        joinparam="${ouswitch}\"${MYOU}\""
 
77
else 
 
78
        echo "+join domain"
 
79
        joinparam=
 
80
fi
 
81
 
 
82
e="net ads join ${joinparam} -U '${MYADMIN}%${MYADMINPWD}' ${redirection}"
 
83
#echo $e
 
84
if eval ${e} ; then
 
85
        echo "join succeeded"
 
86
else
 
87
        echo "join failed and returned $?"
 
88
        exit 2
 
89
fi
 
90
 
 
91
# T E S T
 
92
if indomain; then
 
93
        echo "join is ok"
 
94
else
 
95
        exit 3
 
96
fi
 
97
exit 0