#!/usr/bin/env rc gitdir=`{git rev-parse --git-dir} sip_root='@SIP_ROOT@' queue=$gitdir^/sip/queue if(! mkdir -p $queue) { echo sip: could not create event queue $queue >[1=2] exit 1 } queued_at=`{date +%s} if(! awk -v queue=$queue -v queued_at=$queued_at ' function zero_oid(oid) { return oid ~ "^0+$" } function event_kind(old, new) { if (zero_oid(old)) return "create" if (zero_oid(new)) return "delete" return "update" } function clean_actor(actor) { gsub(/[[:space:]]+/, "_", actor) gsub(/[^A-Za-z0-9._@+-]/, "_", actor) return actor } function shell_quote(value, q, bs) { q = sprintf("%c", 39) bs = sprintf("%c", 92) gsub(q, q bs q q, value) return q value q } function temp_event_path(command, path) { command = "mktemp " shell_quote(queue "/event.XXXXXXXXXX") if ((command | getline path) != 1) { close(command) print "sip: could not create temporary event in " queue > "/dev/stderr" exit 1 } close(command) return path } $3 ~ "^refs/(heads|tags)/" { if ($1 !~ "^[0-9a-f]{40}$" || $2 !~ "^[0-9a-f]{40}$") { print "sip: malformed receive record for " $3 > "/dev/stderr" exit 1 } path = temp_event_path() final = path ".event" actor = clean_actor(ENVIRON["SIP_ACTOR"]) if (actor == "") actor = "unknown" printf "1\t%s\t%s\t%s\t%s\t%s\t%s\n", $1, $2, $3, actor, queued_at, event_kind($1, $2) > path if (close(path) != 0) { print "sip: could not write event " path > "/dev/stderr" exit 1 } if (system("mv " shell_quote(path) " " shell_quote(final)) != 0) { print "sip: could not publish event " final > "/dev/stderr" exit 1 } } ') { exit 1 } if(git show-ref --verify --quiet refs/sip/orchestrator) { if(! $sip_root^/bin/sip-worker.rc $gitdir) exit 1 }