From 19ff8ac28a266b60d28cf3d9cf7464ac79836480 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 17 Oct 2016 17:25:09 +0200 Subject: Cleanup mkrepo, mrrepo scripts --- server/mrrepo | 93 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 46 deletions(-) (limited to 'server/mrrepo') 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] " -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 () # [] { - 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