#!/usr/bin/perl use File::Copy; use Shell::Command; use Time::Local; use DBI; # relocate_all_bornDigital # modified to move PDFs as well as MODS, 10/30/09, jld. # modified 12/23/09 to # check the database for embargo # copy MODS and content live for non-embargoed stuff # copy MODS to deposit directory to go to archive # will need to follow this with a script to check that MODS has changed before # archiving new version # undergrad research does not need to be archived -- can be deposited in Acumen. # this for the MODS files output from spreadsheets using Tonio's software. # once the MODS files are repaired, rewrite this to move to /archive and link # the item-level files as v1 into the Manifests there for LOCKSS # this version, however, simply scatters them to where they go in # the web-accessible directories, so his software can work with them. # modified 2/8/10 to copy content to deposit directory to go to archive IF # the collection is u0015_0000001 (ETDs) # jody DeRidder, 8/20/09 ## Copyright (c) 2010, The University of Alabama Libraries. ## Contributed by Jody DeRidder, 7/30/10. ## All rights reserved. ## Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ## * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. ## * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in ## the documentation and/or other materials provided with the distribution. ## * Neither the name of The University of Alabama Libraries nor the names of its contributors may be used to endorse or promote products ## derived from this software without specific prior written permission. ##THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ##THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ##CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ##PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ##LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ##EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #$indir = "/srv/scripts/metadata/MODS/Output/"; #$indir = "/home/taloewald/MODS/Output/"; #$indir = "./MODS_20090925/"; $base = "./MODS/"; $archive = "/srv/deposits/bornDigital/u0015_0000001/Metadata/"; $saveContent = "/srv/deposits/bornDigital/u0015_0000001/Content/"; $hostname = "localhost"; $port = "3306"; $user = "user"; $password = "password"; $database = "InfoTrack"; ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime; $year += 1900; $mon += 1; # this makes it this month if ($mon =~ /^[1-9]{1}$/){ $mon = "0".$mon;} $test = "$year-$mon-$mday"; print "I will check the database for content still under embargo today, $test\n\n\n"; $dbh = DBI->connect("DBI:mysql:$database:$hostname", #:$port", $user, $password) or die "can't connect to database: ",$DBI::errstr,"\n"; $h->{PrintError} = 1; $h->{RaiseError} = 1; $mydate = $dbh->quote($test); $sth = $dbh->prepare("select id_2009 from bornDigital where dateAvailable > $mydate") or die "can't prepare select ",$dbh->errstr(),"\n"; $sth->execute() or die "Can't select from InfoTrack : ", $sth->errstr(),"\n"; while (@vals= $sth->fetchrow_array()){ $anid = $vals[0]; push (@holdback, $anid); # print "$anid is not yet live\n"; } $sth->finish(); $dbh->disconnect(); #print "testing for $year-$mon-01\n"; #:$hour $min $sec\n"; print "Please place the MODS and content files into a \nsubdirectory of MODS which is named for today's date.\n\n"; print "Unzip them, make sure they are all on the same level, \nno subdirectories for compound objects.\n\n"; print "Remove extraneous files. Then tell me the name of \ntoday's upload directory and hit enter:\n"; $dir = ; chomp $dir; $indir = $base.$dir; print "Is this correct? Enter Y or N\n"; $answ = ; while ($answ =~ /n/i){ REDO: print "Please re-enter the name of the subdirectory of MODS where you have today's upload:\n"; $dir = ; chomp $dir; $indir = $base.$dir; print "Is this correct? Enter Y or N\n"; $answ = ; } if (! -e $indir){ print "that directory does not exist.\n"; goto REDO; } else{ `chmod -R 775 $indir`;} # make sure we start with correct permissions, and then retain them $outbase = "/srv/www/htdocs/content/"; opendir(IN, $indir) or die "can't open $indir\n"; while ($file = readdir(IN)){ if ($file =~ /^\./){ next;} # skip . files # if (! $file =~ /\.mods\.xml$/){ next;} # skip $path = $indir."/".$file; if ($file =~ /^(.{21}).*/){ $id = $1; foreach $h (@holdback){ # if it's in this list, don't send it live # print "comparing -->$id<--- to -->$h<---\n"; if ($id eq $h){ print "holding back $h\n"; if ($file =~ /u0015_0000001.*?\.mods\.xml/){ $out = $archive.$file; # go ahead and put it in deposits directory if (! (cp $path, $out)){ print "ERROR: could not copy $file to $archive\n";} else{ unlink $path;} # deletes local copy } elsif ($file =~ /u0015_0000001.*?/){ $out = $saveContent.$file; # go ahead and put it in deposits directory if (! (cp $path, $out)){ print "ERROR: could not copy $file to $archive\n";} else{ unlink $path;} # deletes local copy } next; } } } else{ print "ERROR: cannot find id for $file\n";} ($mydir = $file) =~ s,\_,\/,g; # translate underscores in filename to / for directory path $mydir =~ s,\.mods\.xml,,; #remove extensions $mydir =~ s,\.pdf,,i; $mydir =~ s,\..*,,; # remove extensions from subfiles too if ($file =~ /\.mods\.xml$/){ $mydir = $outbase.$mydir."/Metadata/"; # goes in outbase directory, with Metadata subdirectory } else{ $mydir = $outbase.$mydir."/"; } if (! -e $mydir){ $mypath = $mydir; $mypath =~ s,$outbase,,; undef $test; while ($mypath =~ /(.*?\/)(.*)/){ $test .= $1; $mypath = $2; $apath = $outbase.$test; if (!-e $apath){ `mkdir -m 0775 $apath`; } } $test .= $mypath; $apath = $outbase.$test; if (!-e $apath){ `mkdir -m 0775 $apath`; } } $oldfile = $indir."/".$file; $newfile = $mydir.$file; if (! (cp $oldfile, $newfile)){ print "ERROR: could not copy $oldfile to $newfile\n";} elsif ($file =~ /u0015_0000001.*?\.mods\.xml/){ $out = $archive.$file; # go ahead and put it in deposits directory if (! (cp $path, $out)){ print "ERROR: could not copy $file to $archive\n";} else{ unlink $path;} # deletes local copy } elsif ($file =~ /u0015_0000001.*?/){ $out = $saveContent.$file; # go ahead and put it in deposits directory if (! (cp $path, $out)){ print "ERROR: could not copy $file to $archive\n";} if (-e $out){ unlink $path;} # deletes local copy } } close(DIR); #`chmod -R 775 $outbase`; print "\nThank you! All done. \n You can view the files at http:\/\/libcontent1.lib.ua.edu\/content\/\n"; print "Log in at http:\/\/acumen.lib.ua.edu as admin with password:\n zero followed by letters \"fo\" followed by a one followed by the letter \"o\"\n click on Admin and reindex so that your changes will go live.\n"; print "\n Then please check the website to verify display is correct.\n"; print "\nHit enter to close this window.\n"; $ans = ; print "\n THANK YOU!!! Bye!!\n"; sleep(1); exit;