2005-08-29 16:31:32 +04:00
#!/bin/sh
exec smbscript "$0" ${1+"$@"}
/*
Upgrade from Samba3
Copyright Jelmer Vernooij 2005
Released under the GNU GPL v2 or later
*/
options = GetOptions(ARGV,
"POPT_AUTOHELP",
"POPT_COMMON_SAMBA",
"POPT_COMMON_VERSION",
2006-01-15 10:02:34 +03:00
"POPT_COMMON_CREDENTIALS",
2005-08-31 20:51:09 +04:00
'verify',
2005-08-31 06:39:57 +04:00
'targetdir=s',
2005-08-29 16:31:32 +04:00
'quiet', 'blank');
if (options == undefined) {
println("Failed to parse options");
return -1;
}
libinclude("base.js");
libinclude("provision.js");
libinclude("upgrade.js");
/*
print a message if quiet is not set
*/
function message()
{
if (options["quiet"] == undefined) {
print(vsprintf(arguments));
}
}
/*
show some help
*/
function ShowHelp()
{
print("
Samba4 import tool
provision [options] <libdir> <smbconf>
2005-08-31 06:39:57 +04:00
--targetdir=DIR Output to specified directory
2005-08-29 16:31:32 +04:00
--quiet Be quiet
--blank do not add users or groups, just the structure
You must provide at least a realm and domain
");
exit(1);
}
if (options.ARGV.length != 2) {
ShowHelp();
exit(1);
}
2005-08-29 22:52:24 +04:00
var lp = loadparm_init();
2005-08-29 19:54:10 +04:00
2005-08-29 16:31:32 +04:00
message("Reading Samba3 databases and smb.conf\n");
var samba3 = samba3_read(options.ARGV[0], options.ARGV[1]);
if (samba3 == undefined) {
println("Error reading Samba3 data");
exit(1);
}
2005-08-31 06:39:57 +04:00
2005-08-29 16:31:32 +04:00
message("Provisioning\n");
var subobj = upgrade_provision(samba3);
2005-08-31 06:39:57 +04:00
var paths;
if (options.targetdir != undefined) {
paths = new Object();
paths.smbconf = sprintf("%s/smb.conf", options.targetdir);
2005-10-15 14:15:42 +04:00
var ldbs = new Array("hklm","hkcr","hku","hkcu","hkpd","hkpt","samdb","rootdse","secrets","wins");
2005-08-31 06:39:57 +04:00
for (var i in ldbs) {
var n = ldbs[i];
paths[n] = sprintf("tdb://%s/%s.ldb", options.targetdir, n);
}
paths.dns = options.targetdir+"/dns.zone";
} else {
paths = provision_default_paths(subobj);;
}
2006-01-15 10:02:34 +03:00
var creds = options.get_credentials();
var system_session = system_session();
var paths = provision_default_paths(subobj);
provision(subobj, message, options.blank, paths, system_session, creds);
2005-08-29 19:54:10 +04:00
2006-01-15 12:03:28 +03:00
var ret = upgrade(subobj,samba3,message,paths, system_session, creds);
2005-08-30 16:27:53 +04:00
if (ret > 0) {
message("Failed to import %d entries\n", ret);
} else {
2006-01-15 12:03:28 +03:00
provision_dns(subobj, message, paths, system_session, creds);
2005-08-30 16:27:53 +04:00
message("All OK\n");
}
2005-08-31 20:51:09 +04:00
if (options.verify != undefined) {
message("Verifying...\n");
ret = upgrade_verify(subobj, samba3,paths,message);
}
return ret;