Home | History | Annotate | Download | only in scripts
      1 #!/bin/bash
      2 
      3 OLD="$1"
      4 NEW="$2"
      5 
      6 # sanity check in input args
      7 if [ -z "$OLD" ] || [ -z "$NEW" ]; then
      8     cat <<EOF
      9 Usage: $0 <old> <new>
     10 Changes the ADT plugin revision number.
     11 Example:
     12   cd tools/eclipse
     13   scripts/update_version.sh 0.1.2 0.2.3
     14 EOF
     15     exit 1
     16 fi
     17 
     18 # sanity check on current dir
     19 if [ `basename "$PWD"` != "eclipse" ]; then
     20     echo "Please run this from tools/eclipse."
     21     exit 1
     22 fi
     23 
     24 # quote dots for regexps
     25 OLD="${OLD//./\.}"
     26 NEW="${NEW//./\.}"
     27 
     28 # Find all the files with the old pattern, except changes.txt and
     29 # p4 edit them. Skip that if there's no p4 in path.
     30 if which g4 1>/dev/null 2>/dev/null ; then
     31     grep -rl "$OLD" * | grep -E "\.xml$|\.MF$" | xargs -n 5 g4 edit
     32 fi
     33 
     34 # Now find the same files but this time use sed to replace in-place with
     35 # the new pattern. Old files get backuped with the .old extension.
     36 grep -rl "$OLD" * | grep -E "\.xml$|\.MF$" | xargs -n 1 sed -i.old "s/$OLD/$NEW/g"
     37 
     38