aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2022-08-31 17:01:18 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2022-09-01 19:36:42 +0300
commit144385cd9b6046e6236041f96586175ae12a19c7 (patch)
tree223b42f16ae2c5fc6d2d43d408131d94b1c26bae
parent97d33a602e4c0b5a65ac36543e22f2fddb7ecdbc (diff)
Make host argument optional for mrrepo scriptHEADmaster
-rwxr-xr-xserver/mrrepo71
1 files changed, 44 insertions, 27 deletions
diff --git a/server/mrrepo b/server/mrrepo
index 1bb3989..469a03f 100755
--- a/server/mrrepo
+++ b/server/mrrepo
@@ -40,7 +40,7 @@
#
# runuser -u scm -- /var/scm/mrrepo -s -v git.example.org /var/scm
#
-usage="usage: $0 [-v] [-s] <host> <path>"
+usage="usage: $0 [-v] [-s] [<host>] <path>"
owd="$(pwd)"
trap "{ cd '$owd'; exit 1; }" ERR
@@ -65,19 +65,34 @@ while [ "$#" -gt 0 ]; do
shift
;;
*)
- if [ -z "$host" ]; then
- host="$1"
- elif [ -z "$path" ]; then
- path="${1%/}"
- else
- error "$usage"
- fi
- shift
+ break; # The end of options is encountered.
;;
esac
done
-if [ -z "$host" -o -z "$path" ]; then
+# Parse the command line arguments.
+#
+if [ "$#" -lt 1 -o "$#" -gt 2 ]; then
+ error "$usage"
+fi
+
+# Host.
+#
+if [ "$#" -gt 1 ]; then
+ host="$1"
+ shift
+
+ if [ -z "$host" ]; then
+ error "$usage"
+ fi
+fi
+
+# Repositories directory.
+#
+path="${1%/}"
+shift
+
+if [ -z "$path" ]; then
error "$usage"
fi
@@ -121,8 +136,6 @@ function fetch () # <url> [<curl-options>]
curl "${curl_ops[@]}" "$@" "$u"
}
-fetch "$prot://$host/manifest" -z remote.manifest -o remote.manifest
-
function manifest_filter () # <file>
{
sed -e '/^\s*#/d;/^\s*$/d;s/\s\s*/ /g' "$1"
@@ -169,18 +182,22 @@ function push_add () # <rep> <url>
push_auth["$r"]="$u"
}
-while read l || [ -n "$l" ]; do
- r=$(manifest_field "$l" 1 'path')
- u=$(manifest_field "$l" 2)
+if [ -n "$host" ]; then
+ fetch "$prot://$host/manifest" -z remote.manifest -o remote.manifest
- remote+=("$r")
+ while read l || [ -n "$l" ]; do
+ r=$(manifest_field "$l" 1 'path')
+ u=$(manifest_field "$l" 2)
- # If the push URL is specified then add it to auth/orig maps.
- #
- if [ -n "$u" ]; then
- push_add "$r" "$u"
- fi
-done < <(manifest_filter remote.manifest)
+ remote+=("$r")
+
+ # If the push URL is specified then add it to auth/orig maps.
+ #
+ if [ -n "$u" ]; then
+ push_add "$r" "$u"
+ fi
+ done < <(manifest_filter remote.manifest)
+fi
# Find all the existing repositories (directories that end with .git) and sort
# them out into mirrored and local public. Note that local private will end up
@@ -202,7 +219,7 @@ if test -f manifest; then
for i in "${remote[@]}"; do
if [ "$i" = "$r" ]; then
- error "attempt to mirror into local public repository $r"
+ error "attempt to mirror into local public repository $r"
fi
done
@@ -222,10 +239,10 @@ if test -f manifest; then
for i in "${local[@]}"; do
if [ "$i" = "$r" ]; then
if [ "$verb" -ge 1 ]; then
- info "local public repository $r"
- fi
- r=
- break
+ info "local public repository $r"
+ fi
+ r=
+ break
fi
done