r9805: Add 'data' property to param EJS object
[gd/samba-autobuild/.git] / source4 / setup / upgrade
1 #!/bin/sh
2 exec smbscript "$0" ${1+"$@"}
3 /*
4         Upgrade from Samba3
5         Copyright Jelmer Vernooij 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                 'ldif',
14                 'quiet', 'blank');
15
16 if (options == undefined) {
17    println("Failed to parse options");
18    return -1;
19 }
20
21 libinclude("base.js");
22 libinclude("provision.js");
23 libinclude("upgrade.js");
24
25 /*
26   print a message if quiet is not set
27 */
28 function message() 
29 {
30         if (options["quiet"] == undefined) {
31                 print(vsprintf(arguments));
32         }
33 }
34
35 function ldifprint(data)
36 {
37         if (options.ldif != undefined) {
38                 print(data);
39         }
40 }
41
42 /*
43  show some help
44 */
45 function ShowHelp()
46 {
47         print("
48 Samba4 import tool
49
50 provision [options] <libdir> <smbconf>
51  --ldif                         Dump LDIF
52  --quiet                        Be quiet
53  --blank                        do not add users or groups, just the structure
54
55 You must provide at least a realm and domain
56
57 ");
58         exit(1);
59 }
60
61 if (options.ARGV.length != 2) {
62         ShowHelp();
63         exit(1);
64 }
65
66 var lp = loadparm_init();
67
68 message("Reading Samba3 databases and smb.conf\n");
69 var samba3 = samba3_read(options.ARGV[0], options.ARGV[1]);
70
71 if (samba3 == undefined) {
72         println("Error reading Samba3 data");
73         exit(1);
74 }
75
76 message("Provisioning\n");
77 var subobj = upgrade_provision(samba3);
78 provision(subobj, message, options.blank);
79
80 var ret = upgrade(subobj,samba3,message);
81 if (ret > 0) {
82         message("Failed to import %d entries\n", ret);
83 } else {
84         message("All OK\n");
85 }
86 return 0;