5 # This file is part of OpenTTD.
6 # OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
7 # OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 # See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
11 echo "Usage: version_utils.sh OPTION" >&2
12 echo "-s: Output a SHA-256 of the source tree" >&2
13 echo "-l: Output the names of all files in the source tree with their SHA-256 hash" >&2
14 echo "-n: Output the names of all files in the source tree without a hash" >&2
15 echo "-o: Return true (0) if SHA-256 utility can be found" >&2
16 echo "-w: Write ./.ottdrev-vc" >&2
17 echo "-r TAGNAME: Create a tag, write ./.ottdrev-vc referencing the tag, possibly update README.md," >&2
18 echo " commit it and move the tag to point to the new revision. Requires git." >&2
19 echo "-h: Show this help" >&2
28 while getopts ":hslnowr:" opt
; do
57 function handle_source
{
65 function find_hasher
{
66 if [ "`echo -n "test" | sha256sum 2> /dev/null`" == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 -" ]; then
68 elif [ "`echo -n "test" | shasum -a 256 2> /dev/null`" == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 -" ]; then
69 HASH_CMD
="shasum -a 256"
70 elif [ "`echo -n "test" | shasum -a 256 -p 2> /dev/null`" == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 -" ]; then
71 HASH_CMD
="shasum -a 256 -p"
73 echo "Could not generate SHA-256" >&2
78 function output_hash_list
{
82 function read_source
{
83 handle_source
"CMakeLists.txt" "$1"
84 while IFS
=$
'\n' read -r line
; do
85 handle_source
"$line" "$1"
86 done < <( find -L src
-type f \
( -name 'CMakeLists.txt' -o -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h' -o -name '*.sq' -o -name '*.mm' -o -name '*.in' \
) -print | LC_ALL
=C
sort )
87 while IFS
=$
'\n' read -r line
; do
88 handle_source
"$line" "$1"
89 done < <( find -L src
/lang
-type f
-name '*.txt' -print | LC_ALL
=C
sort )
92 if [ -z "$HASH" -a -z "$NAMES" -a -z "$HASHLIST" -a -z "$TESTOK" -a -z "$WRITE" -a -z "$RELEASETAG" ]; then
97 if [ -n "$NAMES" ]; then
101 if [ -n "$HASHLIST" ]; then
106 if [ -n "$HASH" ]; then
108 output_hash_list |
$HASH_CMD
111 if [ -n "$WRITE" ]; then
113 cmake
-DGENERATE_OTTDREV=.ottdrev-vc-tmp
-P cmake
/scripts
/FindVersion.cmake
114 output_hash_list |
$HASH_CMD >> .ottdrev-vc-tmp
115 mv .ottdrev-vc-tmp .ottdrev-vc
118 function unignore_files
{
119 git update-index
--no-assume-unchanged README.md jgrpp-changelog.md .ottdrev-vc
122 if [ -n "$RELEASETAG" ]; then
123 git update-index
--assume-unchanged README.md jgrpp-changelog.md .ottdrev-vc
124 trap unignore_files EXIT
125 if ! git diff-index
--quiet HEAD
; then
126 echo "Repo is dirty, aborting" >&2
129 if ! git diff-index
--quiet --cached HEAD
; then
130 echo "Repo is dirty, aborting" >&2
133 if [ "${RELEASETAG:0:6}" = "jgrpp-" -a -n "${RELEASETAG:6}" ]; then
134 if ! grep -q -e "^### v${RELEASETAG:6} (" jgrpp-changelog.md
; then
135 echo "v${RELEASETAG:6} is not in changelog, aborting" >&2
139 if ! git tag
"$RELEASETAG"; then
140 echo "Tag already exists or is not valid, aborting" >&2
143 if ! .
/version_utils.sh
-w; then
148 if [ "${RELEASETAG:0:6}" = "jgrpp-" -a -n "${RELEASETAG:6}" ]; then
149 sed -i "1 s/^\(## JGR's Patchpack version \).\+/\1${RELEASETAG:6}/" README.md
151 git add .ottdrev-vc README.md jgrpp-changelog.md
152 git commit
-m "Version: Committing version data for tag: $RELEASETAG"
153 git tag
-f "$RELEASETAG"
156 if [ -n "$TESTOK" ]; then
157 find_hasher
2> /dev
/null