#!/usr/bin/perl use File::Copy; use Shell::Command; # relocate_all_BD (born digital) # modified to move PDFs as well as MODS, 10/30/09, jld. # 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. # this version simply scatters them to where they go in # the web-accessible directories, so his software can work with them. ##Copyright (c) 2009, The University of Alabama Libraries. ## Contributed by Jody DeRidder, 8/20/09. ##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. # jody DeRidder, 8/20/09 $base = "./MODS/"; print "Please place the MODS and PDF 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 -- uncomment this file if ALL we want to move are MODS files. ($mydir = $file) =~ s,\_,\/,g; # translate underscores in filename to / for directory path $mydir =~ s,\.mods\.xml,,; #remove extensions $mydir =~ s,\.pdf,,i; if ($file =~ /\.mods\.xml$/){ $mydir = $outbase.$mydir."/Metadata/"; # goes in outbase directory, with Metadata subdirectory } else{ $mydir = $outbase.$mydir."/"; } if (! -e $mydir){ `mkdir -p $mydir`;} $oldfile = $indir."/".$file; $newfile = $mydir.$file; if (! (cp $oldfile, $newfile)){ print "ERROR: could not copy $oldfile to $newfile\n";} } close(DIR); 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;