| 1 |
operz |
1 |
#!/bin/ksh |
| 2 |
|
|
# |
| 3 |
|
|
# $Id: replacer 1023 2007-02-04 09:20:41Z comand $ |
| 4 |
|
|
# |
| 5 |
|
|
# Copyright 2006 Cory Omand <comand@blastwave.org> |
| 6 |
|
|
# All rights reserved. Use is subject to license terms. |
| 7 |
|
|
# |
| 8 |
|
|
# Redistribution and/or use, with or without modification, is |
| 9 |
|
|
# permitted. This software is without warranty of any kind. The |
| 10 |
|
|
# author(s) shall not be liable in the event that use of the |
| 11 |
|
|
# software causes damage. |
| 12 |
|
|
# |
| 13 |
|
|
# replacer - replace or remove references to the specified directory. |
| 14 |
|
|
# |
| 15 |
|
|
|
| 16 |
|
|
function usage { |
| 17 |
|
|
print "Usage: $0 <root_path> <replace_path>.." |
| 18 |
|
|
exit 1 |
| 19 |
|
|
} |
| 20 |
|
|
|
| 21 |
|
|
ROOTDIR=${1:-'.'} |
| 22 |
|
|
[ $# -ge 1 ] && shift |
| 23 |
|
|
|
| 24 |
|
|
[ -z "$@" ] && usage |
| 25 |
|
|
|
| 26 |
|
|
for subdir in $@ |
| 27 |
|
|
do |
| 28 |
|
|
for file in `find $ROOTDIR -type f | xargs -r ggrep -l $subdir` |
| 29 |
|
|
do |
| 30 |
|
|
ok=true |
| 31 |
|
|
|
| 32 |
|
|
# Skip backups and static libraries |
| 33 |
|
|
if [[ "$file" == *.bak ]]; then ok=false ; fi |
| 34 |
|
|
if [[ "$file" == *~ ]]; then ok=false ; fi |
| 35 |
|
|
if [[ "$file" == *.a ]]; then ok=false ; fi |
| 36 |
|
|
|
| 37 |
|
|
# Skip ELF binaries and archives |
| 38 |
|
|
ftype="`file $file 2>&1`" |
| 39 |
|
|
if [[ "$ftype" == *ELF* ]]; then ok=false ; fi |
| 40 |
|
|
if [[ "$ftype" == *:*archive* ]]; then ok=false ; fi |
| 41 |
|
|
|
| 42 |
|
|
if $ok ; then |
| 43 |
|
|
echo $file |
| 44 |
|
|
perl -i~ -plne " |
| 45 |
|
|
s#-[ILR]\s*$subdir\S+\s+##g; |
| 46 |
|
|
s#$subdir/#/#g; |
| 47 |
|
|
s#$subdir\b##g; |
| 48 |
|
|
" $file |
| 49 |
|
|
fi |
| 50 |
|
|
|
| 51 |
|
|
done |
| 52 |
|
|
done |
| 53 |
|
|
|
| 54 |
|
|
exit 0 |
| 55 |
|
|
|