interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / bazinga / omega-read

58 lines · 2626 bytes Raw Blame History
1#!/bin/sh
2# The clone and both main archives use the same public, filtered repository.
3set -eu
4export GIT_PROJECT_ROOT=/var/www/interplane-git
5export GIT_HTTP_EXPORT_ALL=1
6notfound() { printf 'Status: 404 Not Found\r\n\r\n'; exit 0; }
7route=${PATH_INFO#/}
8name=${route%%/*}
9case "$name" in ''|[!a-zA-Z0-9]*|*[!a-zA-Z0-9._-]*) notfound ;; esac
10repo="$GIT_PROJECT_ROOT/$name.git"
11[ -d "$repo" ] && [ ! -L "$repo" ] || notfound
12PATH_INFO="/${route#*/}"
13export GIT_CONFIG_COUNT=3 GIT_CONFIG_KEY_0=safe.directory GIT_CONFIG_VALUE_0="$repo"
14export GIT_CONFIG_KEY_1=http.receivepack GIT_CONFIG_VALUE_1=false
15# http-backend invokes upload-pack on dot after entering this fixed public repo.
16cd "$repo"
17export GIT_CONFIG_KEY_2=safe.directory GIT_CONFIG_VALUE_2=.
18case "$REQUEST_METHOD $PATH_INFO" in
19 "GET /info/refs"|"POST /git-upload-pack")
20 case "$REQUEST_METHOD:$QUERY_STRING" in
21 GET:service=git-upload-pack|GET:|POST:) ;;
22 *) printf "Status: 403 Forbidden\r\n\r\n"; exit 0 ;;
23 esac
24 export PATH_INFO="/$name.git$PATH_INFO"
25 exec /usr/lib/git-core/git-http-backend
26 ;;
27 "GET /archive/"*|"HEAD /archive/"*|"GET /refs/heads/"*|"HEAD /refs/heads/"*|"GET /commits/"*|"HEAD /commits/"*)
28 case "$PATH_INFO" in
29 *.zip) format=zip; mime=application/zip ;;
30 *.tar.gz) format=tar.gz; mime=application/gzip ;;
31 *) notfound ;;
32 esac
33 case "$PATH_INFO" in
34 /commits/*)
35 commit=${PATH_INFO#/commits/}
36 commit=${commit%."$format"}
37 case "$commit" in *[!0-9a-f]*) notfound ;; esac
38 [ "${#commit}" -eq 40 ] || notfound
39 [ "$(git cat-file -t "$commit" 2>/dev/null)" = commit ] || notfound
40 visible=$(git for-each-ref --count=1 --contains="$commit" --format='%(refname)' refs/heads refs/tags) || notfound
41 [ -n "$visible" ] || notfound
42 label=$commit
43 ;;
44 *)
45 branch=${PATH_INFO#/refs/heads/}
46 branch=${branch#/archive/}
47 branch=${branch%."$format"}
48 case "$branch" in ''|*[!a-zA-Z0-9._/-]*) notfound ;; esac
49 git check-ref-format "refs/heads/$branch" >/dev/null || notfound
50 commit=$(git --git-dir="$repo" rev-parse --verify "refs/heads/$branch^{commit}" 2>/dev/null) || notfound
51 label=$(printf '%s' "$branch" | tr / -)
52 ;;
53 esac
54 printf "Content-Type: %s\r\nContent-Disposition: attachment; filename=%s-%s.%s\r\nETag: \"%s\"\r\nCache-Control: no-cache\r\n\r\n" "$mime" "$name" "$label" "$format" "$commit"
55 [ "$REQUEST_METHOD" = HEAD ] || exec git --git-dir="$repo" archive --format="$format" --prefix="$name-$label/" "$commit"
56 ;;
57 *) printf "Status: 405 Method Not Allowed\r\n\r\n" ;;
58esac