r23560: - Activate metze's schema modules (from metze's schema-loading-13 patch).
[ira/wip.git] / source4 / setup / provision
1 #!/bin/sh
2 exec smbscript "$0" ${1+"$@"}
3 /*
4         provision a Samba4 server
5         Copyright Andrew Tridgell 2005
6         Released under the GNU GPL v2 or later
7 */
8
9 options = GetOptions(ARGV,
10                 "POPT_AUTOHELP",
11                 "POPT_COMMON_SAMBA",
12                 "POPT_COMMON_VERSION",
13                 "POPT_COMMON_CREDENTIALS",
14                 'realm=s',
15                 'domain=s',
16                 'domain-guid=s',
17                 'domain-sid=s',
18                 'host-name=s',
19                 'host-ip=s',
20                 'host-guid=s',
21                 'invocationid=s',
22                 'adminpass=s',
23                 'krbtgtpass=s',
24                 'machinepass=s',
25                 'root=s',
26                 'nobody=s',
27                 'nogroup=s',
28                 'wheel=s',
29                 'users=s',
30                 'quiet',
31                 'blank',
32                 'partitions-only',
33                 'ldap-base',
34                 'ldap-backend=s',
35                 'ldap-module=s',
36                 'aci=s');
37
38 if (options == undefined) {
39    println("Failed to parse options");
40    return -1;
41 }
42
43 libinclude("base.js");
44 libinclude("provision.js");
45
46 /*
47   print a message if quiet is not set
48 */
49 function message()
50 {
51         if (options["quiet"] == undefined) {
52                 print(vsprintf(arguments));
53         }
54 }
55
56 /*
57  show some help
58 */
59 function ShowHelp()
60 {
61         print("
62 Samba4 provisioning
63
64 provision [options]
65  --realm        REALM           set realm
66  --domain       DOMAIN          set domain
67  --domain-guid  GUID            set domainguid (otherwise random)
68  --domain-sid   SID             set domainsid (otherwise random)
69  --host-name    HOSTNAME        set hostname
70  --host-ip      IPADDRESS       set ipaddress
71  --host-guid    GUID            set hostguid (otherwise random)
72  --invocationid GUID            set invocationid (otherwise random)
73  --adminpass    PASSWORD        choose admin password (otherwise random)
74  --krbtgtpass   PASSWORD        choose krbtgt password (otherwise random)
75  --machinepass  PASSWORD        choose machine password (otherwise random)
76  --root         USERNAME        choose 'root' unix username
77  --nobody       USERNAME        choose 'nobody' user
78  --nogroup      GROUPNAME       choose 'nogroup' group
79  --wheel        GROUPNAME       choose 'wheel' privileged group
80  --users        GROUPNAME       choose 'users' group
81  --quiet                        Be quiet
82  --blank                        do not add users or groups, just the structure
83  --partitions-only              Configure Samba's partitions, but do not modify them (ie, join a BDC)
84  --ldap-base                    output only an LDIF file, suitable for creating an LDAP baseDN
85  --ldap-backend LDAPSERVER      LDAP server to use for this provision
86  --ldap-module= MODULE          LDB mapping module to use for the LDAP backend
87  --aci=         ACI             An arbitary LDIF fragment, particularly useful to loading a backend ACI value into a target LDAP server
88 You must provide at least a realm and domain
89
90 ");
91         exit(1);
92 }
93
94 if (options['host-name'] == undefined) {
95         options['host-name'] = hostname();
96 }
97
98 /*
99    main program
100 */
101 if (options["realm"] == undefined ||
102     options["domain"] == undefined ||
103     options["host-name"] == undefined) {
104         ShowHelp();
105 }
106
107 /* cope with an initially blank smb.conf */
108 var lp = loadparm_init();
109 lp.set("realm", options.realm);
110 lp.set("workgroup", options.domain);
111 lp.reload();
112
113 var subobj = provision_guess();
114 for (r in options) {
115         var key = strupper(join("", split("-", r)));
116         subobj[key] = options[r];
117 }
118
119 var blank = (options["blank"] != undefined);
120 var ldapbase = (options["ldap-base"] != undefined);
121 var ldapbackend = (options["ldap-backend"] != undefined);
122 var ldapmodule = (options["ldap-module"] != undefined);
123 var partitions_only = (options["partitions-only"] != undefined);
124 if (options["aci"] != undefined) {
125         message("set ACI: %s\n", subobj["ACI"]);
126 }
127
128 message("set DOMAIN SID: %s\n", subobj["DOMAINSID"]);
129
130 if (ldapbackend) {
131         if (!ldapmodule) {
132                 subobj["LDAPMODULE"] = "entryUUID";
133         }
134         subobj["DOMAINDN_LDB"] = subobj["LDAPBACKEND"];
135         subobj["DOMAINDN_MOD2"] = subobj["LDAPMODULE"] + ",paged_searches";
136         subobj["CONFIGDN_LDB"] = subobj["LDAPBACKEND"];
137         subobj["CONFIGDN_MOD2"] = subobj["LDAPMODULE"] + ",paged_searches";
138         subobj["SCHEMADN_LDB"] = subobj["LDAPBACKEND"];
139         subobj["SCHEMADN_MOD2"] = subobj["LDAPMODULE"] + ",paged_searches";
140 }
141
142 if (!provision_validate(subobj, message)) {
143         return -1;
144 }
145
146 var system_session = system_session();
147 var creds = options.get_credentials();
148 var paths = provision_default_paths(subobj);
149 message("Provisioning for %s in realm %s\n", subobj.DOMAIN, subobj.REALM);
150 message("Using administrator password: %s\n", subobj.ADMINPASS);
151 if (ldapbase) {
152         provision_ldapbase(subobj, message, paths);
153         message("Please install the LDIF located in " + paths.ldap_basedn_ldif + ", " + paths.ldap_config_basedn_ldif + " and " + paths.ldap_schema_basedn_ldif + " into your LDAP server, and re-run with --ldap-backend=ldap://my.ldap.server\n");
154 } else if (partitions_only) {
155         provision_become_dc(subobj, message, false, paths, system_session);
156 } else {
157         provision(subobj, message, blank, paths, system_session, creds, ldapbackend);
158         provision_dns(subobj, message, paths, system_session, creds);
159 }
160 message("All OK\n");
161 return 0;