From 6f8c257c882a4f001f283f457f5f3a892111cca5 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 1 Mar 2012 16:26:12 -0800 Subject: [PATCH] Extend fromConfig to import the entire old config, and to change the spectre information. Very handy for moving sites between servers while maintaining all config settings. --- wre/sbin/addsite.pl | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/wre/sbin/addsite.pl b/wre/sbin/addsite.pl index 4b0b666..b6a2dd2 100755 --- a/wre/sbin/addsite.pl +++ b/wre/sbin/addsite.pl @@ -37,8 +37,8 @@ "adminPassword=s" => \$adminPassword, "databaseUser=s" => \$dbUser, "databasePassword=s" => \$dbPassword, - "databaseName=s" => \$dbName, - "fromConfig=s" => \$fromConfig, + "databaseName=s" => \$dbName, + "fromConfig=s" => \$fromConfig, ); my $dbAdminUser = $config->get("mysql/adminUser"); @@ -62,7 +62,9 @@ --sitename The name of the site you'd like to create. For example: www.example.com or intranet.example.com - --fromConfig Pull the sitename, dbUser and dbPassword from the referenced config file + --fromConfig Pull the sitename, dbUser and dbPassword from the referenced config file to build a new site. Then, + it replaces the newly created config file with the old config file. Handy for moving sites to + new servers. --var0-9 A series of variables you can use to arbitrary information into the site creation process. These variables will be exposed to all templates used to @@ -102,6 +104,24 @@ var8 => $var8, var9 => $var9, }); + if ($fromConfig) { + ##Get the spectre information from the newly created config file. + use Config::JSON; + my $new_config = Config::JSON->new($config->getWebguiRoot('etc/'.$sitename.".conf")); + my $spectreSubnets = $new_config->get('spectreSubnets'); + undef $new_config; + + ##Copy the file over + printf "copying file from %s to %s\n", $fromConfig, $config->getWebguiRoot('etc/'.$sitename.".conf"); + use WRE::File; + my $file = WRE::File->new(wreConfig=>$config); + $file->copy($fromConfig, $config->getWebguiRoot('etc/'.$sitename.".conf"), { force => 1 }); + + ##Update the spectre information in the old config + print "Setting new spectre information into old config\n"; + my $orig_config = Config::JSON->new($config->getWebguiRoot('etc/'.$sitename.".conf")); + $orig_config->set('spectreSubnets', $spectreSubnets); + } print $site->sitename." was created. Don't forget to restart the web servers and Spectre.\n"; } else {