From 5fe69c4e5867075d8f7c201ae81758b579e5e258 Mon Sep 17 00:00:00 2001 From: Ricard Illa Date: Sun, 3 Jan 2021 20:23:49 +0100 Subject: [PATCH] separate sites --- gitolite-stagit/Dockerfile | 11 +--- gitolite-stagit/bin/build-stagit-repo | 64 ++++++++++++++++--- gitolite-stagit/bin/set-owner | 16 ----- gitolite-stagit/bin/set-owners | 7 -- gitolite-stagit/bin/set-url | 18 ------ gitolite-stagit/bin/set-urls | 7 -- gitolite-stagit/gitolite.rc | 5 +- .../local_code/hooks/common/post-receive | 2 - .../local_code/triggers/build-stagit-repo | 5 ++ gitolite-stagit/local_code/triggers/set-owner | 5 -- .../local_code/triggers/set-owners | 5 -- gitolite-stagit/local_code/triggers/set-url | 5 -- gitolite-stagit/local_code/triggers/set-urls | 5 -- 13 files changed, 64 insertions(+), 91 deletions(-) delete mode 100644 gitolite-stagit/bin/set-owner delete mode 100644 gitolite-stagit/bin/set-owners delete mode 100644 gitolite-stagit/bin/set-url delete mode 100644 gitolite-stagit/bin/set-urls create mode 100644 gitolite-stagit/local_code/triggers/build-stagit-repo delete mode 100644 gitolite-stagit/local_code/triggers/set-owner delete mode 100644 gitolite-stagit/local_code/triggers/set-owners delete mode 100644 gitolite-stagit/local_code/triggers/set-url delete mode 100644 gitolite-stagit/local_code/triggers/set-urls diff --git a/gitolite-stagit/Dockerfile b/gitolite-stagit/Dockerfile index 4ec7753..74e93dd 100644 --- a/gitolite-stagit/Dockerfile +++ b/gitolite-stagit/Dockerfile @@ -30,17 +30,10 @@ RUN chown -R git:git /var/lib/git && \ /usr/local/bin/build-stagit-index \ /usr/local/bin/build-stagit-repo \ /usr/local/bin/build-stagit-repos \ - /usr/local/bin/set-url \ - /usr/local/bin/set-urls \ - /usr/local/bin/set-owner \ - /usr/local/bin/set-owners \ /opt/gitolite-local/hooks/common/post-receive \ /opt/gitolite-local/triggers/build-stagit-index \ - /opt/gitolite-local/triggers/build-stagit-repos \ - /opt/gitolite-local/triggers/set-url \ - /opt/gitolite-local/triggers/set-urls \ - /opt/gitolite-local/triggers/set-owners \ - /opt/gitolite-local/triggers/set-owner + /opt/gitolite-local/triggers/build-stagit-repo \ + /opt/gitolite-local/triggers/build-stagit-repos ENTRYPOINT ["/usr/local/bin/entrypoint"] CMD ["/usr/sbin/sshd", "-D", "-e"] diff --git a/gitolite-stagit/bin/build-stagit-repo b/gitolite-stagit/bin/build-stagit-repo index a239d80..42e8a8f 100644 --- a/gitolite-stagit/bin/build-stagit-repo +++ b/gitolite-stagit/bin/build-stagit-repo @@ -4,19 +4,67 @@ set -e [ -z "${1}" ] && exit -STAGIT_DIR="${STAGIT_DIR:-/var/lib/git/stagit}" +STAGIT_BASE="${STAGIT_BASE:-/var/lib/git/stagit}" GL_REPO_BASE="${GL_REPO_BASE:-/var/lib/git/repositories}" -out_dir="${STAGIT_DIR}/${1}" -repo_dir="${GL_REPO_BASE}/${1}.git" +# shellcheck disable=SC1091 +[ -f /etc/env ] && . /etc/env + +run_stagit () { + repo_dir="${GL_REPO_BASE}/${1}.git" + if [ -n "${2}" ]; then + out_dir="${STAGIT_BASE}-${2}/${1}.git" + else + out_dir="${STAGIT_BASE}/${1}/git" + fi + mkdir -p "${out_dir}" && \ + cd "${out_dir}" && \ + /usr/local/bin/stagit "${repo_dir}" && \ + ln -sf files.html index.html +} + +set_url () { + url_file="${GL_REPO_BASE}/${1}.git/url" + if [ -n "${2}" ]; then + echo "${2}/${1}" > "${url_file}" + else + echo "url not set" + rm -f "${url_file}" + fi +} + +set_owner () { + owner_file="${GL_REPO_BASE}/${1}.git/owner" + if owner=$(gitolite git-config "${1}" gitweb.owner); then + echo "setting owner for '${1}'" + echo "${owner}" > "${owner_file}" + else + echo "usetting owner for '${1}'" + rm -f "${owner_file}" + fi +} echo "running stagit for '${1}'" if gitolite access "${1}" stagit R any; then - mkdir -p "${out_dir}" && \ - cd "${out_dir}" && \ - /usr/local/bin/stagit "${repo_dir}" && - ln -sf files.html index.html + + set_owner "${1}" + + if [ -n "${SITES}" ]; then + _i=1 + for site in ${SITES}; do + url=$(printf "%s" "${URLS}" | cut -d " " -f "$_i") + set_url "${1}" "${url}" + run_stagit "${1}" "${site}" + _i=$((_i+1)) + done + + else + url=$(printf "%s" "${URLS}" | cut -d " " -f 1) + set_url "${1}" "${url}" + run_stagit "${1}" "" + fi + else - rm -rf "${out_dir}" + rm -rf "${STAGIT_BASE}*/${1}.git" fi diff --git a/gitolite-stagit/bin/set-owner b/gitolite-stagit/bin/set-owner deleted file mode 100644 index 7bf4afd..0000000 --- a/gitolite-stagit/bin/set-owner +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -set -e - -[ -z "$1" ] && exit 0 - -GL_REPO_BASE="${GL_REPO_BASE:-/var/lib/git/repositories}" -owner_file="${GL_REPO_BASE}/${1}.git/owner" - -if owner=$(gitolite git-config "${1}" gitweb.owner); then - echo "setting owner for '${1}'" - echo "${owner}" > "${owner_file}" -else - echo "usetting owner for '${1}'" - rm -f "${owner_file}" -fi diff --git a/gitolite-stagit/bin/set-owners b/gitolite-stagit/bin/set-owners deleted file mode 100644 index d043216..0000000 --- a/gitolite-stagit/bin/set-owners +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -set -e - -for repo in $(gitolite list-phy-repos); do - /usr/local/bin/set-owner "${repo}" -done diff --git a/gitolite-stagit/bin/set-url b/gitolite-stagit/bin/set-url deleted file mode 100644 index 64005d5..0000000 --- a/gitolite-stagit/bin/set-url +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -set -e - -[ -z "$1" ] && exit 0 - -GL_REPO_BASE="${GL_REPO_BASE:-/var/lib/git/repositories}" -repo_dir="${GL_REPO_BASE}/${1}.git" - -# shellcheck disable=SC1091 -[ -z "${REPOS_URL}" ] && [ -f /etc/env ] && . /etc/env - -echo "setting url for '${1}'" -if [ -z "$REPOS_URL" ]; then - echo "REPOS_URL not set" - exit 0 -fi -[ -d "$repo_dir" ] && echo "${REPOS_URL}/${1}" > "${repo_dir}/url" diff --git a/gitolite-stagit/bin/set-urls b/gitolite-stagit/bin/set-urls deleted file mode 100644 index bce255e..0000000 --- a/gitolite-stagit/bin/set-urls +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -set -e - -for repo in $(gitolite list-phy-repos); do - /usr/local/bin/set-url "${repo}" -done diff --git a/gitolite-stagit/gitolite.rc b/gitolite-stagit/gitolite.rc index 4d7da89..1e55aec 100644 --- a/gitolite-stagit/gitolite.rc +++ b/gitolite-stagit/gitolite.rc @@ -86,15 +86,12 @@ #POST_COMPILE => [], POST_COMPILE => [ - 'set-urls', - 'set-owners', 'build-stagit-repos', 'build-stagit-index' ], POST_CREATE => [ - 'set-url', - 'set-owner' + 'build-stagit-repo' ], # List of commands and features to enable diff --git a/gitolite-stagit/local_code/hooks/common/post-receive b/gitolite-stagit/local_code/hooks/common/post-receive index 6121394..a74fc11 100644 --- a/gitolite-stagit/local_code/hooks/common/post-receive +++ b/gitolite-stagit/local_code/hooks/common/post-receive @@ -3,6 +3,4 @@ set -e [ -n "${GL_REPO}" ] && \ - /usr/local/bin/set-url "${GL_REPO}" && \ - /usr/local/bin/set-owner "${GL_REPO}" && \ /usr/local/bin/build-stagit-repo "${GL_REPO}" diff --git a/gitolite-stagit/local_code/triggers/build-stagit-repo b/gitolite-stagit/local_code/triggers/build-stagit-repo new file mode 100644 index 0000000..722f145 --- /dev/null +++ b/gitolite-stagit/local_code/triggers/build-stagit-repo @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +[ -n "$2" ] && /usr/local/bin/build-stagit-repo "$2" diff --git a/gitolite-stagit/local_code/triggers/set-owner b/gitolite-stagit/local_code/triggers/set-owner deleted file mode 100644 index 4d7faba..0000000 --- a/gitolite-stagit/local_code/triggers/set-owner +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -e - -[ -n "$2" ] && /usr/local/bin/set-owner "$2" diff --git a/gitolite-stagit/local_code/triggers/set-owners b/gitolite-stagit/local_code/triggers/set-owners deleted file mode 100644 index 018403e..0000000 --- a/gitolite-stagit/local_code/triggers/set-owners +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -e - -/usr/local/bin/set-owners diff --git a/gitolite-stagit/local_code/triggers/set-url b/gitolite-stagit/local_code/triggers/set-url deleted file mode 100644 index 5d68ae1..0000000 --- a/gitolite-stagit/local_code/triggers/set-url +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -e - -[ -n "$2" ] && /usr/local/bin/set-url "$2" diff --git a/gitolite-stagit/local_code/triggers/set-urls b/gitolite-stagit/local_code/triggers/set-urls deleted file mode 100644 index 82b487c..0000000 --- a/gitolite-stagit/local_code/triggers/set-urls +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -e - -/usr/local/bin/set-urls