#!/usr/bin/perl use strict; use warnings; # Config defaults our %CFG = ( WEBROOT => "/var/local/www", DOMAIN => "testing.cancerprev.org"); # Read config file if exists if (-f "/etc/local-webroot.conf") { open(IN, "<", "/etc/local-webroot.conf") or die $!; while () { if (m/(\w+)\s*\=\s*(\"?)(.*)\2/) { $CFG{$1} = $3; } } } # Enter the web root directory so we can make relative symlinks chdir("$CFG{WEBROOT}") or die $!; # This is the name of the symlink, and the base of the real dir names my $baseDir = "$ENV{USER}.$CFG{DOMAIN}"; if (-e "$baseDir" and ! -l "$baseDir") { die("Error: $baseDir exists, but is not a symlink!\n"); } # Read command line my $name = shift; if (!defined $name) { if (! -e "$baseDir") { die("Error: $CFG{WEBROOT}/$baseDir does not exist!\n"); } # Show current setting my $ptr = `ls -l $baseDir`; $ptr =~ s/.*-> $baseDir-//; chomp($ptr); print "Currently using \U$ptr\E source tree for $baseDir.\n"; exit(0); } # Change symlink, if target exists if (! -d "$baseDir-$name") { die("Error: There is no directory $CFG{WEBROOT}/$baseDir-$name.\n"); } unlink($baseDir) or die $! if (-e $baseDir); symlink("$baseDir-$name", "$baseDir") or die $!; print("Now using \U$name\E source tree for $baseDir.\n");