diff --git a/apply-patch.sh b/apply-patch.sh index c8e2ddd..63fc1d3 100755 --- a/apply-patch.sh +++ b/apply-patch.sh @@ -1,8 +1,7 @@ #!/usr/bin/env bash usage() { - script=`basename $0` - echo "USAGE: $script AOSP-SRC [TAG]" + echo "USAGE: $(basename "$0") AOSP-SRC [TAG]" exit 1 } @@ -11,24 +10,26 @@ usage() { src=$1 tag=$2 -if [ -z "$tag" ]; then +if [[ -z $tag ]]; then echo "detect AOSP tag from manifest" - tag=`grep revision $src/.repo/manifests/default.xml | cut -d\" -f 2 | cut -d/ -f 3` + tag=$(basename "$(xmllint --xpath "string(/manifest/default/@revision)" "$src"/.repo/manifests/default.xml)") fi echo "===== AOSP SRC: $src" echo "===== AOSP TAG: $tag" -patch_dir=$(dirname $(realpath $0))/$tag -if [ ! -d $patch_dir ];then +patch_dir=$(dirname "$(realpath "$0")")/$tag +if [[ ! -d $patch_dir ]]; then echo "patches for $tag not exist" exit 1 fi -cd $patch_dir -for p in `find * -links 2` +cd "$patch_dir" || exit 1 +while read -r p do + [[ $(find "$patch_dir/$p" -maxdepth 1 -name '*.patch' 2> /dev/null | wc -l) -eq 0 ]] && continue + echo echo "process project: $p" - git -C $src/$p am --reject $patch_dir/$p/* || echo "*****[ERROR]***** apply failed: $p" -done + git -C "$src/$p" am --reject "$patch_dir/$p"/* || echo "*****[ERROR]***** apply failed: $p" +done < <(find -- * -type d)