commit:     76ef821a35c6ac43665c4909b298a67cc9237bb1
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Nov  9 18:20:27 2021 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Tue Nov  9 18:20:27 2021 +0000
URL:        https://gitweb.gentoo.org/proj/qa-scripts.git/commit/?id=76ef821a

Add a cgi script to trigger git pulls remotely

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 cgi-bin/trigger-pull.sh | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/cgi-bin/trigger-pull.sh b/cgi-bin/trigger-pull.sh
new file mode 100755
index 0000000..89aff7a
--- /dev/null
+++ b/cgi-bin/trigger-pull.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+if [[ ! ${QUERY_STRING} ]]; then
+       echo "Script must be run through CGI" >&2
+       exit 1
+fi
+
+main() {
+       local repo=${QUERY_STRING}
+       if [[ ${repo} == */* ]]; then
+               echo "DANGER! DANGER! DON'T TALK TO STRANGERS!" >&2
+               exit 1
+       fi
+
+       local topdir=$(dirname "${0}")/..
+
+       if ! cd "${topdir}/htdocs/output/${repo}" 2>/dev/null; then
+               echo "Status: 404 Not Found"
+               echo
+               echo "404 Not Found"
+               exit 0
+       fi
+
+       local output=$(git pull -q 2>&1)
+       if [ $? -eq 0 ]; then
+               echo "Status: 200 OK"
+               echo
+               echo "Done."
+       else
+               echo "Status: 500 Failed"
+               echo
+               echo "${output}"
+       fi
+}
+
+main

Reply via email to