From f697b300cc0b421b196193c090df54a121b1d398 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Jan 2016 18:01:13 +0200 Subject: Add script for mirroring, update creation script to support --- server/mkrepo | 73 +++++++++++++++++++++++++++ server/mkrepo.sh | 63 ----------------------- server/mrrepo | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+), 63 deletions(-) create mode 100755 server/mkrepo delete mode 100755 server/mkrepo.sh create mode 100755 server/mrrepo (limited to 'server') diff --git a/server/mkrepo b/server/mkrepo new file mode 100755 index 0000000..f372d2e --- /dev/null +++ b/server/mkrepo @@ -0,0 +1,73 @@ +#! /usr/bin/env bash + +# Create remote git repository (on the server). You must run this script from +# the "repositories root" (e.g., /var/scm) where you want the repository to be +# created. If the repository is public, also add it to the manifest file (used +# for mirroring). +# +# Usage: mkrepo [] +# +# --private +# make the repository private +# +# Note: is without the .git suffix. +# +trap 'exit 1' ERR + +function error () +{ + echo "$*" 1>&2 +} + +public=y + +while [ $# -gt 0 ]; do + case $1 in + --private) + public=n + shift + ;; + -*) + error "unknown option: $1" + exit 1 + ;; + *) + break + ;; + esac +done + +if [ "$1" = "" ]; then + error "repository name expected" + exit 1 +fi + +r=$1 +if [ `basename $1` = `basename --suffix=.git $1` ]; then + r="$r.git" +fi + +mkdir -p $r +chgrp scm $r +git --bare init --shared=all $r +error "Enter project description (one line; or edit $r/descrition later)" +error "Hit Ctrl-D when done" +cat >$r/description +chgrp -R scm $r + +if [ "$public" = "y" ]; then + f=$r/git-daemon-export-ok + touch $f + chgrp scm $f + chmod g+w $f +else + # Disable raw HTTP access to this directory. + # + echo "deny from all" >$r/.htaccess +fi + +mv $r/hooks/post-update.sample $r/hooks/post-update + +if [ "$public" = "y" ]; then + echo "$r" >>manifest +fi diff --git a/server/mkrepo.sh b/server/mkrepo.sh deleted file mode 100755 index adf48fa..0000000 --- a/server/mkrepo.sh +++ /dev/null @@ -1,63 +0,0 @@ -#! /usr/bin/env bash - -# Create remote git repository (on the server). You must run this script -# from the directory where you want the repository to be created. -# -# Usage: mkrepo.sh [] -# -# --private make the repository private -# -# Note: if without the .git suffix. -# -trap 'exit 1' ERR - -function error () -{ - echo "$*" 1>&2 -} - -public=y - -while [ $# -gt 0 ]; do - case $1 in - --private) - public=n - shift - ;; - -*) - error "unknown option: $1" - exit 1 - ;; - *) - break - ;; - esac -done - -if [ "$1" = "" ]; then - error "repository name expected" - exit 1 -fi - -r=$1.git - -mkdir $r -chgrp scm $r -git --bare init --shared=all $r -error "Enter project description (one line; or edit $r/descrition later)" -error "Hit Ctrl-D when done" -cat >$r/description -chgrp -R scm $r - -if [ "$public" = "y" ]; then - f=$r/git-daemon-export-ok - touch $f - chgrp scm $f - chmod g+w $f -else - # Disable raw HTTP access to this directory. - # - echo "deny from all" >$r/.htaccess -fi - -mv $r/hooks/post-update.sample $r/hooks/post-update diff --git a/server/mrrepo b/server/mrrepo new file mode 100755 index 0000000..1210725 --- /dev/null +++ b/server/mrrepo @@ -0,0 +1,149 @@ +#! /usr/bin/env bash + +# Mirror repositories. For example: +# +# mrrepo -s git.example.org /var/scm +# +# Will first download (via http or https if -s specified) the manifest file +# from git.example.org which should list all publicly available repositories. +# It will then mirror each repository in /var/scm using the git protocol. +# +# -v +# Run verbose. +# +# -s +# Use https rather than http to download the manifest (git protocol is still +# used for mirroring). +# +# Notes: +# - needs curl +# - run from cron as user scm (which belongs to the group scm). +# +usage="usage: $0 [-v] [-s] " + +owd=`pwd` +trap "{ cd $owd; exit 1; }" ERR +set -o errtrace # Trap in functions. + +function info () { echo "$*" 1>&2; } +function error () { info "$*"; exit 1; } + +prot=http +host= +path= +verb=0 + +while [ $# -gt 0 ]; do + case $1 in + -v) + verb=1 + shift + ;; + -s) + prot=https + shift + ;; + *) + if [ -z "$host" ]; then + host=$1 + elif [ -z "$path" ]; then + path=$1 + else + error "$usage" + fi + shift + ;; + esac +done + +if [ -z "$host" -o -z "$path" ]; then + error "$usage" +fi + +if [ ! -d "$path" ]; then + error "$path is not a directory" +fi + +cd $path + +curl_ops="-f" # Fail on HTTP errors. +curl_ops+=" --max-time 10" # Finish in 10 seconds. + +if [ $verb -ge 1 ]; then + curl_ops+=" --progress-bar" +else + curl_ops+=" -s -S" # Silent but show errors. +fi + +function fetch () # [] +{ + local u=$1; shift + + if [ $verb -ge 1 ]; then + info "curl $curl_ops $* $u" + fi + + curl $curl_ops $* $u +} + +fetch $prot://$host/manifest -z manifest -o manifest + +new=() +while read r || [ -n "$r" ]; do + new+=("$r") +done