#!/usr/bin/perl use File::Copy; use Shell::Command; use Time::Local; # relocate_all # modified version of relocate_all for archival text and image # picks up jpegs from jpegs directory # jpegs or ocr or txt from transcripts directory # MODS from MODS directory # this version simply scatters them to where they go in # the web-accessible directories, so Acumen can find them ## 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. # jody DeRidder, 5/3/10 $modsdir = "../MODS/"; $jpegdir = "../jpegs/"; $transdir = "../transcripts/"; $outbase = "/srv/www/htdocs/content/"; print "\n\nPlease make sure the content is in the \nappropriate directories under UploadArea;\nno subdirectories are needed.\n"; print "Everything shoulud be on the same level, \nno subdirectories for compound objects.\n\n"; print "\nWARNING: This script assumes all jpegs, ocr.txt \nand txt files in the transcripts directory are Transcripts.\n\n"; print "Remove extraneous files, including the Admin xml file!\n That must be uploaded elsewhere to the database\n"; print "\n When ready hit enter:\n"; $ans = ; @indirs = ($modsdir, $jpegdir, $transdir); foreach $indir (@indirs){ `chmod -R 775 $indir`; # make sure we start with correct permissions, and then retain them opendir(IN, $indir) or die "can't open $indir\n"; while ($file = readdir(IN)){ if ($file =~ /^\./){ next;} # skip . files if (! $file =~ /^[a-z]{1}\d{4}\_\d{7}\_\d{7}(\_\d{4}(\_\d{3})?)?/){ print "$file in $indir does not match filename pattern!\nNOT distributing!\n"; next; } ($mydir = $file) =~ s,\_,\/,g; # translate underscores in filename to / for directory path $mydir =~ s,\.mods\.xml,\/Metadata\/,; #remove extensions $mydir =~ s,\.mp3,\/,i; $mydir =~ s,\.ocr\.txt,\/Transcripts\/,i,; $mydir =~ s,\.txt,\/Transcripts\/,i,; if ($indir =~ /transcripts/i){ # problem! only jpegs in transcripts directory go there $mydir =~ s,\/128\.jpg,\/Transcripts\/,i,; $mydir =~ s,\/512\.jpg,\/Transcripts\/,i,; $mydir =~ s,\/2048\.jpg,\/Transcripts\/,i,; } else{ $mydir =~ s,\/128\.jpg,\/,i,; $mydir =~ s,\/512\.jpg,\/,i,; $mydir =~ s,\/2048\.jpg,\/,i,; } $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; # print "$oldfile --> $newfile\n"; if (! (cp $oldfile, $newfile)){ print "ERROR: could not copy $oldfile to $newfile\n";} if (-e $newfile){ unlink $oldfile; # deletes local copy if (-e $oldfile){ print "I can't delete $oldfile, but I copied it!!\n";} } } close(IN); } print "\nThank you! All done. \nPlease check directories; any files remaining\n"; print "were not processed and have a problem. Please correct and rerun.\n"; print "\n You can view the online 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 "\n When content is live, run the moveContent script to update the database\nand move content off share to the deposits directory\n"; print "\nHit enter to close this window.\n"; $ans = ; print "\n THANK YOU!!! Bye!!\n"; sleep(1); exit;