Created
January 14, 2013 20:41
-
-
Save nickboldt/4533210 to your computer and use it in GitHub Desktop.
script to find disabled jobs and enable them, or enabled jobs and disable them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ]; then | |
echo "usage: $0 \"<dir(s)>\" <-d|-DISABLE|-e|-ENABLE> \"--include <include paths>\" \"--exclude <exclude paths>\""; echo ""; | |
echo "example: $0 . -d --include \"component|updatesite|aggregate\" --exclude \"xulrunner\" "; echo ""; | |
exit 1; | |
fi | |
# files to change | |
dirs="."; | |
includepath="*" | |
includepattern="config.xml" | |
excludepattern="" | |
# regex replacements | |
matchpattern="" | |
replacepattern="" | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
'--include') | |
includepath=$2; | |
# includes path and filename, so extract path (filename is always config.xml) | |
if [[ ${includepath##*/*} == "" ]]; then includepath=${includepath%%/*}; fi | |
shift 1;; | |
'--exclude') | |
excludepattern="$2"; shift 1;; | |
'-d'|'-DISABLE') | |
# is enabled (disabled=false) so want to disable (disabled=true) | |
matchpattern="disabled>false<"; | |
replacepattern="disabled>true<";; | |
'-e'|'-ENABLE') | |
# is disabled (disabled=true) so want to enable (disable=false) | |
replacepattern="disabled>false<"; | |
matchpattern="disabled>true<";; | |
*) dirs="$1"; | |
esac | |
shift | |
done | |
echo "includepattern=${includepattern}" | |
echo "includepath=${includepath}" | |
echo "excludepattern=${excludepattern}" | |
echo "matchpattern=${matchpattern}" | |
echo "replacepattern=${replacepattern}" | |
echo "dirs=${dirs}" | |
cnt=0; | |
for d in $dirs; do | |
tmp=$(mktemp -p /tmp XXXXXX); rm -f $tmp; tmp="_"${tmp//\//}${tmp//\//}tmp"_"; # echo $tmp; # make random string (YY6Qjj), then change to _tmpYY6QjjtmpYY6Qjjtmp_ | |
if [[ $excludepattern != "" ]]; then | |
files=$(find $d $minmax -type f -name ${includepattern} | sort | egrep "$includepath" | egrep -v "$excludepattern" | sed -e "s/ /$tmp/g"); | |
else | |
files=$(find $d $minmax -type f -name ${includepattern} | sort | egrep "$includepath" | sed -e "s/ /$tmp/g"); | |
fi | |
# echo $files; # get files and apply temp string replacement for " " to keep files w/ spaces in names together | |
for f in $files; do | |
g=${f//$tmp/ }; # echo "$g ..."; # remove temp string replacement for " " | |
if [ "$(egrep -c "$searchstring" "$g")" != "0" ]; then | |
(( cnt++ )); | |
echo "$cnt: $f "; | |
sed -i -e "s#${matchpattern}#${replacepattern}#g" $f | |
fi | |
done | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment