summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rwxr-xr-xsource4/script/provision.pl124
1 files changed, 40 insertions, 84 deletions
diff --git a/source4/script/provision.pl b/source4/script/provision.pl
index d6c4cd68fe..1730f0859a 100755
--- a/source4/script/provision.pl
+++ b/source4/script/provision.pl
@@ -186,6 +186,23 @@ sub substitute($)
die "ERROR: Uknown substitution variable $var\n";
}
+
+####################################################################
+# substitute all variables in a string
+sub apply_substitutions($)
+{
+ my $data = shift;
+ my $res = "";
+ while ($data =~ /(.*?)\$\{(\w*)\}(.*)/s) {
+ my $sub = substitute($2);
+ $res .= "$1$sub";
+ $data = $3;
+ }
+ $res .= $data;
+ return $res;
+}
+
+
#####################################################################
# write a string into a file
sub FileSave($$)
@@ -365,123 +382,62 @@ if (!$opt_adminpass) {
print "chose random Administrator password '$opt_adminpass'\n";
}
-my $res = "";
-
-print "applying substitutions ...\n";
-
-while ($data =~ /(.*?)\$\{(\w*)\}(.*)/s) {
- my $sub = substitute($2);
- $res .= "$1$sub";
- $data = $3;
-}
-$res .= $data;
-
-print "saving ldif to newsam.ldif ...\n";
-
-FileSave("newsam.ldif", $res);
-
-unlink("newsam.ldb");
-
-print "creating newsam.ldb ...\n";
-
# allow provisioning to be run from the source directory
$ENV{"PATH"} .= ":bin";
-system("ldbadd -H newsam.ldb newsam.ldif");
-print "done\n";
+my $res = apply_substitutions($data);
-$data = FileLoad("rootdse.ldif") || die "Unable to load rootdse.ldif\n";
+my $newdb = "newdb." . int(rand(1000));
-$res = "";
+print "Putting new database files in $newdb\n";
-print "applying substitutions ...\n";
+mkdir($newdb) || die "Unable to create temporary directory $newdb\n";
-while ($data =~ /(.*?)\$\{(\w*)\}(.*)/s) {
- my $sub = substitute($2);
- $res .= "$1$sub";
- $data = $3;
-}
-$res .= $data;
+FileSave("$newdb/sam.ldif", $res);
-print "saving ldif to newrootdse.ldif ...\n";
+print "creating $newdb/sam.ldb ...\n";
-FileSave("newrootdse.ldif", $res);
+system("ldbadd -H $newdb/sam.ldb $newdb/sam.ldif") == 0 || die "Failed to create sam.ldb\n";
-unlink("newrootdse.ldb");
-
-print "creating newrootdse.ldb ...\n";
-
-system("ldbadd -H newrootdse.ldb newrootdse.ldif");
-
-print "done\n";
-
-$data = FileLoad("secrets.ldif") || die "Unable to load secrets.ldif\n";
-
-$res = "";
+$data = FileLoad("rootdse.ldif") || die "Unable to load rootdse.ldif\n";
-print "applying substitutions ...\n";
+$res = apply_substitutions($data);
-while ($data =~ /(.*?)\$\{(\w*)\}(.*)/s) {
- my $sub = substitute($2);
- $res .= "$1$sub";
- $data = $3;
-}
-$res .= $data;
+FileSave("$newdb/rootdse.ldif", $res);
-print "saving ldif to newsecrets.ldif ...\n";
+print "creating $newdb/rootdse.ldb ...\n";
-FileSave("newsecrets.ldif", $res);
+system("ldbadd -H $newdb/rootdse.ldb $newdb/rootdse.ldif") == 0 || die "Failed to create rootdse.ldb\n";
-unlink("newsecrets.ldb");
+$data = FileLoad("secrets.ldif") || die "Unable to load secrets.ldif\n";
-print "creating newsecrets.ldb ...\n";
+$res = apply_substitutions($data);
-system("ldbadd -H newsecrets.ldb newsecrets.ldif");
+FileSave("$newdb/secrets.ldif", $res);
-print "done\n";
+print "creating $newdb/secrets.ldb ...\n";
-print "generating dns zone file ...\n";
+system("ldbadd -H $newdb/secrets.ldb $newdb/secrets.ldif") == 0 || die "Failed to create secrets.ldb\n";
$data = FileLoad("provision.zone") || die "Unable to load provision.zone\n";
-$res = "";
-
-print "applying substitutions ...\n";
-
-while ($data =~ /(.*?)\$\{(\w*)\}(.*)/s) {
- my $sub = substitute($2);
- $res .= "$1$sub";
- $data = $3;
-}
-$res .= $data;
+$res = apply_substitutions($data);
-print "saving dns zone to newdns.zone ...\n";
+print "saving dns zone to $newdb/dns.zone ...\n";
FileSave("$dnsdomain.zone", $res);
-print "done\n";
-
-unlink("newhklm.ldb");
-
-print "creating newhklm.ldb ... \n";
-
-system("ldbadd -H newhklm.ldb hklm.ldif");
+print "creating $newdb/hklm.ldb ... \n";
-print "done\n";
+system("ldbadd -H $newdb/hklm.ldb hklm.ldif") == 0 || die "Failed to create hklm.ldb\n";
print "
Installation:
-- Please move newsam.ldb to sam.ldb in the private/ directory of your
+- Please move $newdb/*.ldb to the private/ directory of your
Samba4 installation
-- Please move newrootdse.ldb to rootdse.ldb in the private/ directory
- of your Samba4 installation
-- Please move newsecrets.ldb to secrets.ldb in the private/ directory
- of your Samba4 installation
-- Please move newhklm.ldb to hklm.ldb in the private/ directory
- of your Samba4 installation
-- Please use $dnsdomain.zone to in BIND dns server
+- Please use $newdb/dnsdomain.zone in BIND on your dns server
";