From 1405f339575cba2ae64f3463067cbed8c9add427 Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Mon, 8 Jan 2024 09:27:25 +0100 Subject: [PATCH] final nuggit: check if we wrote our last redeem number This can catch people manually tinkering with the nuggits "branch" Also: remove duplicate flag from nuggits... --- create_challenge.sh | 5 ----- lib.sh | 4 +++- src/nuggits | 1 - src/redeem.nuggit | 7 ++++++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/create_challenge.sh b/create_challenge.sh index 5edffa5..cd18595 100755 --- a/create_challenge.sh +++ b/create_challenge.sh @@ -119,11 +119,6 @@ eval "$DOCDIR/store_nuggits.sh" # register the nuggits in our "git database" (ak ALMOST_CREDITS_HASH="$(git hash-object -w "$DOCDIR/almost_credits.txt")" # for the final credits do a little rot13, just to make life a bit harder if anyone e.g. greps through the loose objects... CREDITS_HASH="$(tr 'A-Za-z' 'N-ZA-Mn-za-m' < "$DOCDIR/credits.txt" | git hash-object -w --stdin)" -CREDIT_WHERE_CREDIT_IS_DUE="$(echo " -[ \"\$redeemed_flags\" -ne $((NUMBER_OF_NUGGITS - 1)) ] || - git cat-file -p $ALMOST_CREDITS_HASH; -[ \"\$redeemed_flags\" -ne $NUMBER_OF_NUGGITS ] || - git cat-file -p $CREDITS_HASH | tr 'A-Za-z' 'N-ZA-Mn-za-m';" | tr -d "\n")" replace_placeholders "$DOCDIR/redeem.nuggit" > ./redeem.nuggit chmod +x ./redeem.nuggit diff --git a/lib.sh b/lib.sh index c7d2cbb..87c9cc3 100644 --- a/lib.sh +++ b/lib.sh @@ -49,7 +49,9 @@ reproducibility_setup() { replace_placeholders() { sed -e "s/INTERACTIVE_REBASE_BASE_COMMIT/$INTERACTIVE_REBASE_BASE_COMMIT/" \ -e "s/BRANCH_COMMIT/$BRANCH_COMMIT/" \ - -e "s/CREDIT_WHERE_CREDIT_IS_DUE/$(printf "%q" "$CREDIT_WHERE_CREDIT_IS_DUE")"/ \ + -e "s/NUMBER_OF_NUGGITS/$NUMBER_OF_NUGGITS"/ \ + -e "s/ALMOST_CREDITS_HASH/$ALMOST_CREDITS_HASH"/ \ + -e "s/CREDITS_HASH/$CREDITS_HASH"/ \ -e "s/LOCAL_CODE_EXECUTION_HASH/$LOCAL_CODE_EXECUTION_HASH/" \ -e "s/INTERACTIVE_REBASE_EXAMPLE_PICKS/$INTERACTIVE_REBASE_EXAMPLE_PICKS/" \ -e "s/INTERACTIVE_REBASE_COMMIT/$INTERACTIVE_REBASE_COMMIT/" "$1" diff --git a/src/nuggits b/src/nuggits index b669799..e6344d7 100644 --- a/src/nuggits +++ b/src/nuggits @@ -2,7 +2,6 @@ LocalCodeExecution WorkInProgress CommitmentIssues CommitMirInsAbendteuerland -LocalCodeExecution Switcheridoo ShowMeMore MyFirstBranch diff --git a/src/redeem.nuggit b/src/redeem.nuggit index 7ad9c6c..fab5d8e 100755 --- a/src/redeem.nuggit +++ b/src/redeem.nuggit @@ -19,7 +19,12 @@ else redeemed_flags="$(git rev-list --count nuggits)" - CREDIT_WHERE_CREDIT_IS_DUE + [ "$redeemed_flags" -ne NUMBER_OF_NUGGITS ] || git cat-file -p ALMOST_CREDITS_HASH; + + [ "$redeemed_flags" -ne $(( NUMBER_OF_NUGGITS + 1 )) ] || { + git cat-file -e "$(echo "# Redemed flags: $((NUMBER_OF_NUGGITS - 1))" | git hash-object --stdin)" 2>/dev/null || { echo Noughty boy!; exit 1; } + git cat-file -p CREDITS_HASH | tr 'A-Za-z' 'N-ZA-Mn-za-m'; + } git cat-file -p "$(echo "'$nuggit' already redeemed" | git hash-object --stdin)" 2>/dev/null && exit git cat-file -p "$(echo "You tried '$nuggit' before. It still isn't a valid answer... 🙄" | git hash-object --stdin)" 2>/dev/null && exit 1