Index: Tools/scripts/bump-revision.sh =================================================================== --- Tools/scripts/bump-revision.sh +++ Tools/scripts/bump-revision.sh @@ -1,6 +1,8 @@ #!/bin/sh # +# ex: ts=4 sw=4 expandtab +# # bump-revision.sh category/portname category/portname ... # Bump PORTREVISION if it exists or create it with number 1 if it does not # @@ -47,50 +49,53 @@ while [ $# -gt 0 ] do - if [ -f "$1/Makefile" ]; then - # If the Makefile exists, continue and empty the tempfile, set up variables - echo -n > $tempfile - revision_str=`grep "^PORTREVISION?\?=" "$1/Makefile"` - revision_num=`echo "$revision_str" | awk -F "\t+" '{ print $2 }'` - - case $? in - 0) - # If the exit code is 0, then PORTREVISION line was found - if [ `echo "$revision_str" | wc -l` = 1 ]; then - # If the $revision_str variable has only 1 line, then proceed with processing it - case `echo "$revision_str" | awk -F "\t+" '{ print $2 }'` in - (*[^0-9]*|'') - # If the value of PORTREVISION is not an integer, we can't bump its value - printc "ERROR: $1 PORTREVISION value is not a number, unable to solve!" "red" - ;; - (*) - # If the value of PORTREVISION is an integer, increase it by 1 - printc "INFO: $1 PORTREVISION= $revision_num found, bumping it by 1." "green" - rm -f $tempfile && awk -F "\t+" '/^PORTREVISION\??=/{ gsub ($2, $2+1) }; { print }' "$1/Makefile" > $tempfile \ - && cat $tempfile > "$1/Makefile" \ - || printc "ERROR: $1 PORTREVISION found but failed to bump it!" "red" - ;; - esac - else - # If the $revision_str variable had more than 1 line, we can't bump its value safely - printc "ERROR: $1 PORTREVISION found more than once, unable to bump it reliably!" "red" - fi - ;; - 1) - # If the exit code is 1 then PORTREVISION wasn't found, so we need to add one with value of 1 - printc "INFO: $1 PORTREVISION not found, adding PORTREVISION= 1" "green" - rm -f $tempfile && awk '/^(PORT|DIST)VERSION\??=\t/{ print; print "PORTREVISION=\t1"; next } { print }' "$1/Makefile" > $tempfile \ - && cat $tempfile > "$1/Makefile" \ - || printc "ERROR: $1 PORTREVISION found but failed to bump it!" "red" - ;; - *) - printc "ERROR: PORTREVISION grep for $1 exited with error!" "red" - ;; - esac - else + if [ ! -f "$1/Makefile" ]; then # The directory specified had no Makefile, so it seems like a mistake printc "ERROR: $1 might not be a port directory because $1/Makefile is missing!" "red" + shift + continue + fi + + revision_nlines=$(egrep -c '^PORTREVISION\??' $1/Makefile) + + if [ $? -gt 1 ]; then + printc "ERROR: PORTREVISION grep for $1 exited with error!" "red" + shift + continue + fi + + if [ $revision_nlines -gt 1 ]; then + # If the $revision_str variable had more than 1 line, we can't bump its value safely + printc "ERROR: $1 PORTREVISION found more than once, unable to bump it reliably!" "red" + shift + continue fi + + revision_num=$(make -C $1 -V PORTREVISION) + + if ! echo "$revision_num" | egrep -q '^[0-9]+$'; then + # If the value of PORTREVISION is not an integer, we can't bump its value + printc "ERROR: $1 PORTREVISION value is not a number, unable to solve!" "red" + shift + continue + fi + + if [ $revision_nlines -eq 1 ]; then + # If the value of PORTREVISION is an integer, increase it by 1 + printc "INFO: $1 PORTREVISION= $revision_num found, bumping it by 1." "green" + rm -f $tempfile \ + && awk -F "\t+" '/^PORTREVISION\??=/{ gsub ($2, $2+1) }; { print }' "$1/Makefile" > $tempfile \ + && cat $tempfile > "$1/Makefile" \ + || printc "ERROR: $1 PORTREVISION found but failed to bump it!" "red" + else + # If the exit code is 1 then PORTREVISION wasn't found, so we need to add one with value of 1 + printc "INFO: $1 PORTREVISION not found, adding PORTREVISION= 1" "green" + rm -f $tempfile \ + && awk '/^(PORT|DIST)VERSION\??=\t/{ print; print "PORTREVISION=\t1"; next } { print }' "$1/Makefile" > $tempfile \ + && cat $tempfile > "$1/Makefile" \ + || printc "ERROR: $1 PORTREVISION found but failed to bump it!" "red" + fi + shift done