#!/usr/bin/perl # v1.0 (c) 12/23/2004 by Durwood Gafford # v1.1 (c) 10/18/2005 by Durwood Gafford # added support for retreving past versions # v1.2 (c) 09/05/2006 by Durwood Gafford # added -F option # v1.3 (c) 11/28/2006 by Durwood Gafford # Fixed for directorys other than '.' by adding chdir() command use File::Copy; use LWP::Simple; $link = 1; $linkforce = 0; $force = 0; $cwd = qx/"pwd"/; $numargs = $#ARGV + 1; if ($numargs == 0) { PrintUsageExit(); } $lastarg = $numargs - 1; for ($ii = 0; $ii < $numargs; $ii++) { $arg = $ARGV[$ii]; if ($arg eq "-f") { $force = 1; } elsif ($arg eq "-l") { $linkforce = 1; } elsif ($arg eq "-F") { $linkforce = 1; $force = 1; } elsif ($arg eq "-v") { $ii++; $version = $ARGV[$ii]; } elsif ($ii == $lastarg) { $dest = $arg; } else { printf "Illegal option: %s\n", $arg; PrintUsageExit(); } } if (!$dest) { printf ("\nNo destination provided. Please verify usage.\n"); PrintUsageExit(); } # Validate desitnation directory if (! -d $dest) { printf ("Error: %s does not exist or is not a directory\n", $dest); exit(0); } # Change directory to destinaation chdir($dest); # Setup global parameters $srcwebsite = "http://www.berzerker.net/imgdir/"; if ($version) { $srcfname = "src/imgdir_v" . $version . ".php_"; } else { $srcfname = "imgdir.php_"; } $srcurl = $srcwebsite.$srcfname; $destimgdir = "imgdir.php"; $configdir = ".imgdir"; # See if it's ok to continue if (!$force && (-e $configdir || -e $destimgdir)) { printf ("Error: imgdir.php or .imgdir already exists\n"); printf ("Use -f to force reinstall\n"); exit (0); } # Retreive the latest version of imgdir $rc = getstore ($srcurl, $destimgdir); if (is_error($rc)) { print ("Unable to retreive imgdir source: $srcurl\n"); print (" Destination: $srcfname\n"); exit(0); } ### gdg rename ($srcfname, $destimgdir); mkdir $configdir; chmod (0777, $configdir); if ($link) { $destlink = "index.php"; if (-l $destlink && $linkforce) { unlink($destlink); } if (-e $destlink) { $curLink = readlink($destlink); if ($curLink ne $destimgdir) { printf ("Link $destlink already exists and points to $curLink\n"); printf ("Keeping existing link; rerun with -l to force overwrite\n"); } } else { symlink ($destimgdir, $destlink); } } exit(0); sub PrintUsageExit() { print "\n"; print "Usage: getimgdir [-f -l -F] [-v vernum] \n"; print " -f Force overwrite of existing .imgdir or imgdir.php\n"; print " -l Force overwrite of existing index.php symbolic link\n"; print " -F Force overwrite of both; equivalent to -f and -l\n"; print " -v vernum Retreive specified version (\"v\" is added)\n"; print " Retreives the latest version of imgdir.php from the web and\n"; print " installs it in the specified location (use "." to install it\n"; print " in the current directory). Specifically, it will attempt the\n"; print " following steps:\n"; print " - retreive http://www.berzerker.net/imgdir/imgdir.php_\n"; print " - rename local imgdir.php_ to imgdir.php\n"; print " - create a .imgdir sub directory\n"; print " - change access to .imgdir to 777\n"; print " - create an index.php symbolic link to imgdir.php\n"; print "\n"; exit (0); }