r20468: Patch from Martin Kuehl <kuehl@univention.de> to make it easier to load
[Samba.git] / source / setup / provision
blob163cb932746de836570c590dc8bc9ace74292baf
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 */
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 'ldap-base',
33 'ldap-backend=s');
35 if (options == undefined) {
36 println("Failed to parse options");
37 return -1;
40 libinclude("base.js");
41 libinclude("provision.js");
44 print a message if quiet is not set
46 function message()
48 if (options["quiet"] == undefined) {
49 print(vsprintf(arguments));
54 show some help
56 function ShowHelp()
58 print("
59 Samba4 provisioning
61 provision [options]
62 --realm REALM set realm
63 --domain DOMAIN set domain
64 --domain-guid GUID set domainguid (otherwise random)
65 --domain-sid SID set domainsid (otherwise random)
66 --host-name HOSTNAME set hostname
67 --host-ip IPADDRESS set ipaddress
68 --host-guid GUID set hostguid (otherwise random)
69 --invocationid GUID set invocationid (otherwise random)
70 --adminpass PASSWORD choose admin password (otherwise random)
71 --krbtgtpass PASSWORD choose krbtgt password (otherwise random)
72 --machinepass PASSWORD choose machine password (otherwise random)
73 --root USERNAME choose 'root' unix username
74 --nobody USERNAME choose 'nobody' user
75 --nogroup GROUPNAME choose 'nogroup' group
76 --wheel GROUPNAME choose 'wheel' privileged group
77 --users GROUPNAME choose 'users' group
78 --quiet Be quiet
79 --blank do not add users or groups, just the structure
80 --ldap-base output only an LDIF file, suitable for creating an LDAP baseDN
81 --ldap-backend LDAPSERVER LDAP server to use for this provision
83 You must provide at least a realm and domain
85 ");
86 exit(1);
89 if (options['host-name'] == undefined) {
90 options['host-name'] = hostname();
94 main program
96 if (options["realm"] == undefined ||
97 options["domain"] == undefined ||
98 options["host-name"] == undefined) {
99 ShowHelp();
102 /* cope with an initially blank smb.conf */
103 var lp = loadparm_init();
104 lp.set("realm", options.realm);
105 lp.set("workgroup", options.domain);
106 lp.reload();
108 var subobj = provision_guess();
109 for (r in options) {
110 var key = strupper(join("", split("-", r)));
111 subobj[key] = options[r];
114 if (options["ldap-backend"] != undefined) {
115 subobj["LDAPMODULES"] = "entryUUID,paged_searches";
118 var blank = (options["blank"] != undefined);
119 var ldapbase = (options["ldap-base"] != undefined);
120 var ldapbackend = (options["ldap-backend"] != undefined);
122 if (!provision_validate(subobj, message)) {
123 return -1;
126 var system_session = system_session();
127 var creds = options.get_credentials();
128 var paths = provision_default_paths(subobj);
129 message("Provisioning for %s in realm %s\n", subobj.DOMAIN, subobj.REALM);
130 message("Using administrator password: %s\n", subobj.ADMINPASS);
131 if (ldapbase) {
132 provision_ldapbase(subobj, message, paths);
133 } else {
134 provision(subobj, message, blank, paths, system_session, creds, ldapbackend);
135 provision_dns(subobj, message, paths, system_session, creds);
137 message("All OK\n");
138 return 0;