You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
750 B

  1. #!/bin/bash
  2. # Increment a version string using Semantic Versioning (SemVer) terminology.
  3. # Parse command line options.
  4. while getopts ":Mmp" Option
  5. do
  6. case $Option in
  7. M ) major=true;;
  8. m ) minor=true;;
  9. p ) patch=true;;
  10. esac
  11. done
  12. shift $(($OPTIND - 1))
  13. version=$1
  14. # Build array from version string.
  15. a=( ${version//./ } )
  16. # If version string is missing or has the wrong number of members, show usage message.
  17. if [ ${#a[@]} -ne 3 ]
  18. then
  19. echo "usage: $(basename $0) [-Mmp] major.minor.patch"
  20. exit 1
  21. fi
  22. # Increment version numbers as requested.
  23. if [ ! -z $major ]
  24. then
  25. ((a[0]++))
  26. a[1]=0
  27. a[2]=0
  28. fi
  29. if [ ! -z $minor ]
  30. then
  31. ((a[1]++))
  32. a[2]=0
  33. fi
  34. if [ ! -z $patch ]
  35. then
  36. ((a[2]++))
  37. fi
  38. echo "${a[0]}.${a[1]}.${a[2]}"