david_williams | 5125637 | 2010-04-20 21:04:25 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
david_williams | 2aec693 | 2009-05-28 16:34:57 +0000 | [diff] [blame] | 2 | |
| 3 | # Important: it is assumed this script is ran from the directory |
| 4 | # that is the parent of the directory to rename |
| 5 | |
| 6 | oldname=$1 |
| 7 | newname=$2 |
| 8 | |
| 9 | function renamefile () |
| 10 | { |
| 11 | # file name is input parameter |
david_williams | a3b6560 | 2010-08-01 17:50:32 +0000 | [diff] [blame] | 12 | if [[ $1 =~ (.*)($oldname)(.*) ]] |
david_williams | 2aec693 | 2009-05-28 16:34:57 +0000 | [diff] [blame] | 13 | then |
| 14 | echo "changing $1 to ${BASH_REMATCH[1]}$newname${BASH_REMATCH[3]}" |
| 15 | mv "$1" "${BASH_REMATCH[1]}$newname${BASH_REMATCH[3]}" |
| 16 | |
| 17 | fi |
| 18 | |
| 19 | } |
| 20 | |
| 21 | |
| 22 | echo "Renaming build $oldname to $newname" |
| 23 | |
| 24 | fromString=$oldname |
| 25 | toString=$newname |
| 26 | replaceCommand="s!${fromString}!${toString}!g" |
| 27 | |
david_williams | 5c51ca4 | 2011-09-17 20:30:09 +0000 | [diff] [blame] | 28 | # not all these file types may exist, we include all the commonly used ones, though, |
| 29 | # just in case future changes to site files started to have them. There is no harm, per se, |
| 30 | # if the perl command fails. |
| 31 | # TODO: could add some "smarts" here to see if all was as expected before making changes. |
david_williams | 2aec693 | 2009-05-28 16:34:57 +0000 | [diff] [blame] | 32 | perl -w -pi -e ${replaceCommand} ${oldname}/*.php |
| 33 | perl -w -pi -e ${replaceCommand} ${oldname}/*.map |
| 34 | perl -w -pi -e ${replaceCommand} ${oldname}/*.html |
| 35 | perl -w -pi -e ${replaceCommand} ${oldname}/*.xml |
| 36 | perl -w -pi -e ${replaceCommand} ${oldname}/checksum/* |
| 37 | |
| 38 | # move directory before file renames, so it won't be in file path name twice |
| 39 | mv $oldname $newname |
| 40 | |
| 41 | for file in `find ./${newname} -name "*${oldname}*" -print ` |
| 42 | do |
| 43 | renamefile $file |
| 44 | done |