diff options
author | Michał Górny <mgorny@gentoo.org> | 2015-09-06 15:24:28 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2015-09-06 15:24:28 +0200 |
commit | 49748d5bfee72b7e80a93a11250a1ba78eadfcab (patch) | |
tree | 8c46ce091758d266498d1f14ed3e9d34a852c03c /cgi-bin | |
parent | Add a script to fetch remote check reports from git repos (diff) | |
download | qa-scripts-49748d5bfee72b7e80a93a11250a1ba78eadfcab.tar.gz qa-scripts-49748d5bfee72b7e80a93a11250a1ba78eadfcab.tar.bz2 qa-scripts-49748d5bfee72b7e80a93a11250a1ba78eadfcab.zip |
cgi: Add script to output files from git repo
Diffstat (limited to 'cgi-bin')
-rwxr-xr-x | cgi-bin/get-git-file.sh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cgi-bin/get-git-file.sh b/cgi-bin/get-git-file.sh new file mode 100755 index 0000000..8b48b08 --- /dev/null +++ b/cgi-bin/get-git-file.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +if [[ ! ${QUERY_STRING} ]]; then + echo "Script must be run through CGI" >&2 + exit 1 +fi + +main() { + local qs=${QUERY_STRING} + local repo=${qs%%;*} + qs=${qs#*;} + local commit=${qs%%;*} + qs=${qs#*;} + local file=${qs%%;*} + + if [[ ${repo} == */* ]]; then + echo "DANGER! SOMEONE TRIES TO ABUSE ME!" >&2 + exit 1 + fi + + if ! cd "$(dirname "${0}")/../htdocs/output/${repo}" 2>/dev/null; then + echo "Status: 404 Not Found" + echo + echo "404 Not Found" + exit 0 + fi + + local tree=( $(git ls-tree "${commit}" "${file}" 2>/dev/null) ) + if [[ ! ${tree[*]} ]]; then + echo "Status: 404 Not Found" + echo + echo "404 Not Found" + exit 0 + fi + + local ct + case "${file}" in + *.css) ct=text/css;; + *.html) ct=text/html;; + *) ct=text/plain;; + esac + + echo "Content-Type: ${ct}" + echo + git cat-file -p "${tree[2]}" +} + +main |