aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xserver/mkrepo60
-rwxr-xr-xserver/mrrepo93
2 files changed, 76 insertions, 77 deletions
diff --git a/server/mkrepo b/server/mkrepo
index f372d2e..82eaa4a 100755
--- a/server/mkrepo
+++ b/server/mkrepo
@@ -2,34 +2,33 @@
# 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 [<options>] <name>
+# created (including any subdirectories). If the repository is public, also
+# add it to the manifest file (used for mirroring).
#
# --private
# make the repository private
#
# Note: <name> is without the .git suffix.
#
-trap 'exit 1' ERR
+usage="usage: $0 [--private] <name>"
+
+owd="$(pwd)"
+trap "{ cd '$owd'; exit 1; }" ERR
+set -o errtrace # Trap in functions.
-function error ()
-{
- echo "$*" 1>&2
-}
+function info () { echo "$*" 1>&2; }
+function error () { info "$*"; exit 1; }
-public=y
+public="y"
-while [ $# -gt 0 ]; do
- case $1 in
+while [ "$#" -gt "0" ]; do
+ case "$1" in
--private)
- public=n
+ public="n"
shift
;;
-*)
error "unknown option: $1"
- exit 1
;;
*)
break
@@ -37,36 +36,35 @@ while [ $# -gt 0 ]; do
esac
done
-if [ "$1" = "" ]; then
+if [ -z "$1" ]; then
error "repository name expected"
- exit 1
fi
-r=$1
-if [ `basename $1` = `basename --suffix=.git $1` ]; then
+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
+mkdir -p "$r"
+chgrp scm "$r"
+git --bare init --shared=all "$r"
+info "Enter project description (one line; or edit $r/descrition later)"
+info "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
+ 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
+ echo "deny from all" >"$r/.htaccess"
fi
-mv $r/hooks/post-update.sample $r/hooks/post-update
+mv "$r/hooks/post-update.sample" "$r/hooks/post-update"
if [ "$public" = "y" ]; then
echo "$r" >>manifest
diff --git a/server/mrrepo b/server/mrrepo
index 71eff69..91f6966 100755
--- a/server/mrrepo
+++ b/server/mrrepo
@@ -21,35 +21,35 @@
#
usage="usage: $0 [-v] [-s] <host> <path>"
-owd=`pwd`
-trap "{ cd $owd; exit 1; }" ERR
+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
+prot="http"
host=
path=
-verb=0
+verb="0"
-while [ $# -gt 0 ]; do
- case $1 in
+while [ "$#" -gt "0" ]; do
+ case "$1" in
-v)
- verb=1
+ verb="1"
shift
;;
-s)
- prot=https
+ prot="https"
shift
;;
*)
if [ -z "$host" ]; then
- host=$1
+ host="$1"
elif [ -z "$path" ]; then
- path=$1
+ path="${1%/}"
else
- error "$usage"
+ error "$usage"
fi
shift
;;
@@ -64,86 +64,87 @@ if [ ! -d "$path" ]; then
error "$path is not a directory"
fi
-cd $path
+cd "$path"
-curl_ops="-f" # Fail on HTTP errors.
-curl_ops+=" --max-time 30" # Finish in 30 seconds.
+curl_ops=()
+curl_ops+=("-f") # Fail on HTTP errors.
+curl_ops+=("--max-time" "30") # Finish in 30 seconds.
-if [ $verb -ge 1 ]; then
- curl_ops+=" --progress-bar"
+if [ "$verb" -ge "1" ]; then
+ curl_ops+=("--progress-bar")
else
- curl_ops+=" -s -S" # Silent but show errors.
+ curl_ops+=("-s" "-S") # Silent but show errors.
fi
function fetch () # <url> [<curl-options>]
{
- local u=$1; shift
+ local u="$1"; shift
- if [ $verb -ge 1 ]; then
- info "curl $curl_ops $* $u"
+ if [ "$verb" -ge "1" ]; then
+ info "${curl_ops[@]}" "$@" "$u"
fi
- curl $curl_ops $* $u
+ curl "${curl_ops[@]}" "$@" "$u"
}
-fetch $prot://$host/manifest -z manifest -o manifest
+fetch "$prot://$host/manifest" -z manifest -o manifest
new=()
while read r || [ -n "$r" ]; do
new+=("$r")
done <manifest
-# Find all existing repositories (directories that end with .git).
+# Find all the existing repositories (directories that end with .git).
#
-old=(`find . -type d -name '*.git' -print -prune | sed -e 's%^./%%' -`)
+old=("$(find . -type d -name '*.git' -print -prune | sed -e 's%^./%%' -)")
-git_ops=
-if [ $verb -eq 0 ]; then
- git_ops+="-q"
+git_ops=()
+if [ "$verb" -eq "0" ]; then
+ git_ops+=("-q")
fi
-for r in ${new[@]}; do
- if [ -d $r ]; then
- if [ -z "$(ls -A $r)" ]; then
- rm -r $r
+for r in "${new[@]}"; do
+ if [ -d "$r" ]; then
+ if [ -z "$(ls -A "$r")" ]; then
+ rm -r "$r"
fi
fi
- if [ ! -d $r ]; then
- if [ $verb -ge 1 ]; then
+ if [ ! -d "$r" ]; then
+ if [ "$verb" -ge "1" ]; then
info "new repository $r in manifest, cloning"
- info "git clone $git_ops --mirror git://$host/$r $r"
+ info git clone "${git_ops[@]}" --mirror "git://$host/$r" "$r"
fi
- mkdir -p $r
- git clone $git_ops --mirror git://$host/$r $r
+ mkdir -p "$r"
+ git clone "${git_ops[@]}" --mirror "git://$host/$r" "$r"
# Also copy the description file.
#
- fetch $prot://$host/$r/description -o $r/description
+ fetch "$prot://$host/$r/description" -o "$r/description"
else
- if [ $verb -ge 1 ]; then
+ if [ "$verb" -ge "1" ]; then
info "existing repository $r, fetching"
- info "git -C $r fetch $git_ops --tags"
+ info git -C "$r" fetch "${git_ops[@]}" --prune --tags
fi
- git -C $r fetch $git_ops --prune --tags
+ git -C "$r" fetch "${git_ops[@]}" --prune --tags
fi
done
# Remove old repositories.
#
-for o in ${old[@]}; do
- for n in ${new[@]}; do
- if [ $o = $n ]; then
+for o in "${old[@]}"; do
+ for n in "${new[@]}"; do
+ if [ "$o" = "$n" ]; then
o=
break
fi
done
if [ -n "$o" ]; then
- if [ $verb -ge 1 ]; then
+ if [ "$verb" -ge "1" ]; then
info "repository $o is no longer in manifest, removing"
fi
- rm -rf $o
+ rm -rf "$o"
fi
done
-cd $owd
+cd "$owd"