1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
#!/usr/bin/perl
#
# You need to change the above line to the location of Perl on your machine.
# And yes, I realized that I am reinventing the functionality of make here -
# but make sucks... If you disagree, then tell me why we have tools like
# GNU configure, imake, xmkmf, and perl's makemaker...
$PERL = "/usr/bin/perl";
$PREFIX = "/usr/local/spong";
$BINDIR = "$PREFIX/bin";
$ETCDIR = "$PREFIX/etc";
$LIBDIR = "$PREFIX/lib";
$WWWDIR = "$PREFIX/www";
$CGIDIR = "$PREFIX/cgi-bin";
$VARDIR = "$PREFIX/var"; # Directory where spong will put data
$TMPDIR = "$PREFIX/tmp"; # update $SPONGTMP var in spong.conf also
$WEBUSER = "nobody";
# That is typically all you need to change. You can change the values below
# if you use a system like depot where you install to one located, but those
# files get moved into their final location via some program.
$IPREFIX = $PREFIX;
$IBINDIR = "$IPREFIX/bin";
$IETCDIR = "$IPREFIX/etc";
$ILIBDIR = "$IPREFIX/lib";
$IWWWDIR = "$IPREFIX/www";
$ICGIDIR = "$IPREFIX/cgi-bin";
$IVARDIR = "$IPREFIX/var"; # Directory where spong will put data
$ITMPDIR = "$IPREFIX/tmp"; # update $SPONGTMP var in spong.conf also
# -----------------------------------------------------------------------------
# You really really shouldn't need to change anything below this point (I hope)
# -----------------------------------------------------------------------------
@bin = qw( spong spong-server spong-network spong-client spong-message
spong-ack spong-cleanup spong-status);
@lib = qw( Ack AckList History HistoryList Host HostList Info Service
ServiceList );
@cgibin = qw( www-spong www-spong-ack wap-spong);
# Make sure that we are running build in the directory where things are
# unpacked. This is kind of a lame check, but good enough for now...
if( `cat ./.version 2>&1` ne "spong 2.7\n" ) {
print "Error: You need to run build from the directory that you unpacked ";
print "spong in.\nPlease \"cd\" into that directory and type \"./build\"\n";
exit(0);
}
($VER) = (`cat ./.version 2>&1` =~ /spong (.*)/);
# Compute a list of operating systems that we know about.
opendir( DIR, "./config" ) || die "Can't open ./config dir: $!";
while( $file = readdir( DIR ) ) {
if( $file =~ /spong\.conf\.(.*)$/ ) { $known_os{$1} = 1; }
}
closedir( DIR );
# Find out the arguments that are passed in and call the appropriate function
$run = 1;
if( $ARGV[0] eq "-n" ) { $run = 0; shift @ARGV; }
if( $ARGV[0] eq "help" ) { &help(); exit(); }
if( $ARGV[0] eq "clean" ) { &clean(); exit(); }
if( $ARGV[0] eq "install" ) { &install(); exit(); }
if( $ARGV[0] eq "upgrade" ) { &upgrade(); exit(); }
if( $known_os{$ARGV[0]} ) { &build( $ARGV[0] ); exit(); }
&help(); exit();
# This routine takes and builds all the stuff that we can. Based on the OS
# provided, it creates an etc directory that contains the spong.conf and
# spong.hosts file. It then converts the tokens in the .pl and .pod files
# into their appropriate values, finally it generates some man pages and html
# documents.
sub build {
my( $os ) = @_;
my $file;
ssystem( "mkdir ./etc" ) if ! -d "./etc";
ssystem( "cp ./config/spong.conf ./etc/spong.conf" );
ssystem( "cp ./config/spong.hosts ./etc/spong.hosts" );
ssystem( "cp ./config/spong.groups ./etc/spong.groups" );
ssystem( "cp ./config/spong.message ./etc/spong.message" );
ssystem( "cat ./config/spong.conf.$os >> ./etc/spong.conf" );
ssystem( "mkdir ./etc/default") if ! -d "./etc/default";
ssystem( "mkdir ./bin" ) if ! -d "./bin";
foreach $file ( @bin ) {
&replace( "./src/$file.pl", "./bin/$file" ); }
ssystem( "chmod +x ./bin/*" );
ssystem( "mkdir -p ./lib/Spong" ) if ! -d "./lib/Spong";
# foreach $file ( @lib ) {
# &replace( "./src/lib/Spong/$file.pm", "./lib/Spong/$file.pm" ); }
ssystem( "cp -rp ./src/lib/Spong/* ./lib/Spong/");
ssystem( "chmod 644 ./lib/Spong/*" );
ssystem( "chmod 755 ./lib/Spong/Client ./lib/Spong/Message ./lib/Spong/Network");
ssystem( "mkdir ./cgi-bin" ) if ! -d "./cgi-bin";
foreach $file ( @cgibin ) {
&replace( "./src/$file.pl", "./cgi-bin/$file" ); }
ssystem( "chmod +x ./cgi-bin/*" );
# Need to do something about replacing the configurable tags in the HTML
# documentation.
ssystem( "touch .built" );
}
# After everything is all built, this just copies the various files to their
# final location
sub install {
if( ! -f ".built" ) { &help(); }
ssystem( "mkdir -p $IBINDIR" ) if ! -d $IBINDIR;
ssystem( "cp bin/* $IBINDIR/" );
ssystem( "mkdir -p $IETCDIR" ) if ! -d $IETCDIR;
ssystem( "cp etc/* $IETCDIR/" );
ssystem( "mkdir -p $IVARDIR" ) if ! -d $IVARDIR;
ssystem( "mkdir -p $IVARDIR/database" );
ssystem( "mkdir -p $IVARDIR/archives" );
ssystem( "mkdir -p $IVARDIR/misc" );
ssystem( "mkdir -p $ITMPDIR" ) if ! -d $ITMPDIR;
# TODO - Clean this up...
ssystem( "mkdir -p $ILIBDIR" ) if ! -d $ILIBDIR;
ssystem( "cp -rp lib/* $ILIBDIR/" );
ssystem( "chmod -R ugo+rwX,go-w $ILIBDIR/*" );
# Your web server needs to be able to access these files
ssystem( "chmod 751 $IETCDIR" );
ssystem( "chmod 644 $IETCDIR/spong.*" );
ssystem( "mkdir -p $IWWWDIR" ) if ! -d $IWWWDIR;
ssystem( "cp -rp ./www/* $IWWWDIR/" );
ssystem( "chmod -R ugo+rwX,go-w $IWWWDIR" );
ssystem( "chown -R $WEBUSER $IWWWDIR" );
# Put copies of the CGI program in the cgi-bin directory...
ssystem( "mkdir -p $ICGIDIR" ) if ! -d $ICGIDIR;
ssystem( "cp ./cgi-bin/www-spong $ICGIDIR/www-spong" );
ssystem( "cp ./cgi-bin/www-spong-ack $ICGIDIR/www-spong-ack" );
ssystem( "cp ./cgi-bin/wap-spong $ICGIDIR/wap-spong" );
ssystem( "chmod u=rx,go=r $ICGIDIR/*spong*" ); # Let's be conservative
ssystem( "chown $WEBUSER $ICGIDIR/*spong*" );
# Remove this once I'm done testing...
# ssystem( "cp $ICGIDIR/www-spong /local/www/cgi-bin/www-spong2" );
# ssystem( "cp $ICGIDIR/www-spong-ack /local/www/cgi-bin/www-spong2-ack" );
}
# This does the same thing as install, except it doesn't override your
# configuration files. Instead it copies its new configuration files to the
# install directory - but calls them *.dist, and displays a message telling
# you about it.
sub upgrade {
if( ! -f ".built" ) { &help(); }
ssystem( "mkdir -p $IBINDIR" ) if ! -d $IBINDIR;
ssystem( "cp bin/* $IBINDIR/" );
ssystem( "mkdir -p $IETCDIR" ) if ! -d $IETCDIR;
ssystem( "cp etc/spong.conf $IETCDIR/spong.conf.dist" );
ssystem( "cp etc/spong.hosts $IETCDIR/spong.hosts.dist" );
ssystem( "cp etc/spong.groups $IETCDIR/spong.groups.dist" );
ssystem( "cp etc/spong.message $IETCDIR/spong.message.dist" );
# Your web server needs to be able to access these files
ssystem( "chmod 751 $IETCDIR" );
ssystem( "chmod 644 $IETCDIR/spong.*" );
# TODO - Clean this up...
ssystem( "mkdir -p $ILIBDIR" ) if ! -d $ILIBDIR;
ssystem( "cp -rp lib/* $ILIBDIR/" );
ssystem( "chmod -R ugo+rwX,go-w $ILIBDIR/*" );
ssystem( "mkdir -p $IWWWDIR" ) if ! -d $IWWWDIR;
ssystem( "cp -rp ./www/* $IWWWDIR/" );
ssystem( "chmod -R ugo+rwX,go-w $IWWWDIR" );
ssystem( "chown -R $WEBUSER $IWWWDIR" );
# Put copies of the CGI program in the cgi-bin directory...
ssystem( "mkdir -p $ICGIDIR" ) if ! -d $ICGIDIR;
ssystem( "cp ./cgi-bin/www-spong $ICGIDIR/www-spong" );
ssystem( "cp ./cgi-bin/www-spong-ack $ICGIDIR/www-spong-ack" );
ssystem( "cp ./cgi-bin/wap-spong $ICGIDIR/wap-spong" );
ssystem( "chmod ugo+rwx,go-w $ICGIDIR/*spong*" );
ssystem( "chown $WEBUSER $ICGIDIR/*spong*" );
}
# This removes all the generated files in the spong distrib directory.
sub clean {
ssystem( "rm -rf ./lib" );
foreach( qw( etc bin cgi-bin ) ) {
if( -d "./$_" ) {
ssystem( "rm -rf ./$_/*" );
ssystem( "rmdir ./$_" );
}
}
ssystem( "rm ./.built" ) if -f "./.built";
}
# This prints out a help message, it explains how this program can be called,
# what options are apropriate, etc...
sub help {
print "You need to type ./build <os> first, where <os> is one of the ";
print "following:\n\n";
foreach( sort keys %known_os ) { print " * $_\n"; }
print <<'_EOF_';
If your OS is not listed above, then you will need to create a
config/spong.conf.<os> file for your OS before building this package. Once
you have done that, please send that file to ed-hill@uiowa.edu so that I can
include it with the distribution.
_EOF_
exit(0);
}
# This takes a source file and replaces some keywords in the file with values
# that the user has defined. It's a sed replacement...
sub replace {
my( $in, $out ) = @_;
print "replacing tokens in $in, creating $out\n";
if( $run ) {
open( IN, $in ) || die "can't open $in: $!";
open( OUT, ">$out" ) || die "can't create $out: $!";
while( <IN> ) {
s/\@\@PERL\@\@/$PERL/g; s/\@\@ETCDIR\@\@/$ETCDIR/g;
s/\@\@BINDIR\@\@/$BINDIR/g; s/\@\@WWWDIR\@\@/$WWWDIR/g;
s/\@\@LIBDIR\@\@/$LIBDIR/g; s/\@\@VER\@\@/$VER/g;
print OUT $_;
}
close( OUT );
close( IN );
}
}
# This takes a shell command, prints it and then passes it off to the normal
# perl system function. It also checks to see if it should run the command.
sub ssystem {
if( $run ) {
print $_[0], "\n";
system( $_[0] );
} else {
print $_[0], "\n";
}
}
|