mkchlog 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. # A shell script to maintain ChangeLog.txt
  3. # Copyright 2018-2019 orbea
  4. # All rights reserved.
  5. #
  6. # Redistribution and use of this script, with or without modification, is
  7. # permitted provided that the following conditions are met:
  8. #
  9. # 1. Redistributions of this script must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  13. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  15. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  18. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  19. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  20. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  21. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. # This is required for the legacy ash in Slackware and can be removed
  23. # once ash is no longer included in any supported Slackware releases.
  24. # shellcheck disable=SC2004
  25. # https://github.com/koalaman/shellcheck/wiki/SC2004
  26. TMP="${TMP:-/tmp}"
  27. set -euf
  28. branch="$(git rev-parse --abbrev-ref HEAD)"
  29. origin=master
  30. chlog=ChangeLog.txt
  31. [ "$branch" = $origin ] && { printf %s\\n "Already on '$origin'."; exit 1; }
  32. [ -f ./$chlog ] || { printf %s\\n "No '$chlog' found."; exit 1; }
  33. trap 'rm -f -- "$TMP/$chlog.new"; trap - EXIT; exit 0' EXIT INT
  34. mkdir -p -- "$TMP"
  35. cat /dev/null > "$TMP/$chlog.new"
  36. git log --format=%s "$branch" ^$origin --no-merges | while read -r line; do
  37. [ "${line}" ] || continue
  38. printf %s\\n "$line" >> "$TMP/$chlog.new"
  39. done
  40. date="$(date -u)"
  41. day="$(date -u +%Y%m%d)"
  42. tag=1
  43. while git rev-parse "$day.$tag" >/dev/null 2>&1; do
  44. tag="$(($tag+1))"
  45. done
  46. sed -i '1s/^/+--------------------------+\n/' ./$chlog
  47. sort < "$TMP/$chlog.new" | sed "1s/^/$date\\n/" |
  48. cat - ./$chlog > "$TMP/$chlog.tmp"
  49. mv -- "$TMP/$chlog.tmp" ./$chlog
  50. git add ./$chlog
  51. git commit -sm "Public www update: $date."
  52. git tag "$day.$tag"