mirror of
https://github.com/aljazceru/gna.git
synced 2025-12-17 14:04:19 +01:00
use post-commit scirpt to edit config
Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
21
gna.sh
21
gna.sh
@@ -34,14 +34,19 @@ fi
|
|||||||
|
|
||||||
HOOK=`cat <<'EOF'
|
HOOK=`cat <<'EOF'
|
||||||
#!/bin/sh\n
|
#!/bin/sh\n
|
||||||
|
COMMIT=$(git rev-parse HEAD)\n
|
||||||
\n
|
\n
|
||||||
url="$2"\n
|
URLS=$(git remote -v | awk '/\(fetch\)/ {print $2} /\(push\)/ {print $3}' | awk -F' ' '{for(i=1;i<=NF;i++) if($i ~ /http/) print $i}')\n
|
||||||
commit=$(git rev-parse HEAD)\n
|
\n
|
||||||
|
for url in $URLS; do\n
|
||||||
privKey=$(pass PASS_PATH)\n
|
privKey=$(pass PASS_PATH)\n
|
||||||
EVENT="{\"content\":\"\",\"kind\":27235,\"created_at\":$(date +%s),\"tags\":[[\"u\",\"$url\"],[\"method\",\"push\"],[\"payload\",\"$commit\"]]}"\n
|
EVENT="{\"content\":\"\",\"kind\":27235,\"created_at\":$(date +%s),\"tags\":[[\"u\",\"$url\"],[\"method\",\"push\"],[\"payload\",\"$COMMIT\"]]}"\n
|
||||||
|
\n
|
||||||
SIGNED=$(echo -n $EVENT | nak event -sec $privKey)\n
|
SIGNED=$(echo -n $EVENT | nak event -sec $privKey)\n
|
||||||
NOSTR_AUTH_HEADER=$(echo -n $SIGNED | base64 -w 0)\n
|
NOSTR_AUTH_HEADER=$(echo -n $SIGNED | base64 -w 0)\n
|
||||||
git config http.$url.extraHeader "X-Authorization: Nostr $NOSTR_AUTH_HEADER"\n
|
git config http.$url.extraHeader "X-Authorization: Nostr $NOSTR_AUTH_HEADER"\n
|
||||||
|
done\n
|
||||||
|
\n
|
||||||
EOF
|
EOF
|
||||||
`
|
`
|
||||||
PASS_PATH=$(sed 's/\//\\\//g' <<< "$PASS_PATH")
|
PASS_PATH=$(sed 's/\//\\\//g' <<< "$PASS_PATH")
|
||||||
@@ -49,12 +54,12 @@ PATTERN="s/PASS_PATH/$PASS_PATH/g"
|
|||||||
HOOK=$(sed "$PATTERN" <<< "$HOOK")
|
HOOK=$(sed "$PATTERN" <<< "$HOOK")
|
||||||
|
|
||||||
echo "Installing git hooks..."
|
echo "Installing git hooks..."
|
||||||
if [ -f "$GIT_REPO/.git/hooks/pre-push" ]; then
|
if [ -f "$GIT_REPO/.git/hooks/post-commit" ]; then
|
||||||
echo "pre-push hook already exists. Skipping..."
|
echo "post-commit hook already exists. Skipping..."
|
||||||
else
|
else
|
||||||
echo "Installing pre-push hook..."
|
echo "Installing post-commit hook..."
|
||||||
echo -e $HOOK >> $GIT_REPO/.git/hooks/pre-push
|
echo -e $HOOK >> $GIT_REPO/.git/hooks/post-commit
|
||||||
chmod +x $GIT_REPO/.git/hooks/pre-push
|
chmod +x $GIT_REPO/.git/hooks/post-commit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|||||||
Reference in New Issue
Block a user