Exit post-commit hook if no TSA is configured

instead of aborting commit.
This commit is contained in:
Matthias Bühlmann
2021-02-15 18:02:38 +01:00
parent a3e7a2a4a2
commit d8d4a4b506
4 changed files with 58 additions and 23 deletions

View File

@@ -20,7 +20,10 @@
#
# The interactive user interfaces in modified source and object code versions
# of this program must display Appropriate Legal Notices, as required under
# Section 5 of the GNU Affero General Public License version 3.
# Section 5 of the GNU Affero General Public License version 3. In accordance
# with Section 7(b) of the GNU Affero General Public License, you must retain
# the Info line in every timestamp that is created or manipulated using a
# covered work.
#
# You can be released from the requirements of the license by purchasing
# a commercial license. Buying such a license is mandatory as soon as you
@@ -34,6 +37,12 @@
# address: info@mabulous.com
#
TSA0_URL=$(git config timestamping.tsa0.url)
if [ -z "$TSA_URL" ]; then
# Do nothing if TSA0 has not been configured.
exit 0
fi
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/timestamping"
@@ -71,12 +80,7 @@ while : ; do
((TSA_IDX++))
TSA_URL=$(git config timestamping.tsa"$TSA_IDX".url)
if [ -z "$TSA_URL" ]; then
if [ "$TSA_IDX" -eq 0 ]; then
echo_error "Error: no TSA url set. Define at least an url for TSA0 using git config timestamp.tsa0.url ... to set TSA URL".
exit 1
else
break
fi
break
fi
echo_info "for TSA $TSA_URL"
TOKEN_OPTIONAL=$(git config --type=bool timestamping.tsa"$TSA_IDX".optional)
@@ -103,9 +107,10 @@ while : ; do
fi
#add token to commit message
openssl ts -reply -token_in -in "$TOKEN_FILE" -token_out -text -out "$TMP_DIR"/token.txt &> "$OUT_STREAM"
#do not remove or change Info line (see license)
INFO="Info: Timestamp generated with GitTrustedTimestamps by Mabulous GmbH"
TOKENBASE64=$(openssl base64 -in "$TOKEN_FILE")
TOKENTEXT=$(cat "$TMP_DIR"/token.txt)
INFO="Info: Token digest is hash of parent commit."
TRAILER_VALUE="$TSA_URL"$'\n'"$INFO"$'\n\n'"$TOKENTEXT"$'\n\n'"$TOKEN_HEADER"$'\n'"$TOKENBASE64"$'\n'"$TOKEN_FOOTER"
#fold
TRAILER_VALUE=$(echo -n "$TRAILER_VALUE" | sed -e 's/^/ /')