| 1 |
#!/bin/sh |
|---|
| 2 |
exec perl -x $0 $@ |
|---|
| 3 |
|
|---|
| 4 |
#!perl |
|---|
| 5 |
|
|---|
| 6 |
my @configuration=( |
|---|
| 7 |
[ 'install=new|convert', 'new', 'install new database or convert existing' ], |
|---|
| 8 |
[ 'workflow=DIR', '/var/mgd', 'base directory for MidRepository' ], |
|---|
| 9 |
[ 'db-host=host', 'localhost', 'host where the databases reside' ], |
|---|
| 10 |
[ 'db-admin-user=user', 'root', 'username of the database administrator' ], |
|---|
| 11 |
[ 'db-admin-password=password', '', 'password of the database administrator' ], |
|---|
| 12 |
[ 'db-user=user', 'midgard', 'username of the midgard database user' ], |
|---|
| 13 |
[ 'db-user-password=password', 'midgard', 'password of the midgard database user' ], |
|---|
| 14 |
[ 'convert-db=databasename', 'midgardstaging', 'the db you want to convert' ], |
|---|
| 15 |
[ 'staging-db=databasename', 'vcstaging', 'staging database name' ], |
|---|
| 16 |
[ 'live-db=databasename', 'vclive', 'live database name' ], |
|---|
| 17 |
[ 'centralstaging-db=databasename', 'centralstaging', 'centralstaging database name' ], |
|---|
| 18 |
[ 'centrallive-db=databasename', 'centrallive', 'centrallive database name' ], |
|---|
| 19 |
[ 'meta-db=databasename', 'centralmeta', 'meta database name' ], |
|---|
| 20 |
[ 'host=hostname', 'localhost', 'hostname of this machine' ], |
|---|
| 21 |
[ 'ip=ipaddress', '127.0.0.1', 'IP address of this machine' ], |
|---|
| 22 |
[ 'staging-port=portnumber', '8001', 'port number for this server' ], |
|---|
| 23 |
[ 'live-port=portnumber', '80', 'port number for this server' ], |
|---|
| 24 |
[ 'centralstaging-port=portnumber', '8003', 'port number for this server' ], |
|---|
| 25 |
[ 'centrallive-port=portnumber', '8002', 'port number for this server' ], |
|---|
| 26 |
[ 'convert-blobdir=DIR', '/var/www/blobs_staging', 'source BLOBs directory' ], |
|---|
| 27 |
[ 'blobroot=DIR', '/var/www', 'directory in which the different BLOB dirs will be created' ], |
|---|
| 28 |
[ 'staging-cachedir=DIR', '/var/cache/midgard/page/staging ', 'directory where mod-preparser will store generated pages' ], |
|---|
| 29 |
[ 'live-cachedir=DIR', '/var/cache/midgard/page/live', 'directory where mod-preparser will store generated pages' ], |
|---|
| 30 |
[ 'centralstaging-cachedir=DIR', '/var/cache/midgard/page/centralstaging', 'directory where mod-preparser will store generated pages' ], |
|---|
| 31 |
[ 'centrallive-cachedir=DIR', '/var/cache/midgard/page/centrallive', 'directory where mod-preparser will store generated pages' ], |
|---|
| 32 |
[ 'apxs=PROGRAM', '/usr/bin/apxs', 'full path of the apxs binary' ], |
|---|
| 33 |
[ 'midgard=DIR', '/usr', 'installation directory of Midgard' ], |
|---|
| 34 |
[ 'apache-user=user', 'www-data', 'username that apache runs as' ], |
|---|
| 35 |
[ 'apache-group=group', 'www-data', 'group that apache runs as' ], |
|---|
| 36 |
[ 'admin-user', 'admin', 'name of the default user' ], |
|---|
| 37 |
[ 'admin-pass', 'password', 'password of the default user' ], |
|---|
| 38 |
); |
|---|
| 39 |
|
|---|
| 40 |
use Getopt::Long; |
|---|
| 41 |
use Socket; |
|---|
| 42 |
|
|---|
| 43 |
my %configvalues = (); |
|---|
| 44 |
|
|---|
| 45 |
&readoptions(); |
|---|
| 46 |
$configvalues{'help'} && exit; |
|---|
| 47 |
|
|---|
| 48 |
$configvalues{version} = '1.4'; |
|---|
| 49 |
$none = "<none>"; |
|---|
| 50 |
|
|---|
| 51 |
checking('apache-user', sub { (defined getpwnam($configvalues{'apache-user'})) || die "User '$configvalues{'apache-user'}' does not exist\n"; }); |
|---|
| 52 |
checking('apache-group', sub { |
|---|
| 53 |
|
|---|
| 54 |
if ($configvalues{'apache-group'} eq "") { $configvalues{'apache-group'} = $configvalues{'apache-user'}; } |
|---|
| 55 |
(defined getgrnam($configvalues{'apache-group'})) || die "Group '$configvalues{'apache-group'}' does not exist\n"; |
|---|
| 56 |
}); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
checking('db-host', sub { defined gethostbyname($configvalues{'db-host'}) || die "$configvalues{'db-host'} does not resolve\n"; }); |
|---|
| 60 |
checking('db-admin-user', sub { $configvalues{'db-admin-user'} || die "db-admin-user is empty\n"; }); |
|---|
| 61 |
checking('db-user', sub { $configvalues{'db-user'} || die "db-user is empty\n"; }); |
|---|
| 62 |
checking('host', sub { defined gethostbyname($configvalues{host}) || die "$configvalues{host} does not resolve\n"; }); |
|---|
| 63 |
|
|---|
| 64 |
checking('staging-port', sub { ($configvalues{'staging-port'} =~ /^[0-9]+$/) || die "staging-port invalid\n"; }); |
|---|
| 65 |
checking('live-port', sub { ($configvalues{'live-port'} =~ /^[0-9]+$/) || die "live-port invalid\n"; }); |
|---|
| 66 |
checking('centralstaging-port', sub { ($configvalues{'centralstaging-port'} =~ /^[0-9]+$/) || die "centralstaging-port invalid\n" }); |
|---|
| 67 |
checking('centrallive-port', sub { ($configvalues{'centrallive-port'} =~ /^[0-9]+$/) || die "centrallive-port invalid\n"; }); |
|---|
| 68 |
$configvalues{'listen-port-number'} = "Listen $configvalues{'staging-port'}\nListen $configvalues{'live-port'}\nListen $configvalues{'centralstaging-port'}\nListen $configvalues{'centrallive-port'}"; |
|---|
| 69 |
|
|---|
| 70 |
if ($configvalues{install} eq 'convert') { |
|---|
| 71 |
checking('convert-db', sub { $configvalues{'convert-db'} || die "convert-db is empty\n"; }); |
|---|
| 72 |
} |
|---|
| 73 |
checking('staging-db', sub { $configvalues{'staging-db'} || die "staging-db is empty\n"; }); |
|---|
| 74 |
checking('live-db', sub { $configvalues{'live-db'} || die "live-db is empty\n"; }); |
|---|
| 75 |
checking('centralstaging-db', sub { $configvalues{'centralstaging-db'} || die "centralstaging-db is empty\n"; }); |
|---|
| 76 |
checking('centrallive-db', sub { $configvalues{'centrallive-db'} || die "centrallive-db is empty\n"; }); |
|---|
| 77 |
checking('admin-user', sub { $configvalues{'admin-user'} || die "admin-user is empty\n"; }); |
|---|
| 78 |
checking('admin-pass', sub { $configvalues{'admin-pass'} || die "admin-pass is empty\n"; }); |
|---|
| 79 |
|
|---|
| 80 |
if ($configvalues{'admin-pass'} !~ /\*\*/) { |
|---|
| 81 |
$configvalues{'admin-pass-wo-asterisk'} = $configvalues{'admin-pass'}; |
|---|
| 82 |
$configvalues{'admin-pass'} = "**" . $configvalues{'admin-pass'}; |
|---|
| 83 |
} else { |
|---|
| 84 |
$configvalues{'admin-pass-wo-asterisk'} = substr($configvalues{'admin-pass'}, 2); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
foreach('staging', 'live', 'centralstaging', 'centrallive') { |
|---|
| 88 |
$configvalues{$_ . '-blobdir'} = $configvalues{blobroot} . '/blobs_' . $configvalues{$_ . '-db'}; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
if ($configvalues{ip} eq '') { |
|---|
| 92 |
my $tmp = inet_aton($configvalues{host}); |
|---|
| 93 |
if (defined $tmp) { $configvalues{ip} = inet_ntoa($tmp); } |
|---|
| 94 |
} |
|---|
| 95 |
checking('ip', sub { ($configvalues{ip} =~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) || die "ip '$configvalues{ip}' is invalid\n" }); |
|---|
| 96 |
|
|---|
| 97 |
checking('midgard', sub { |
|---|
| 98 |
$location = ''; |
|---|
| 99 |
foreach ('/usr', '/usr/local', $configvalues{midgard}) { |
|---|
| 100 |
if (-e "$_/share/midgard") { $location = $_; } |
|---|
| 101 |
} |
|---|
| 102 |
$location || die "Cannot find installation location of midgard\n"; |
|---|
| 103 |
$configvalues{midgard} = $location; |
|---|
| 104 |
}); |
|---|
| 105 |
$configvalues{'midgard-data'} = "$configvalues{midgard}/share/midgard"; |
|---|
| 106 |
$configvalues{'midgard-bin'} = "$configvalues{midgard}/bin"; |
|---|
| 107 |
|
|---|
| 108 |
checking('apxs', sub { |
|---|
| 109 |
if (!$configvalues{apxs}) { |
|---|
| 110 |
foreach (split(/:/, $ENV{PATH})) { |
|---|
| 111 |
if (-e "$_/apxs") { $configvalues{apxs} = "$_/apxs"; } |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
-e $configvalues{apxs} || die "Cannot find apxs\n"; |
|---|
| 115 |
|
|---|
| 116 |
my $libexecdir=`$configvalues{apxs} -q LIBEXECDIR`; |
|---|
| 117 |
chomp $libexecdir; |
|---|
| 118 |
|
|---|
| 119 |
if ($libexecdir eq '') { |
|---|
| 120 |
print "Your apxs seems to be broken (CFG_LIBEXECDIR not defined)\nAssuming CFG_LIBEXECDIR to /etc/httpd/modules\n"; |
|---|
| 121 |
$libexecdir = "/etc/httpd/modules"; |
|---|
| 122 |
} |
|---|
| 123 |
my $sysconfdir=`$configvalues{apxs} -q SYSCONFDIR`; |
|---|
| 124 |
chomp $sysconfdir; |
|---|
| 125 |
|
|---|
| 126 |
if ($sysconfdir eq '') { |
|---|
| 127 |
print "Your apxs seems to be broken (SYSCONFDIR not defined)\nAssuming SYSCONFDIR to /etc/httpd/conf\n"; |
|---|
| 128 |
$libexecdir = "/etc/httpd/conf"; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
my $httpd=`$configvalues{apxs} -q SBINDIR` . '/' . `$configvalues{apxs} -q TARGET`; |
|---|
| 132 |
chomp $httpd; |
|---|
| 133 |
|
|---|
| 134 |
if ($httpd eq '') { |
|---|
| 135 |
print "Your apxs seems to be broken (SBINDIR + TARGET not defined)\nAssuming executable to /usr/sbin/httpd\n"; |
|---|
| 136 |
$httpd = "/usr/sbin/httpd"; |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
$configvalues{'sysconfdir'} = $sysconfdir; |
|---|
| 141 |
$configvalues{'httpd'} = $httpd; |
|---|
| 142 |
$configvalues{'rootfile-php3'} = "$libexecdir/midgard-root.php3"; |
|---|
| 143 |
$configvalues{'rootfile-php4'} = "$libexecdir/midgard-root.php"; |
|---|
| 144 |
}); |
|---|
| 145 |
|
|---|
| 146 |
$configvalues{'php3-comment'} = "# "; |
|---|
| 147 |
$configvalues{'php4-comment'} = ""; |
|---|
| 148 |
$configvalues{'php-command-prefix'} = "php_value "; |
|---|
| 149 |
|
|---|
| 150 |
checking('php', sub { |
|---|
| 151 |
if (-e "/usr/bin/php") { |
|---|
| 152 |
$configvalues{php} = "/usr/bin/php"; |
|---|
| 153 |
} elsif (-e "/usr/bin/php4") { |
|---|
| 154 |
$configvalues{php} = "/usr/bin/php4"; |
|---|
| 155 |
} else { |
|---|
| 156 |
die "Cannot find php commandline interpreter in /usr/bin/php nor /usr/bin/php4\n"; |
|---|
| 157 |
} |
|---|
| 158 |
} |
|---|
| 159 |
); |
|---|
| 160 |
|
|---|
| 161 |
checking('install', sub { checkvalues($configvalues{install}, 'new', 'convert'); }); |
|---|
| 162 |
|
|---|
| 163 |
$configvalues{'parser'} = "latin1"; |
|---|
| 164 |
|
|---|
| 165 |
open F, ">config.cache"; |
|---|
| 166 |
print F "\%configvalues = (\n"; |
|---|
| 167 |
foreach (@configuration) { |
|---|
| 168 |
$key = $$_[0]; |
|---|
| 169 |
$key =~ s/=.*//; |
|---|
| 170 |
print F "\t", '"', quotemeta($key), '" => "', |
|---|
| 171 |
quotemeta($configvalues{$key}), '",', "\n"; |
|---|
| 172 |
} |
|---|
| 173 |
print F ");\n"; |
|---|
| 174 |
close F; |
|---|
| 175 |
|
|---|
| 176 |
print "Generating install files, please wait...\n"; |
|---|
| 177 |
output('dbinstall', 'midgard-workflow.conf', 'mysql-db.sql', 'mysql-user.sql', 'vcconfig.php', 'midgarddb', 'metadb', 'database-upgrade', 'support.xml', 'clear', 'vcstaging.conf', 'vclive.conf', 'centralstaging.conf', 'centrallive.conf', 'convertdb.conf', 'clients/call-migrate.php', 'clients/everymin.php', 'clients/dump.php'); |
|---|
| 178 |
system "chmod 0700 dbinstall database-upgrade clear"; |
|---|
| 179 |
system "chmod 0660 midgard-workflow.conf mysql-db.sql mysql-user.sql config.cache vcconfig.php midgarddb metadb support.xml vcstaging.conf vclive.conf centralstaging.conf centrallive.conf convertdb.conf"; |
|---|
| 180 |
system "chmod 0755 clients/*"; |
|---|
| 181 |
system "chown $> dbinstall mysql-db.sql mysql-user.sql config.cache vcconfig.php midgarddb metadb database-upgrade support.xml clear vcstaging.conf vclive.conf centralstaging.conf centrallive.conf convertdb.conf"; |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
sub readoptions |
|---|
| 187 |
{ |
|---|
| 188 |
if (-f './config.cache') { |
|---|
| 189 |
print STDERR "Loading config.cache...\n"; |
|---|
| 190 |
eval `cat ./config.cache`; |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
foreach (@configuration) { |
|---|
| 194 |
($option, $default, $help) = @{$_}; |
|---|
| 195 |
if (length($option) > $longest) { $longest = length($option); } |
|---|
| 196 |
|
|---|
| 197 |
$option =~ s/=.*//; |
|---|
| 198 |
$options{"with-$option:s"} = \&handle_option; |
|---|
| 199 |
if (! defined $configvalues{$option}) { |
|---|
| 200 |
$configvalues{$option} = $default; |
|---|
| 201 |
} |
|---|
| 202 |
$optionhelp{$option} = $help; |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
foreach (@configuration) { |
|---|
| 206 |
($option, $default, $help) = @{$_}; |
|---|
| 207 |
$helptext .= sprintf("--with-%-${longest}s $help\n", $option); |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
GetOptions('verbose' => \$verbose, 'help' => \&help, %options); |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
sub handle_option |
|---|
| 214 |
{ |
|---|
| 215 |
my ($name, $value) = @_; |
|---|
| 216 |
|
|---|
| 217 |
$name =~ s/^with-//; |
|---|
| 218 |
if ($value) { $configvalues{$name} = $value; } |
|---|
| 219 |
} |
|---|
| 220 |
|
|---|
| 221 |
sub help |
|---|
| 222 |
{ |
|---|
| 223 |
$configvalues{'help'} = 'yes'; |
|---|
| 224 |
die $helptext; |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
sub checkvalues |
|---|
| 228 |
{ |
|---|
| 229 |
my $answer = shift; |
|---|
| 230 |
my @valid = @_; |
|---|
| 231 |
my $o, $h; |
|---|
| 232 |
|
|---|
| 233 |
foreach (@valid) { |
|---|
| 234 |
($answer eq $_) && return; |
|---|
| 235 |
} |
|---|
| 236 |
|
|---|
| 237 |
if ($answer) { print "unexpected answer '$answer'.\n"; } |
|---|
| 238 |
else { print "this option requires a value.\n"; } |
|---|
| 239 |
print "Valid options are: ", join(', ', @valid), "\n"; |
|---|
| 240 |
exit(1); |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
sub checking |
|---|
| 244 |
{ |
|---|
| 245 |
my ($option, $sub) = @_; |
|---|
| 246 |
|
|---|
| 247 |
print STDERR "Checking for $optionhelp{$option}... "; |
|---|
| 248 |
&$sub(); |
|---|
| 249 |
print $configvalues{$option}, "\n"; |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
sub showoptions |
|---|
| 253 |
{ |
|---|
| 254 |
my ($option, $default, $help); |
|---|
| 255 |
|
|---|
| 256 |
foreach (@configuration) { |
|---|
| 257 |
($option, $default, $help) = @{$_}; |
|---|
| 258 |
$option =~ s/=.*//; |
|---|
| 259 |
print "$option => $configvalues{$option}\n"; |
|---|
| 260 |
} |
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
sub output |
|---|
| 264 |
{ |
|---|
| 265 |
my @files = @_; |
|---|
| 266 |
my %replace; |
|---|
| 267 |
my ($key, $value); |
|---|
| 268 |
my $line; |
|---|
| 269 |
|
|---|
| 270 |
while (($key, $value) = each(%configvalues)) { |
|---|
| 271 |
$key =~ s/-/_/g; |
|---|
| 272 |
$key = uc $key; |
|---|
| 273 |
|
|---|
| 274 |
$value =~ s/([$\\"])/\\$1/g; |
|---|
| 275 |
|
|---|
| 276 |
$replace{$key} = $value; |
|---|
| 277 |
$verbose && print "Replacing \@$key\@ with '$value'\n"; |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
foreach (@files) { |
|---|
| 281 |
open I, "<$_.in"; |
|---|
| 282 |
open O, ">$_"; |
|---|
| 283 |
while ($line = <I>) { |
|---|
| 284 |
foreach (keys %replace) { |
|---|
| 285 |
$line =~ s/\@$_\@/$replace{$_}/g; |
|---|
| 286 |
} |
|---|
| 287 |
print O $line; |
|---|
| 288 |
} |
|---|
| 289 |
close I; |
|---|
| 290 |
close O; |
|---|
| 291 |
} |
|---|
| 292 |
} |
|---|
| 293 |
|
|---|