[Pkg-mono-svn-commits] rev 588 - xsp-snapshot/trunk/debian/official
Pablo Fischer
pabl0-guest@haydn.debian.org
Fri, 16 Apr 2004 20:29:16 -0600
Author: pabl0-guest
Date: 2004-04-16 20:29:13 -0600 (Fri, 16 Apr 2004)
New Revision: 588
Added:
xsp-snapshot/trunk/debian/official/mono-host-reader.conf
xsp-snapshot/trunk/debian/official/mono-host-update.conf
Log:
These two files, will replace the mono-xsp|server-update and reader, now
the scripts are in perl and to update xsp, just run mono-host-update.conf xsp
Added: xsp-snapshot/trunk/debian/official/mono-host-reader.conf
===================================================================
--- xsp-snapshot/trunk/debian/official/mono-host-reader.conf 2004-04-17 01:33:07 UTC (rev 587)
+++ xsp-snapshot/trunk/debian/official/mono-host-reader.conf 2004-04-17 02:29:13 UTC (rev 588)
@@ -0,0 +1,112 @@
+#!/usr/bin/perl -w
+# Automatic host file generator
+#
+# With this script the user (or daemon) can check if the 'big' host
+# file is ok and in the right sintax, if there is an error it will exit
+# and print the reason in the format: *SORRY*: message.
+#
+# Under GPL, please read:
+# http://www.gnu.org/copyleft/gpl.html
+#
+# Written by: Pablo Fischer
+
+use strict;
+
+#Main vars..
+my ($host_dir, $host_confd, $host_hostfile);
+
+#No args..
+if($#ARGV lt "0") {
+ &usage;
+}
+
+#are we configure mono-server or xsp?
+if($ARGV[0] eq "xsp") {
+ #Setup main vars
+ $host_dir = "/etc/xsp";
+ $host_confd = "$host_dir/conf.d";
+ $host_hostfile = "$host_dir/mono-xsp-hosts.conf";
+}
+elsif($ARGV[0] eq "mono-server") {
+ #Setup main vars
+ $host_dir = "/etc/mono-server";
+ $host_confd = "$host_dir/conf.d";
+ $host_hostfile = "$host_dir/mono-server-hosts.conf";
+}
+else {
+ &usage;
+}
+
+#Check if the user have write access to $host_hostfile
+if( ( -e "$host_hostfile" && ! -w "$host_hostfile" ) || ! -w "$host_dir" ) {
+ print "mono-host-reader requires to be executed as root\n" ;
+ exit 1 ;
+}
+
+
+sub usage() {
+ print "Sorry\, but you need to tell me if you want to parse xsp or mono-server\n";
+ print "Syntax\: mono-host-reader.conf xsp\n";
+ print "or..\n";
+ print "Syntax\, mono-host-reader.conf mono-server\n";
+ exit 1;
+}
+
+
+
+my $opened_section = 0;
+#1 -> true
+#0 -> false
+#Ok, open the file for read mode
+open(HOSTFILE, $host_hostfile);
+#.. read it!
+#Line counter
+my $counter = 0;
+while(my $line = <HOSTFILE>) {
+ $counter++;
+ if($line =~ /begin/i) {
+ if($opened_section eq "1") {
+ print "Sorry\, but you are opening a section before closing the last one (line $counter)\n";
+ last;
+ }
+ else {
+ $opened_section = "1";
+ }
+ }
+
+ if($line =~ /end/i) {
+ if($opened_section eq "0") {
+ print "Sorry\, but you are closing an unopened section (line $counter)\n";
+ }
+ else {
+ $opened_section = "0";
+ }
+ }
+
+ if($line =~ /path/i) {
+ if($opened_section eq "0") {
+ print "Sorry\, but you have a path in a unopened section (line $counter)\n";
+ last;
+ }
+ else {
+ #Ok, the directory exists?
+ my $dir = (split /\= /, $line)[1];
+ #remove that \n
+ $dir =~ s/\n//;
+ if ( ! -d "$dir" ) {
+ print "Sorry\, but you have a path that doesn't exists in your system! (line $counter)\n";
+ last;
+ }
+ }
+ }
+
+ if($line =~ /alias/i) {
+ if($opened_section eq "0") {
+ print "Sorry\, but you have an alias in a unopened section (line $counter)\n";
+ last;
+ }
+ #else.. ok :-)
+ }
+}
+
+close(HOSTFILE);
Added: xsp-snapshot/trunk/debian/official/mono-host-update.conf
===================================================================
--- xsp-snapshot/trunk/debian/official/mono-host-update.conf 2004-04-17 01:33:07 UTC (rev 587)
+++ xsp-snapshot/trunk/debian/official/mono-host-update.conf 2004-04-17 02:29:13 UTC (rev 588)
@@ -0,0 +1,161 @@
+#!/usr/bin/perl -w
+# Automatic Host file generator
+#
+# With this script the user can update the host files
+# that are installed in /etc/xsp|mono-server/conf.d/package and create a
+# 'big' host file (/etc/xsp|mono-server/mono-*-hosts.conf) that will be used
+# by xsp|mono-server to setup the virtual hosts needed by
+# the user.
+#
+# Under GPL, please read:
+# http://www.gnu.org/copyleft/gpl.html
+#
+# Written by: Pablo Fischer
+
+use strict;
+use Digest::MD5;
+
+#Main vars..
+my ($host_dir, $host_confd, $host_hostfile, $daemon);
+
+#No args..
+if($#ARGV lt "0") {
+ &usage;
+}
+
+#are we configure mono-server or xsp?
+if($ARGV[0] eq "xsp") {
+ #Setup main vars
+ $host_dir = "/etc/xsp";
+ $host_confd = "$host_dir/conf.d";
+ $host_hostfile = "$host_dir/mono-xsp-hosts.conf";
+ $daemon = "/etc/init.d/mono-xsp";
+}
+elsif($ARGV[0] eq "mono-server") {
+ #Setup main vars
+ $host_dir = "/etc/mono-server";
+ $host_confd = "$host_dir/conf.d";
+ $host_hostfile = "$host_dir/mono-server-hosts.conf";
+ $daemon = "/etc/init.d/mono-server";
+
+}
+else {
+ &usage;
+}
+
+
+my $restart = "yes";
+my $first_file = "yes";
+my ($orig_md5, $new_md5);
+
+#Check if the user have write access to $host_hostfile
+if( ( -e "$host_hostfile" && ! -w "$host_hostfile" ) || ! -w "$host_dir" ) {
+ print "mono-xsp-update.conf requires write access to $host_hostfile or run it
+as root\n" ;
+ exit 1 ;
+}
+
+#The user doesn't wants to restart the server?
+if($#ARGV eq "1") {
+ if($ARGV[1] eq "--norestart" || $ARGV[0] eq "--norestart") {
+ $restart = "no";
+ }
+}
+
+
+
+#Orig md5
+$orig_md5 = &get_md5;
+#Read directory..
+&read_dir;
+#cp the temp file to the original one..
+system("cp $host_hostfile.tmp $host_hostfile");
+#rm the temp
+system("rm -Rf $host_hostfile.tmp");
+#Final md5
+$new_md5 = &get_md5;
+#Equal?
+if(("$new_md5" ne "$orig_md5") && ($restart eq "yes")) {
+ if( -f $daemon ) {
+ system("$daemon restart");
+ }
+}
+
+sub usage() {
+ print "Sorry\, but you need to tell me if you want to update xsp or mono-server\n";
+ print "Syntax\: mono-host-update.conf xsp\n";
+ print "or..\n";
+ print "Syntax\, mono-host-update.conf mono-server\n";
+ exit 1;
+}
+
+sub get_md5 {
+ if( -e $host_hostfile ) {
+ open(HOSTFILE, $host_hostfile);
+ binmode(HOSTFILE);
+ return Digest::MD5->new->addfile(*HOSTFILE)->hexdigest;
+
+ }
+ else {
+ return "";
+ }
+}
+
+
+sub read_dir {
+ opendir(DIR, $host_confd);
+ my @host_dirs = sort (grep { -d "$host_confd/$_" } readdir(DIR));
+ closedir(DIR);
+
+ #How many dirs?
+ if($#host_dirs ne "0") {
+ foreach my $dir (@host_dirs) {
+ if(($dir ne "..") && ($dir ne ".")) {
+ #Ok, in the dir.. we have more files, so read them
+ opendir(DIR, "$host_confd/$dir");
+ my @host_files = sort (readdir(DIR));
+ closedir(DIR);
+ #Is it empty?
+ if($#host_files ne "0") {
+ #So, read it..
+ foreach my $hostfile (@host_files) {
+ #Just remember.. we don't like directories inside directories!
+ if(($hostfile ne "..") && ($hostfile ne ".")) {
+ $hostfile = "$host_confd/$dir/$hostfile";
+ write_tempxsphostfile($hostfile);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+sub write_tempxsphostfile {
+ my $hostfile = shift;
+ local $/;
+
+ #Write the content to a temp file..
+ open(TEMPHOST, ">> $host_hostfile.tmp");
+ #And open the hostfile..
+ open(HOSTFILE, "$hostfile");
+ #Read it..
+ my $content_hostfile = <HOSTFILE>;
+ #Close it..
+ close(HOSTFILE);
+ #Write the header to the host_hostfile
+ print TEMPHOST "###########################################\n";
+ print TEMPHOST "### begin $hostfile\n";
+ print TEMPHOST "###########################################\n";
+ print TEMPHOST $content_hostfile, "\n";
+ print TEMPHOST "###########################################\n";
+ print TEMPHOST "### end $hostfile\n";
+ print TEMPHOST "###########################################\n";
+ close(TEMPHOST);
+}
+
+
+
+
+
+