From d9c8f960ccc2091526982924734d9dd8061d777d Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 17 Nov 2017 18:26:41 -0800 Subject: [PATCH] scripts: purge use of test '-a' and '-o' ops and clean up Although the test utility's '-a' and '-o' operators are documented by POSIX, they are marked obsolete and may not be supported by some implementations. Furthermore, the semantics (i.e. precedence and order of evaluation) are not well defined when they are in use. Therefore expunge use of them in favor of multiple tests combined with '||' and/or '&&'. At the same time clean up the scripts by removing all extraneous '\' and other oddities to make the scripts a bit more stylistically consistent. Also correct a few minor anomalies noticed in the process. Signed-off-by: Kyle J. McKay --- bin/create-personal-mob-area | 37 ++++--- bin/format-readme | 40 ++++---- bin/git-daemon-verify | 6 +- bin/git-http-backend-verify | 86 ++++++---------- bin/git-shell-verify | 16 +-- bin/update-pwd-db | 4 +- cgi/authrequired.cgi | 6 +- cgi/snapshot.cgi | 28 ++---- chrootsetup_dragonfly.sh | 29 +++--- chrootsetup_freebsd.sh | 27 ++--- chrootsetup_linux.sh | 22 +++-- gitweb/genindex.sh | 12 ++- hooks/post-receive | 8 +- hooks/pre-receive | 4 +- hooks/update | 20 ++-- install.sh | 176 +++++++++++++++++---------------- jailsetup.sh | 44 ++++----- jobd/combine-packs.sh | 67 ++++++++----- jobd/gc.sh | 94 +++++++++--------- jobd/jobd.sh | 1 - jobd/update.sh | 43 ++++---- jobs/gitwebcache.sh | 14 ++- jobs/updateweb.sh | 30 +++--- make-apache-conf.sh | 2 +- shlib.sh | 68 ++++++------- taskd/clone.sh | 53 +++++----- taskd/mail.sh | 140 +++++++++++++------------- toolbox/backup-db.sh | 24 ++--- toolbox/clear-all-htmlcache.sh | 2 +- toolbox/edit-user-email.sh | 10 +- toolbox/make-all-gc-eligible.sh | 2 +- toolbox/perform-pre-gc-linking.sh | 20 ++-- toolbox/project-changed.sh | 2 +- toolbox/remove-user.sh | 8 +- toolbox/reports/project-disk-use.sh | 20 ++-- toolbox/reports/project-fsck-status.sh | 16 +-- toolbox/update-all-config.sh | 50 +++++----- toolbox/update-all-hooks.sh | 22 ++--- toolbox/update-all-projects.sh | 6 +- toolbox/updatecheck.sh | 12 +-- 40 files changed, 645 insertions(+), 626 deletions(-) diff --git a/bin/create-personal-mob-area b/bin/create-personal-mob-area index 94c13bf..396373a 100755 --- a/bin/create-personal-mob-area +++ b/bin/create-personal-mob-area @@ -12,11 +12,20 @@ proj="$1" [ -f "$cfg_reporoot/$proj.git/.nofetch" ] || { echo "Mirrors may not use mob: $1" >&2; exit 1; } projdir="$cfg_reporoot/$proj.git" -if [ ! -f "$projdir/HEAD" -o ! -f "$projdir/config" -o ! -f "$projdir/description" ] || - [ ! -f "$projdir/hooks/pre-receive" -o ! -x "$projdir/hooks/pre-receive" ] || - [ ! -f "$projdir/hooks/post-receive" -o ! -x "$projdir/hooks/post-receive" ] || - [ ! -f "$projdir/hooks/update" -o ! -x "$projdir/hooks/update" ] || - [ ! -d "$projdir/objects" -o ! -d "$projdir/info" -o -L "$projdir/HEAD" ]; then +if + [ -L "$projdir/HEAD" ] || + ! [ -f "$projdir/HEAD" ] || + ! [ -f "$projdir/config" ] || + ! [ -f "$projdir/description" ] || + ! [ -f "$projdir/hooks/pre-receive" ] || + ! [ -x "$projdir/hooks/pre-receive" ] || + ! [ -f "$projdir/hooks/post-receive" ] || + ! [ -x "$projdir/hooks/post-receive" ] || + ! [ -f "$projdir/hooks/update" ] || + ! [ -x "$projdir/hooks/update" ] || + ! [ -d "$projdir/objects" ] || + ! [ -d "$projdir/info" ] +then echo "Incorrectly set up project: $1" >&2 exit 1 fi @@ -35,26 +44,26 @@ chmod 02775 "$projdir/refs" "$projdir/refs/mob" \ for hook in pre-receive post-receive; do if ! [ -x "$projdir/mob/hooks/$hook" ]; then - write_mob_hook "$hook" > "$projdir/mob/hooks/$hook" + write_mob_hook "$hook" >"$projdir/mob/hooks/$hook" chmod 0775 "$projdir/mob/hooks/$hook" fi done [ -x "$projdir/mob/hooks/update" ] || ln -sfn ../../hooks/update "$projdir/mob/hooks/update" -[ -d "$projdir/mob/refs/heads" ] || ln -sfn ../../refs/mob "$projdir/mob/refs/heads" -[ -d "$projdir/mob/refs/mob" ] || ln -sfn ../../refs/mob "$projdir/mob/refs/mob" +[ -d "$projdir/mob/refs/heads" ] || ln -sfn ../../refs/mob "$projdir/mob/refs/heads" +[ -d "$projdir/mob/refs/mob" ] || ln -sfn ../../refs/mob "$projdir/mob/refs/mob" -[ -L "$projdir/mob/packed-refs" ] || ln -sfn ../packed-refs.mob "$projdir/mob/packed-refs" -[ -d "$projdir/mob/objects" ] || ln -sfn ../objects "$projdir/mob/objects" -[ -d "$projdir/mob/info" ] || ln -sfn ../info "$projdir/mob/info" -[ -f "$projdir/mob/description" ] || ln -sfn ../description "$projdir/mob/description" -[ -f "$projdir/mob/config" ] || ln -sfn ../config "$projdir/mob/config" +[ -L "$projdir/mob/packed-refs" ] || ln -sfn ../packed-refs.mob "$projdir/mob/packed-refs" +[ -d "$projdir/mob/objects" ] || ln -sfn ../objects "$projdir/mob/objects" +[ -d "$projdir/mob/info" ] || ln -sfn ../info "$projdir/mob/info" +[ -f "$projdir/mob/description" ] || ln -sfn ../description "$projdir/mob/description" +[ -f "$projdir/mob/config" ] || ln -sfn ../config "$projdir/mob/config" cp -p -f "$projdir/HEAD" "$projdir/mob/HEAD.$$" mv -f "$projdir/mob/HEAD.$$" "$projdir/mob/HEAD" rm -f "$projdir/mob/HEAD.$$" -git --git-dir="$projdir" for-each-ref --format='%(objectname) %(refname)' > "$projdir/packed-refs.mob.$$" || : +git --git-dir="$projdir" for-each-ref --format='%(objectname) %(refname)' >"$projdir/packed-refs.mob.$$" || : if [ -s "$projdir/packed-refs.mob.$$" ]; then mv -f "$projdir/packed-refs.mob.$$" "$projdir/packed-refs.mob" fi diff --git a/bin/format-readme b/bin/format-readme index 603abd6..feae721 100755 --- a/bin/format-readme +++ b/bin/format-readme @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Version 1.2.6 +# Version 1.2.7 # Usage: format-readme [-r | -p [ -i [] @@ -34,15 +34,15 @@ set -e -nl="$(printf '\n*')" -nl="${nl%?}" +nl=' +' symlinks= addprefix= addpath= urlprefix= imgprefix= -if [ "$1" = "-r" -o "$1" = "-p" ]; then +if [ "$1" = "-r" ] || [ "$1" = "-p" ]; then addprefix=1 [ "$1" != "-p" ] || addpath=1 shift @@ -57,7 +57,7 @@ if [ "$1" = "-r" -o "$1" = "-p" ]; then fi fi projdir="$1" -[ -n "$projdir" -a -d "$projdir" ] || exit 2 +[ -n "$projdir" ] && [ -d "$projdir" ] || exit 2 cd "$projdir" || exit 2 unset GIT_DIR gd="$(git rev-parse --git-dir 2>&1)" || exit 2 @@ -87,10 +87,10 @@ readmeextnm= readmeextlnk= readmeextfmt= while read -r mode type hash size name; do - [ "$mode" = "100644" -o "$mode" = "100755" -o "$mode" = "120000" ] || continue - [ "$size" != "0" -a "$size" != "-" ] || continue + [ "$mode" = "100644" ] || [ "$mode" = "100755" ] || [ "$mode" = "120000" ] || continue + [ "$size" != "0" ] && [ "$size" != "-" ] || continue [ "$type" = "blob" ] || continue - [ "$mode" != "120000" -o "$size" -lt 1024 ] || continue + [ "$mode" != "120000" ] || [ "$size" -lt 1024 ] || continue [ "$mode" != "120000" ] || symlinks="$symlinks$hash $name$nl" case "$name" in @@ -105,7 +105,7 @@ while read -r mode type hash size name; do [Rr][Ee][Aa][Dd][Mm][Ee].[Mm][Aa][Rr][Kk][Dd][Oo][Ww][Nn]|\ [Rr][Ee][Aa][Dd][Mm][Ee].[Ll][Ii][Tt][Cc][Oo][Ff][Ff][Ee][Ee]) if [ -n "$readmeext" ]; then - [ "$readmeextfmt" != "md" -o "$mode" != "120000" ] || continue + [ "$readmeextfmt" != "md" ] || [ "$mode" != "120000" ] || continue fi readmeext="$hash" readmeextnm="$name" @@ -118,7 +118,7 @@ while read -r mode type hash size name; do [ -n "$haspod" ] || continue if [ -n "$readmeext" ]; then [ "$readmeextfmt" != "md" ] || continue - [ "$readmeextfmt" = "txt" -o "$mode" != "120000" ] || continue + [ "$readmeextfmt" = "txt" ] || [ "$mode" != "120000" ] || continue fi readmeext="$hash" readmeextnm="$name" @@ -130,7 +130,7 @@ while read -r mode type hash size name; do [Rr][Ee][Aa][Dd][Mm][Ee].[Tt][Xx][Tt]|\ [Rr][Ee][Aa][Dd][Mm][Ee].[Tt][Ee][Xx][Tt]) if [ -n "$readmeext" ]; then - [ "$readmeextfmt" = "txt" -a "$mode" != "120000" ] || continue + [ "$readmeextfmt" = "txt" ] && [ "$mode" != "120000" ] || continue fi readmeext="$hash" readmeextnm="$name" @@ -140,7 +140,7 @@ while read -r mode type hash size name; do ;; [Rr][Ee][Aa][Dd][Mm][Ee]) - [ -z "$readme" -o "$mode" != "120000" ] || continue + [ -z "$readme" ] || [ "$mode" != "120000" ] || continue readme="$hash" readmenm="$name" readmelnk= @@ -148,7 +148,7 @@ while read -r mode type hash size name; do ;; [Rr][Ee][Aa][Dd][Mm][Ee].?*) - [ -z "$readmefb" -o "$mode" != "120000" ] || continue + [ -z "$readmefb" ] || [ "$mode" != "120000" ] || continue [ "${name%.*}" = "${name%%.*}" ] || continue [ "${name#*.}" = "${name##*[!A-Za-z0-9+_]}" ] || continue [ "${name%[$ws]*}" = "$name" ] || continue @@ -162,12 +162,12 @@ while read -r mode type hash size name; do done < 32K [ "$size" -le 32768 ] || exit 1 readmeext="$hash" @@ -258,7 +258,7 @@ case "$readmeextfmt" in pod) # Run pod2html and extract the contents arg= - if [ -n "$addprefix" -a -n "${urlprefix%/}" ]; then + if [ -n "$addprefix" ] && [ -n "${urlprefix%/}" ]; then arg=", \"--htmlroot=${urlprefix%/}\"" fi printf '\n' "$readmeextnm" diff --git a/bin/git-daemon-verify b/bin/git-daemon-verify index 915e2d9..bfeb41c 100755 --- a/bin/git-daemon-verify +++ b/bin/git-daemon-verify @@ -20,7 +20,7 @@ if [ -n "$defined_cfg_git_server_ua" ]; then fi [ -z "$GIT_DAEMON_BIN" ] || cfg_git_daemon_bin="$GIT_DAEMON_BIN" -[ -n "$cfg_git_daemon_bin" ] || \ +[ -n "$cfg_git_daemon_bin" ] || cfg_git_daemon_bin="$var_git_exec_path/git-daemon" errormsg() @@ -46,7 +46,7 @@ denied() internalerr() { - echo "git-daemon-verify: $*" >&2 + printf '%s\n' "git-daemon-verify: $*" >&2 errormsg "internal server error" } @@ -138,7 +138,7 @@ if ! [ -d "$dir" ] || ! [ -f "$dir/HEAD" ] || ! [ -d "$dir/objects" ]; then exit 1 fi -[ -z "$var_upload_window" ] || [ "$type" != "upload-pack" ] || \ +[ -z "$var_upload_window" ] || [ "$type" != "upload-pack" ] || git_add_config "pack.window=$var_upload_window" exec "$cfg_git_daemon_bin" --inetd --verbose --export-all --enable=upload-archive --base-path="$cfg_reporoot" diff --git a/bin/git-http-backend-verify b/bin/git-http-backend-verify index 11cdc99..61ec3cf 100755 --- a/bin/git-http-backend-verify +++ b/bin/git-http-backend-verify @@ -29,7 +29,7 @@ if [ -n "$defined_cfg_git_server_ua" ]; then GIT_HTTP_USER_AGENT="$cfg_git_server_ua" export GIT_HTTP_USER_AGENT fi -if [ -n "$cfg_SmartHTTPOnly" -a "$cfg_SmartHTTPOnly" != "0" ]; then +if [ -n "$cfg_SmartHTTPOnly" ] && [ "$cfg_SmartHTTPOnly" != "0" ]; then git_add_config "http.getanyfile=false" fi @@ -80,58 +80,39 @@ errorhdrs() msglines() { - while [ $# -gt 0 ]; do - printf '%s\n' "$1" - shift - done + [ $# -le 0 ] || printf '%s\n' "$@" } internalerr() { errorhdrs 500 "Internal Server Error" - if [ $# -eq 0 ]; then - msglines "Internal Server Error" - echo "Internal Server Error" >&2 - else - msglines "$@" - while [ $# -gt 0 ]; do - printf '%s\n' "$1" >&2 - shift - done - fi + [ $# -gt 0 ] || set -- "Internal Server Error" + msglines "$@" >&2 + msglines "$@" exit 0 } methodnotallowed() { errorhdrs 405 "Method Not Allowed" "Allow: GET,HEAD,POST" - if [ $# -eq 0 ]; then - msglines "Method Not Allowed" - else - msglines "$@" - fi + [ $# -gt 0 ] || set -- "Method Not Allowed" + msglines "$@" exit 0 } forbidden() { errorhdrs 403 Forbidden - if [ $# -eq 0 ]; then - msglines "Forbidden" - else - msglines "$@" - fi + [ $# -gt 0 ] || set -- "Forbidden" + msglines "$@" exit 0 } notfound() { errorhdrs 404 "Not Found" - if [ $# -eq 0 ]; then - msglines "Not Found" - else - msglines "$@" - fi + [ $# -gt 0 ] || set -- "Not Found" + msglines "$@" exit 0 } @@ -146,11 +127,8 @@ needsauth() exec "$cfg_cgiroot/authrequired.cgi" || : # fallback in case exec fails errorhdrs 401 "Authorization Required" - if [ $# -eq 0 ]; then - msglines "Authorization Required" - else - msglines "$@" - fi + [ $# -gt 0 ] || set -- "Authorization Required" + msglines "$@" exit 0 } @@ -168,8 +146,8 @@ redir() _loc="https" [ "$HTTPS" = "on" ] || _loc="http" _loc="$_loc://$SERVER_NAME" - [ "$HTTPS" != "on" -o "$SERVER_PORT" = "443" ] || _loc="$_loc:$SERVER_PORT" - [ "$HTTPS" = "on" -o "$SERVER_PORT" = "80" ] || _loc="$_loc:$SERVER_PORT" + [ "$HTTPS" != "on" ] || [ "$SERVER_PORT" = "443" ] || _loc="$_loc:$SERVER_PORT" + [ "$HTTPS" = "on" ] || [ "$SERVER_PORT" = "80" ] || _loc="$_loc:$SERVER_PORT" _loc="$_loc$_absbase" case "$1" in /*) :;; *) _loc="$_loc/";; esac _loc="$_loc$1" @@ -204,7 +182,7 @@ bundle= suffix= needsauthcheck= pathcheck="${PATH_INFO#/}" -if [ "$REQUEST_METHOD" = "GET" -o "$REQUEST_METHOD" = "HEAD" ]; then +if [ "$REQUEST_METHOD" = "GET" ] || [ "$REQUEST_METHOD" = "HEAD" ]; then # We do not currently validate non-smart GET/HEAD requests. # There are only 8 possible suffix values that need to be allowed for # non-smart HTTP GET/HEAD fetches (see http-backend.c): @@ -322,7 +300,7 @@ if [ -n "$bundle" ]; then # A bundles/latest symlink must exist and # point to an existing file in the same directory # matching the magic format (\d{8}_\d{6}-$octet4) - if ! [ -L "$dir/bundles/latest" -a -f "$dir/bundles/latest" ]; then + if ! [ -L "$dir/bundles/latest" ] || ! [ -f "$dir/bundles/latest" ]; then notfound exit 0 fi @@ -337,7 +315,7 @@ if [ -n "$bundle" ]; then bundleid="${suffix%.bundle}" bundleid="${bundleid##*-}" bundlepat="${digit8}_$digit6-$bundleid" - bundlefile="$(echo "$dir/bundles/"$bundlepat 2>/dev/null || :)" + bundlefile="$(printf '%s\n' "$dir/bundles/"$bundlepat 2>/dev/null)" || : if [ "$dir/bundles/$bundlepat" = "$bundlefile" ] || ! [ -f "$bundlefile" ]; then notfound exit 0 @@ -346,8 +324,8 @@ if [ -n "$bundle" ]; then { { read -r bundlehdr || : read -r bundlepck || : - } <"$bundlefile"; } 2>/dev/null - [ -n "$bundlehdr" -a -n "$bundlepck" ] || { notfound; exit 0; } + } <"$bundlefile"; } 2>/dev/null || : + [ -n "$bundlehdr" ] && [ -n "$bundlepck" ] || { notfound; exit 0; } # Non-absolute paths are relative to the repository's objects/pack dir case "$bundlehdr" in /*) :;; *) bundlehdr="$dir/objects/pack/$bundlehdr" @@ -355,8 +333,8 @@ if [ -n "$bundle" ]; then case "$bundlepck" in /*) :;; *) bundlepck="$dir/objects/pack/$bundlepck" esac - [ -f "$bundlehdr" -a -f "$bundlepck" ] || { notfound; exit 0; } - [ -s "$bundlehdr" -o -s "$bundlepck" ] || { notfound; exit 0; } + [ -f "$bundlehdr" ] && [ -f "$bundlepck" ] || { notfound; exit 0; } + [ -s "$bundlehdr" ] || [ -s "$bundlepck" ] || { notfound; exit 0; } [ -z "$isredir" ] || { redir "/$proj/$linked.bundle"; exit 0; } exec "$cfg_basedir/bin/rangecgi" -c 'application/x-git-bundle' -e 180 \ -m 1 "$bundlehdr" "$bundlepck" @@ -365,7 +343,7 @@ if [ -n "$bundle" ]; then fi if [ -z "$needsauthcheck" ] || [ -z "$smart" ]; then - [ -z "$var_upload_window" ] || [ -z "$smart" ] || \ + [ -z "$var_upload_window" ] || [ -z "$smart" ] || git_add_config "pack.window=$var_upload_window" if [ -n "$GIT_HTTP_BACKEND_SHOW_ERRORS" ]; then exec "$cfg_git_http_backend_bin" "$@" @@ -391,7 +369,7 @@ if [ "${SSL_CLIENT_VERIFY+set}" = "set" ] && [ "$SSL_CLIENT_VERIFY" != "SUCCESS" exit 1 fi authuser="${REMOTE_USER#/UID=}" -authuuid="${authuser}" +authuuid="$authuser" authuser="${authuser%/dnQualifier=*}" authuuid="${authuuid#$authuser}" authuuid="${authuuid#/dnQualifier=}" @@ -399,7 +377,7 @@ if [ -z "$authuser" ]; then needsauth "Only authenticated users may push, sorry." exit 1 fi -if [ "$authuser" != "mob" -o "$cfg_mob" != "mob" ]; then +if [ "$authuser" != "mob" ] || [ "$cfg_mob" != "mob" ]; then if ! useruuid="$("$cfg_basedir/bin/get_user_uuid" "$authuser")" || [ "$useruuid" != "$authuuid" ]; then forbidden "The user '$authuser' certificate being used is no longer valid." \ "You may download a new user certificate at $cfg_webadmurl/edituser.cgi" @@ -411,13 +389,13 @@ if ! "$cfg_basedir/bin/can_user_push_http" "$projbare" "$authuser"; then # If mob is enabled and mob has push permissions and # the current user is not the mob then it's a personal mob push # presuming the special mob directory has been set up - if [ "$cfg_mob" = "mob" -a "$authuser" != "mob" -a -d "$cfg_reporoot/$proj/mob" ] && + if [ "$cfg_mob" = "mob" ] && [ "$authuser" != "mob" ] && [ -d "$cfg_reporoot/$proj/mob" ] && "$cfg_basedir/bin/can_user_push_http" "$projbare" "mob"; then ( umask 113 - > "$cfg_chroot/etc/sshactive/${authuser}," - mv -f "$cfg_chroot/etc/sshactive/${authuser}," "$cfg_chroot/etc/sshactive/${authuser}" - ! [ -e "$dir/.delaygc" ] || > "$dir/.allowgc" || : + >"$cfg_chroot/etc/sshactive/$authuser," + mv -f "$cfg_chroot/etc/sshactive/$authuser," "$cfg_chroot/etc/sshactive/$authuser" + ! [ -e "$dir/.delaygc" ] || >"$dir/.allowgc" || : ) PATH_INFO="/$proj/mob/$suffix" export PATH_INFO @@ -436,9 +414,9 @@ fi ( umask 113 - > "$cfg_chroot/etc/sshactive/${authuser}," - mv -f "$cfg_chroot/etc/sshactive/${authuser}," "$cfg_chroot/etc/sshactive/${authuser}" - ! [ -e "$dir/.delaygc" ] || > "$dir/.allowgc" || : + >"$cfg_chroot/etc/sshactive/$authuser," + mv -f "$cfg_chroot/etc/sshactive/$authuser," "$cfg_chroot/etc/sshactive/$authuser" + ! [ -e "$dir/.delaygc" ] || >"$dir/.allowgc" || : ) if [ -n "$GIT_HTTP_BACKEND_SHOW_ERRORS" ]; then exec "$cfg_git_http_backend_bin" "$@" diff --git a/bin/git-shell-verify b/bin/git-shell-verify index 91815ac..f75b6ad 100755 --- a/bin/git-shell-verify +++ b/bin/git-shell-verify @@ -209,13 +209,13 @@ if ! [ -x @perlbin@ ] && [ "$type" = 'receive-pack' ]; then # If mob is enabled and mob has push permissions and # the current user is not the mob then it's a personal mob push # presuming the special mob directory has been set up - if [ "$mob" = "mob" -a "$LOGNAME" != "mob" -a -d "$reporoot/$proj/mob" ] && + if [ "$mob" = "mob" ] && [ "$LOGNAME" != "mob" ] && [ -d "$reporoot/$proj/mob" ] && can_user_push "$projbare" mob; then ( umask 113 - > "/etc/sshactive/${LOGNAME}," - mv -f "/etc/sshactive/${LOGNAME}," "/etc/sshactive/${LOGNAME}" - ! [ -e "$dir/.delaygc" ] || > "$dir/.allowgc" || : + >"/etc/sshactive/$LOGNAME," + mv -f "/etc/sshactive/$LOGNAME," "/etc/sshactive/$LOGNAME" + ! [ -e "$dir/.delaygc" ] || >"$dir/.allowgc" || : ) exec git-shell -c "git-receive-pack '$reporoot/$proj/mob'" exit 1 @@ -226,13 +226,13 @@ if ! [ -x @perlbin@ ] && [ "$type" = 'receive-pack' ]; then fi ( umask 113 - > "/etc/sshactive/${LOGNAME}," - mv -f "/etc/sshactive/${LOGNAME}," "/etc/sshactive/${LOGNAME}" - ! [ -e "$dir/.delaygc" ] || > "$dir/.allowgc" || : + >"/etc/sshactive/$LOGNAME," + mv -f "/etc/sshactive/$LOGNAME," "/etc/sshactive/$LOGNAME" + ! [ -e "$dir/.delaygc" ] || >"$dir/.allowgc" || : ) fi -[ -z "$var_upload_window" ] || [ "$type" != "upload-pack" ] || \ +[ -z "$var_upload_window" ] || [ "$type" != "upload-pack" ] || git_add_config "pack.window=$var_upload_window" exec git-shell -c "git-$type '$dir'" diff --git a/bin/update-pwd-db b/bin/update-pwd-db index 4e3914a..91e3f2a 100755 --- a/bin/update-pwd-db +++ b/bin/update-pwd-db @@ -20,7 +20,7 @@ set -e # user - optionally passed. If passed then the only # change to file involves the username 'user'. -[ -n "$1" -a -r "$1" ] || { echo "update-pwd-db: error: no such passwd file: $1" >&2; exit 2; } +[ -n "$1" ] && [ -r "$1" ] || { echo "update-pwd-db: error: no such passwd file: $1" >&2; exit 2; } cd "$cfg_chroot" user_only= [ -z "$2" ] || user_only="-u $2" @@ -30,6 +30,6 @@ cleanup() { } >/dev/null 2>&1 trap cleanup EXIT rm -f etc/master.passwd -awk -F ':' '{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }' < "$1" > etc/master.passwd +awk -F ':' '{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }' <"$1" >etc/master.passwd PW_SCAN_BIG_IDS=1 pwd_mkdb -d etc $user_only etc/master.passwd 2>/dev/null exit 0 diff --git a/cgi/authrequired.cgi b/cgi/authrequired.cgi index 284fd33..4f695fb 100755 --- a/cgi/authrequired.cgi +++ b/cgi/authrequired.cgi @@ -1,7 +1,7 @@ #!/bin/sh # authrequired.cgi -- show certification authorization instructions on 401 -# Copyright (C) 2014,2016 Kyle J. McKay. All rights reserved. +# Copyright (C) 2014,2016,2017 Kyle J. McKay. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# Version 1.3 +# Version 1.3.1 # We pretend like we don't exist. Unless this was an attempt to access a push # URL over HTTP/HTTPS in which case we return a suitable error message. @@ -148,7 +148,7 @@ of your private key (see the above page). ====================================================================== " -if [ -n "$isoldgit" -a -n "$service" ]; then +if [ -n "$isoldgit" ] && [ -n "$service" ]; then l1=$(( 15 + ${#service} )) l2=$(( 9 + ${#message} )) headers 200 "application/x-$service-advertisement" \ diff --git a/cgi/snapshot.cgi b/cgi/snapshot.cgi index c16bedd..ef9acc3 100755 --- a/cgi/snapshot.cgi +++ b/cgi/snapshot.cgi @@ -1,7 +1,7 @@ #!/bin/sh # snapshot.cgi -- throttle snapshot requests -# Copyright (C) 2015 Kyle J. McKay. All rights reserved. +# Copyright (C) 2015,2017 Kyle J. McKay. All rights reserved. # License GPLv2+: GNU GPL version 2 or later. # www.gnu.org/licenses/gpl-2.0.html # This is free software: you are free to change and redistribute it. @@ -47,42 +47,30 @@ errorhdrs() msglines() { - while [ $# -gt 0 ]; do - printf '%s\n' "$1" - shift - done + [ $# -le 0 ] || printf '%s\n' "$@" } methodnotallowed() { errorhdrs 405 "Method Not Allowed" "Allow: GET" - if [ $# -eq 0 ]; then - msglines "Method Not Allowed" - else - msglines "$@" - fi + [ $# -gt 0 ] || set -- "Method Not Allowed" + msglines "$@" exit 0 } forbidden() { errorhdrs 403 Forbidden - if [ $# -eq 0 ]; then - msglines "Forbidden" - else - msglines "$@" - fi + [ $# -gt 0 ] || set -- "Forbidden" + msglines "$@" exit 0 } notfound() { errorhdrs 404 "Not Found" - if [ $# -eq 0 ]; then - msglines "Not Found" - else - msglines "$@" - fi + [ $# -gt 0 ] || set -- "Not Found" + msglines "$@" exit 0 } diff --git a/chrootsetup_dragonfly.sh b/chrootsetup_dragonfly.sh index b7b04bf..58f9120 100644 --- a/chrootsetup_dragonfly.sh +++ b/chrootsetup_dragonfly.sh @@ -15,19 +15,19 @@ # Finally this script must install a suitable nc.openbsd compatible version of # netcat into the chroot jail that's available as nc.openbsd and which supports -# connects to unix sockets. +# connections to unix sockets. # We are designed to set up the chroot based on binaries from # x86_64 DragonFly BSD 4.4; some things may need slight modifications if # being run on a different distribution. # We require update_pwd_db to be set to work properly on DragonFly BSD -[ -n "$cfg_update_pwd_db" -a "$cfg_update_pwd_db" != "0" ] || { +[ -n "$cfg_update_pwd_db" ] && [ "$cfg_update_pwd_db" != "0" ] || { echo 'error: Config.pm must set $update_pwd_db to 1 to use a DragonFly BSD jail' >&2 exit 1 } -chroot_dir="`pwd`" +chroot_dir="$(pwd)" mkdir -p dev proc chown 0:0 dev proc @@ -37,13 +37,13 @@ mkdir -p libexec var/tmp # Install the devfsctl chroot ruleset rm -f etc/devfs.conf -cat "$curdir/fstab/devfsctl_chroot_ruleset" > etc/devfs.conf +cat "$curdir/fstab/devfsctl_chroot_ruleset" >etc/devfs.conf chown 0:0 etc/devfs.conf chmod 0444 etc/devfs.conf # Make sure there's an auth.conf file, empty is fine if ! [ -e etc/auth.conf ]; then - > etc/auth.conf + >etc/auth.conf chown 0:0 etc/auth.conf chmod 0444 etc/auth.conf fi @@ -51,8 +51,10 @@ fi cp_p() { # use cpio to avoid setting flags # must NOT use passthrough mode as that will set flags on newer systems - (cd "$(dirname "$1")" && echo "$(basename "$1")" | \ - cpio -o -L 2>/dev/null| { cd "$chroot_dir/${2%/*}" && cpio -i -m -u; } 2>/dev/null) + [ "$2" = "${2%/}/" ] || ! [ -d "$chroot_dir/$2" ] || set -- "$1" "$2/" + (cd "$(dirname "$1")" && echo "$(basename "$1")" | + cpio -o -L 2>/dev/null | { cd "$chroot_dir/${2%/*}" && cpio -i -m -u; } 2>/dev/null) + test $? -eq 0 if [ "${2%/*}" != "${2%/}" ]; then mv -f "$chroot_dir/${2%/*}/$(basename "$1")" \ "$chroot_dir/${2%/*}/$(basename "$2")" @@ -62,7 +64,7 @@ cp_p() { # Bring in basic libraries: rm -f lib/* libexec/* # ld-elf.so.2: -cp_p /libexec/ld-elf.so.2 libexec +cp_p /libexec/ld-elf.so.2 libexec/ pull_in_lib() { [ -f "$1" ] || return @@ -71,6 +73,7 @@ pull_in_lib() { cp_p "$1" "$dst" for llib in $(ldd "$1" | grep '=>' | awk '{print $3}'); do (pull_in_lib "$llib" lib) + test $? -eq 0 done fi @@ -97,12 +100,12 @@ pull_in_bin() { bnam="$(basename "$bdst")" bdst="${bdst%/*}" fi - if [ -n "$3" ] && [ "$3" != "$bnam" ] && \ - [ -r "$bdst/$3" -a -x "$bdst/$3" ] && cmp -s "$bin" "$bdst/$3"; then + if [ -n "$3" ] && [ "$3" != "$bnam" ] && + [ -r "$bdst/$3" ] && [ -x "$bdst/$3" ] && cmp -s "$bin" "$bdst/$3"; then ln -f "$bdst/$3" "$bdst/$bnam" return 0 fi - cp_p "$bin" var/tmp + cp_p "$bin" var/tmp/ # ...and all the dependencies. for lib in $(ldd "$bin" | grep '=>' | awk '{print $3}'); do pull_in_lib "$lib" lib @@ -113,13 +116,13 @@ pull_in_bin() { # A catch all that needs to be called after everything's been pulled in chroot_update_permissions() { # Be paranoid - [ -n "$chroot_dir" -a "$chroot_dir" != "/" ] || { echo bad '$chroot_dir' >&2; exit 2; } + [ -n "$chroot_dir" ] && [ "$chroot_dir" != "/" ] || { echo bad '$chroot_dir' >&2; exit 2; } cd "$chroot_dir" || { echo bad '$chroot_dir' >&2; exit 2; } rm -rf var/tmp chown -R 0:0 bin lib sbin var libexec # bootstrap the master.passwd database rm -f etc/master.passwd etc/pwd.db etc/spwd.db - awk -F ':' '{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }' < etc/passwd > etc/master.passwd + awk -F ':' '{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }' etc/master.passwd PW_SCAN_BIG_IDS=1 pwd_mkdb -d etc etc/master.passwd 2>/dev/null chown $cfg_mirror_user:$cfg_owning_group etc/master.passwd etc/pwd.db etc/spwd.db chmod 0664 etc/master.passwd etc/pwd.db etc/spwd.db diff --git a/chrootsetup_freebsd.sh b/chrootsetup_freebsd.sh index 681db1d..d4d62fc 100644 --- a/chrootsetup_freebsd.sh +++ b/chrootsetup_freebsd.sh @@ -15,19 +15,19 @@ # Finally this script must install a suitable nc.openbsd compatible version of # netcat into the chroot jail that's available as nc.openbsd and which supports -# connects to unix sockets. +# connections to unix sockets. # We are designed to set up the chroot based on binaries from # amd64 FreeBSD 8; some things may need slight modifications if # being run on a different distribution. # We require update_pwd_db to be set to work properly on FreeBSD -[ -n "$cfg_update_pwd_db" -a "$cfg_update_pwd_db" != "0" ] || { +[ -n "$cfg_update_pwd_db" ] && [ "$cfg_update_pwd_db" != "0" ] || { echo 'error: Config.pm must set $update_pwd_db to 1 to use a FreeBSD jail' >&2 exit 1 } -chroot_dir="`pwd`" +chroot_dir="$(pwd)" mkdir -p dev proc chown 0:0 dev proc @@ -37,7 +37,7 @@ mkdir -p libexec var/tmp # Make sure there's an auth.conf file, empty is fine if ! [ -e etc/auth.conf ]; then - > etc/auth.conf + >etc/auth.conf chown 0:0 etc/auth.conf chmod 0444 etc/auth.conf fi @@ -45,8 +45,10 @@ fi cp_p() { # use cpio to avoid setting flags # must NOT use passthrough mode as that will set flags on newer systems - (cd "$(dirname "$1")" && echo "$(basename "$1")" | \ - cpio -o -L 2>/dev/null| { cd "$chroot_dir/${2%/*}" && cpio -i -m -u; } 2>/dev/null) + [ "$2" = "${2%/}/" ] || ! [ -d "$chroot_dir/$2" ] || set -- "$1" "$2/" + (cd "$(dirname "$1")" && echo "$(basename "$1")" | + cpio -o -L 2>/dev/null | { cd "$chroot_dir/${2%/*}" && cpio -i -m -u; } 2>/dev/null) + test $? -eq 0 if [ "${2%/*}" != "${2%/}" ]; then mv -f "$chroot_dir/${2%/*}/$(basename "$1")" \ "$chroot_dir/${2%/*}/$(basename "$2")" @@ -56,7 +58,7 @@ cp_p() { # Bring in basic libraries: rm -f lib/* libexec/* # ld-elf.so.1: -cp_p /libexec/ld-elf.so.1 libexec +cp_p /libexec/ld-elf.so.1 libexec/ pull_in_lib() { [ -f "$1" ] || return @@ -65,6 +67,7 @@ pull_in_lib() { cp_p "$1" "$dst" for llib in $(ldd "$1" | grep '=>' | awk '{print $3}'); do (pull_in_lib "$llib" lib) + test $? -eq 0 done fi @@ -91,12 +94,12 @@ pull_in_bin() { bnam="$(basename "$bdst")" bdst="${bdst%/*}" fi - if [ -n "$3" ] && [ "$3" != "$bnam" ] && \ - [ -r "$bdst/$3" -a -x "$bdst/$3" ] && cmp -s "$bin" "$bdst/$3"; then + if [ -n "$3" ] && [ "$3" != "$bnam" ] && + [ -r "$bdst/$3" ] && [ -x "$bdst/$3" ] && cmp -s "$bin" "$bdst/$3"; then ln -f "$bdst/$3" "$bdst/$bnam" return 0 fi - cp_p "$bin" var/tmp + cp_p "$bin" var/tmp/ # ...and all the dependencies. for lib in $(ldd "$bin" | grep '=>' | awk '{print $3}'); do pull_in_lib "$lib" lib @@ -107,13 +110,13 @@ pull_in_bin() { # A catch all that needs to be called after everything's been pulled in chroot_update_permissions() { # Be paranoid - [ -n "$chroot_dir" -a "$chroot_dir" != "/" ] || { echo bad '$chroot_dir' >&2; exit 2; } + [ -n "$chroot_dir" ] && [ "$chroot_dir" != "/" ] || { echo bad '$chroot_dir' >&2; exit 2; } cd "$chroot_dir" || { echo bad '$chroot_dir' >&2; exit 2; } rm -rf var/tmp chown -R 0:0 bin lib sbin var libexec # bootstrap the master.passwd database rm -f etc/master.passwd etc/pwd.db etc/spwd.db - awk -F ':' '{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }' < etc/passwd > etc/master.passwd + awk -F ':' '{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }' etc/master.passwd PW_SCAN_BIG_IDS=1 pwd_mkdb -d etc etc/master.passwd 2>/dev/null chown $cfg_mirror_user:$cfg_owning_group etc/master.passwd etc/pwd.db etc/spwd.db chmod 0664 etc/master.passwd etc/pwd.db etc/spwd.db diff --git a/chrootsetup_linux.sh b/chrootsetup_linux.sh index b888697..083ea6e 100644 --- a/chrootsetup_linux.sh +++ b/chrootsetup_linux.sh @@ -15,13 +15,13 @@ # Finally this script must install a suitable nc.openbsd compatible version of # netcat into the chroot jail that's available as nc.openbsd and which supports -# connects to unix sockets. +# connections to unix sockets. # We are designed to set up the chroot based on binaries from # amd64 Debian lenny; some things may need slight modifications if # being run on a different distribution. -chroot_dir="`pwd`" +chroot_dir="$(pwd)" mkdir -p dev proc selinux chown 0:0 proc selinux @@ -41,7 +41,7 @@ mkdir -p var/run/sshd var/tmp has_files() { - for _f; do + for _f in "$@"; do test -f "$_f" || return 1 done return 0 @@ -51,8 +51,8 @@ has_files() rm -f lib/* # ld.so: -[ -d /lib ] && has_files /lib/ld-linux*.so* && cp -p -t lib /lib/ld-linux*.so* -[ -d /lib64 ] && has_files /lib64/ld-linux*64.so* && cp -p -t lib /lib64/ld-linux*64.so* +! [ -d /lib ] || ! has_files /lib/ld-linux*.so* || cp -p -t lib /lib/ld-linux*.so* +! [ -d /lib64 ] || ! has_files /lib64/ld-linux*64.so* || cp -p -t lib /lib64/ld-linux*64.so* has_files lib/ld-linux*.so* || { echo "ERROR: could not find any ld-linux*.so* file" >&2 exit 1 @@ -60,7 +60,7 @@ has_files lib/ld-linux*.so* || { # Besides '=>' libs, attempt to pick up absolute path libs and create a symlink for upto one level deep extract_libs() { - ldd "$1" | grep -v -e linux-gate -e linux-vdso -e ld-linux | awk '{print $1 " " $2 " " $3}' | \ + ldd "$1" | grep -v -e linux-gate -e linux-vdso -e ld-linux | awk '{print $1 " " $2 " " $3}' | while read -r _f1 _f2 _f3; do case "$_f2" in "=>") @@ -87,6 +87,7 @@ extract_libs() { esac esac done + test $? -eq 0 } pull_in_lib() { @@ -96,12 +97,15 @@ pull_in_lib() { cp -p -t "$2" "$1" for llib in $(extract_libs "$1"); do (pull_in_lib "$llib" lib) + test $? -eq 0 done fi case "$(basename "$1")" in libc.*) # grab libnss_compat.so* from libc location + ! has_files "$(dirname "$1")/libnss_compat."so* || for nlib in "$(dirname "$1")/libnss_compat."so*; do (pull_in_lib "$nlib" "$2") + test $? -eq 0 done esac } @@ -127,8 +131,8 @@ pull_in_bin() { bnam="$(basename "$bdst")" bdst="${bdst%/*}" fi - if [ -n "$3" ] && [ "$3" != "$bnam" ] && \ - [ -r "$bdst/$3" -a -x "$bdst/$3" ] && cmp -s "$bin" "$bdst/$3"; then + if [ -n "$3" ] && [ "$3" != "$bnam" ] && + [ -r "$bdst/$3" ] && [ -x "$bdst/$3" ] && cmp -s "$bin" "$bdst/$3"; then ln -f "$bdst/$3" "$bdst/$bnam" return 0 fi @@ -143,7 +147,7 @@ pull_in_bin() { # A catch all that needs to be called after everything's been pulled in chroot_update_permissions() { # Be paranoid - [ -n "$chroot_dir" -a "$chroot_dir" != "/" ] || { echo bad '$chroot_dir' >&2; exit 2; } + [ -n "$chroot_dir" ] && [ "$chroot_dir" != "/" ] || { echo bad '$chroot_dir' >&2; exit 2; } cd "$chroot_dir" || { echo bad '$chroot_dir' >&2; exit 2; } rm -rf var/tmp chown -R 0:0 bin dev lib sbin var diff --git a/gitweb/genindex.sh b/gitweb/genindex.sh index 96e7a98..99e24da 100755 --- a/gitweb/genindex.sh +++ b/gitweb/genindex.sh @@ -28,20 +28,22 @@ if [ -z "$update" ] || [ ! -s "$cfg_projlist_cache_dir/gitproj.list" ]; then get_repo_list | while read proj; do echo "$proj $(cd "$cfg_reporoot/$proj.git" && config_get owner)" done | perl -MDigest::MD5=md5_hex -ne \ - '@_=split;print "$_[0] ",md5_hex(lc($_[1]))," $_[1]\n";' | \ + '@_=split;print "$_[0] ",md5_hex(lc($_[1]))," $_[1]\n";' | LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$ + test $? -eq 0 else - get_repo_list | LC_ALL=C sort -k 1,1 | \ - LC_ALL=C join -a 1 - "$cfg_projlist_cache_dir/gitproj.list" | \ + get_repo_list | LC_ALL=C sort -k 1,1 | + LC_ALL=C join -a 1 - "$cfg_projlist_cache_dir/gitproj.list" | while read proj hash owner; do - if [ "$proj" = "$update" -o -z "$owner" -o -z "$hash" ]; then + if [ "$proj" = "$update" ] || [ -z "$owner" ] || [ -z "$hash" ]; then echo "$proj recalc $(cd "$cfg_reporoot/$proj.git" && config_get owner)" else echo "$proj $hash $owner" fi done | perl -MDigest::MD5=md5_hex -ne \ - '@_=split;print "$_[0] ",$_[1] eq "recalc"?md5_hex(lc($_[2])):$_[1]," $_[2]\n";' | \ + '@_=split;print "$_[0] ",$_[1] eq "recalc"?md5_hex(lc($_[2])):$_[1]," $_[2]\n";' | LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$ + test $? -eq 0 fi cut -d ' ' -f 1,3- /tmp/gitweb.list.$$ diff --git a/hooks/post-receive b/hooks/post-receive index 65c017b..7a66b08 100755 --- a/hooks/post-receive +++ b/hooks/post-receive @@ -12,11 +12,11 @@ mob=@mob@ umask 002 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" || : git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \ - --count=1 refs/heads > info/lastactivity || : + --count=1 refs/heads >info/lastactivity || : ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || : rm -f .delaygc .allowgc -if [ "$mob" = "mob" -a -d mob ]; then - git for-each-ref --format='%(objectname) %(refname)' > packed-refs.mob.$$ || : +if [ "$mob" = "mob" ] && [ -d mob ]; then + git for-each-ref --format='%(objectname) %(refname)' >packed-refs.mob.$$ || : mv -f packed-refs.mob.$$ packed-refs.mob rm -f packed-refs.mob.$$ fi @@ -62,7 +62,7 @@ else done git for-each-ref --format='%(objectname) %(objectname) %(refname)' refs/heads || : echo "done ref-changes $authuser ${projname%.git}" || : - ) 2>/dev/null | { nc_openbsd -w 15 -U "$sockpath" || :; } + ) 2>/dev/null | { nc_openbsd -w 15 -U "$sockpath" || :; } || : fi exit 0 diff --git a/hooks/pre-receive b/hooks/pre-receive index 4c19a17..7d16741 100755 --- a/hooks/pre-receive +++ b/hooks/pre-receive @@ -51,8 +51,8 @@ octet='[0-9a-f][0-9a-f]' octet4="$octet$octet$octet$octet" octet20="$octet4$octet4$octet4$octet4$octet4" _make_packs_ugw() { - find "$1" -maxdepth 1 -type f \! -perm -ug+w \ - -name "pack-$octet20.pack" -print0 | \ + find "$1" -maxdepth 1 -type f ! -perm -ug+w \ + -name "pack-$octet20.pack" -print0 | xargs -0 chmod ug+w || : } 2>/dev/null _make_packs_ugw objects/pack diff --git a/hooks/update b/hooks/update index ecef878..f7d86b8 100755 --- a/hooks/update +++ b/hooks/update @@ -26,17 +26,17 @@ if ! [ -x @perlbin@ ]; then exit 3 fi - if [ -n "$mobdir" -a "$mob" != "mob" ]; then + if [ -n "$mobdir" ] && [ "$mob" != "mob" ]; then # Should only get here if there's a misconfiguration echo "Personal mob branches are not supported" >&2 exit 3 fi - if [ -n "$mobdir" -a "$LOGNAME" = "mob" ]; then + if [ -n "$mobdir" ] && [ "$LOGNAME" = "mob" ]; then # Should only get here if there's a misconfiguration echo "The mob user may not use personal mob branches" >&2 exit 3 fi - if [ -n "$mobdir" -a ! -d "$reporoot/$proj/mob" ]; then + if [ -n "$mobdir" ] && ! [ -d "$reporoot/$proj/mob" ]; then # Should only get here if there's a misconfiguration echo "The project '$proj' does not support personal mob branches" >&2 exit 3 @@ -76,7 +76,7 @@ if ! [ -x @perlbin@ ]; then exit 3 fi - if [ "$mob" = "mob" -a "$LOGNAME" = "mob" ]; then + if [ "$mob" = "mob" ] && [ "$LOGNAME" = "mob" ]; then if [ x"$1" != x"refs/heads/mob" ]; then echo "The mob user may push only to the 'mob' branch, sorry" >&2 exit 1 @@ -138,7 +138,7 @@ if [ -n "$GIT_PROJECT_ROOT" ]; then fi authuser="${REMOTE_USER#/UID=}" - authuuid="${authuser}" + authuuid="$authuser" authuser="${authuser%/dnQualifier=*}" authuuid="${authuuid#$authuser}" authuuid="${authuuid#/dnQualifier=}" @@ -146,7 +146,7 @@ if [ -n "$GIT_PROJECT_ROOT" ]; then echo "Only authenticated users may push, sorry" >&2 exit 3 fi - if [ "$authuser" != "mob" -o "$cfg_mob" != "mob" ]; then + if [ "$authuser" != "mob" ] || [ "$cfg_mob" != "mob" ]; then if ! useruuid="$("$cfg_basedir/bin/get_user_uuid" "$authuser")" || [ "$useruuid" != "$authuuid" ]; then echo "The user '$authuser' certificate being used is no longer valid." echo "You may download a new user certificate at $cfg_webadmurl/edituser.cgi" @@ -154,17 +154,17 @@ if [ -n "$GIT_PROJECT_ROOT" ]; then fi fi - if [ -n "$mobdir" -a "$cfg_mob" != "mob" ]; then + if [ -n "$mobdir" ] && [ "$cfg_mob" != "mob" ]; then # Should only get here if there's a misconfiguration echo "Personal mob branches are not supported" >&2 exit 3 fi - if [ -n "$mobdir" -a "$authuser" = "mob" ]; then + if [ -n "$mobdir" ] && [ "$authuser" = "mob" ]; then # Should only get here if there's a misconfiguration echo "The mob user may not use personal mob branches" >&2 exit 3 fi - if [ -n "$mobdir" -a ! -d "$reporoot/$proj/mob" ]; then + if [ -n "$mobdir" ] && ! [ -d "$reporoot/$proj/mob" ]; then # Should only get here if there's a misconfiguration echo "The project '$proj' does not support personal mob branches" >&2 exit 3 @@ -204,7 +204,7 @@ if [ -n "$GIT_PROJECT_ROOT" ]; then exit 3 fi - if [ "$cfg_mob" = "mob" -a "$authuser" = "mob" ]; then + if [ "$cfg_mob" = "mob" ] && [ "$authuser" = "mob" ]; then if [ x"$1" != x"refs/heads/mob" ]; then echo "The mob user may push only to the 'mob' branch, sorry" >&2 exit 1 diff --git a/install.sh b/install.sh index 25201ee..dd632c5 100755 --- a/install.sh +++ b/install.sh @@ -12,7 +12,7 @@ if [ -z "$MAKE" ]; then fi # Run perl module checker -if [ ! -x toolbox/check-perl-modules.pl ]; then +if ! [ -f toolbox/check-perl-modules.pl ] || ! [ -x toolbox/check-perl-modules.pl ]; then echo "ERROR: missing toolbox/check-perl-modules.pl!" >&2 exit 1 fi @@ -37,7 +37,7 @@ quick_move() { [ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ] || { echo "fatal: quick_move: bad args: '$1' '$2' '$3'" >&2; exit 1; } ! [ -e "$3" ] || { echo "fatal: quick_move: already exists: $3" >&2; exit 1; } [ -d "$1" ] || { echo "fatal: quick_move: no such dir: $1" >&2; exit 1; } - [ ! -e "$2" -o -d "$2" ] || { echo "fatal: quick_move: not a dir: $2" >&2; exit 1; } + ! [ -e "$2" ] || [ -d "$2" ] || { echo "fatal: quick_move: not a dir: $2" >&2; exit 1; } perl -e 'rename($ARGV[1], $ARGV[2]) or die "rename failed: $!\n" if -d $ARGV[1]; rename($ARGV[0], $ARGV[1]) or die "rename failed: $!\n"; exit 0;' "$1" "$2" "$3" || { echo "fatal: quick_move: rename failed" >&2 @@ -54,9 +54,9 @@ check_sh_builtin() ( "command" "$var_sh_bin" -c '{ "unset" -f unalias command "$1" || :; "unalias" "$1" || :; } >/dev/null 2>&1; "command" -v "$1"' "$var_sh_bin" "$1" ) 2>/dev/null -owngroup="" +owngroup= [ -z "$cfg_owning_group" ] || owngroup=":$cfg_owning_group" -if [ -n "$cfg_httpspushurl" -a -z "$cfg_certsdir" ]; then +if [ -n "$cfg_httpspushurl" ] && [ -z "$cfg_certsdir" ]; then echo "ERROR: \$httpspushurl is set but \$certsdir is not!" >&2 echo "ERROR: perhaps you have an incorrect Config.pm?" >&2 exit 1 @@ -64,54 +64,54 @@ fi # Check for extra required tools -if [ -n "$cfg_xmllint_readme" -a "$cfg_xmllint_readme" != "0" ] && ! command -v xmllint >/dev/null; then +if [ "${cfg_xmllint_readme:-0}" != "0" ] && ! command -v xmllint >/dev/null; then echo "ERROR: \$xmllint_readme set but xmllint not in \$PATH!" >&2 exit 1 fi echo "*** Checking for compiled utilities..." -if [ ! -x src/can_user_push ]; then +if ! [ -f src/can_user_push ] || ! [ -x src/can_user_push ]; then echo "ERROR: src/can_user_push is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi -if [ ! -x src/can_user_push_http ]; then +if ! [ -f src/can_user_push_http ] || ! [ -x src/can_user_push_http ]; then echo "ERROR: src/can_user_push_http is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi -if [ ! -x src/getent ]; then +if ! [ -f src/getent ] || ! [ -x src/getent ]; then echo "ERROR: src/getent is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi -if [ ! -x src/get_user_uuid ]; then +if ! [ -f src/get_user_uuid ] || ! [ -x src/get_user_uuid ]; then echo "ERROR: src/get_user_uuid is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi -if [ ! -x src/list_packs ]; then +if ! [ -f src/list_packs ] || ! [ -x src/list_packs ]; then echo "ERROR: src/list_packs is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi -if [ ! -x src/peek_packet ]; then +if ! [ -f src/peek_packet ] || ! [ -x src/peek_packet ]; then echo "ERROR: src/peek_packet is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi -if [ ! -x src/rangecgi ]; then +if ! [ -f src/rangecgi ] || ! [ -x src/rangecgi ]; then echo "ERROR: src/rangecgi is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi -if [ ! -x src/strftime ]; then +if ! [ -f src/strftime ] || ! [ -x src/strftime ]; then echo "ERROR: src/strftime is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 fi -if [ ! -x src/throttle ]; then +if ! [ -f src/throttle ] || ! [ -x src/throttle ]; then echo "ERROR: src/throttle is not built! Did you _REALLY_ read INSTALL?" >&2 echo "ERROR: perhaps you forgot to run make?" >&2 exit 1 @@ -119,7 +119,7 @@ fi echo "*** Checking for ezcert..." -if ! [ -f ezcert.git/CACreateCert -a -x ezcert.git/CACreateCert ]; then +if ! [ -f ezcert.git/CACreateCert ] || ! [ -x ezcert.git/CACreateCert ]; then echo "ERROR: ezcert.git is not checked out! Did you _REALLY_ read INSTALL?" >&2 exit 1 fi @@ -130,11 +130,11 @@ case "$cfg_git_bin" in /*) :;; *) echo 'ERROR: $Girocco::Config::git_bin must be set to an absolute path' >&2 exit 1 esac -if [ ! -x "$cfg_git_bin" ]; then +if ! [ -f "$cfg_git_bin" ] || ! [ -x "$cfg_git_bin" ]; then echo "ERROR: $cfg_git_bin does not exist or is not executable" >&2 exit 1 fi -if ! git_version="$("$cfg_git_bin" version)"; then +if ! git_version="$("$cfg_git_bin" version)" || [ -z "$git_version" ]; then echo "ERROR: $cfg_git_bin version failed" >&2 exit 1 fi @@ -167,7 +167,7 @@ client pushes and server garbage collections. EOT fi -if [ -n "$cfg_mirror" -a "$(vcmp "$git_vernum" 1.7.5)" -lt 0 ]; then +if [ -n "$cfg_mirror" ] && [ "$(vcmp "$git_vernum" 1.7.5)" -lt 0 ]; then echo 'WARNING: $Girocco::Config::git_bin version < 1.7.5 and mirroring enabled, some sources can cause an infinite fetch loop' fi if [ "$(vcmp "$git_vernum" 1.7.6.6)" -lt 0 ]; then @@ -177,7 +177,7 @@ if [ "$(uname -m 2>/dev/null)" = "x86_64" ] && [ "$(vcmp "$git_vernum" 1.7.11)" echo 'WARNING: $Girocco::Config::git_bin version >= 1.7.11 and x86_64, make sure Git built WITHOUT XDL_FAST_HASH' echo 'WARNING: See http://mid.mail-archive.com/20141222041944.GA441@peff.net for details' fi -if [ "$(vcmp "$git_vernum" 1.8.4.2)" -ge 0 ] && [ -n "$cfg_mirror" -a "$(vcmp "$git_vernum" 2)" -lt 0 ]; then +if [ "$(vcmp "$git_vernum" 1.8.4.2)" -ge 0 ] && [ -n "$cfg_mirror" ] && [ "$(vcmp "$git_vernum" 2)" -lt 0 ]; then echo 'WARNING: $Girocco::Config::git_bin version >= 1.8.4.2 and < 2.0.0, git-daemon needs write access for shallow clones' echo 'WARNING: $Girocco::Config::git_bin version >= 1.8.4.2 and < 2.0.0, shallow clones will leave repository turds' fi @@ -250,7 +250,7 @@ We will now pause for a moment so you can reflect on this warning. EOT sleep 60 fi -if [ -n "$cfg_mirror" -a "$cfg_mirror" != 0 ] && grep -q ns_parserr "$cfg_git_bin"; then +if [ -n "$cfg_mirror" ] && [ "$cfg_mirror" != 0 ] && grep -q ns_parserr "$cfg_git_bin"; then cat <<'EOT' *** @@ -277,7 +277,7 @@ fi test_nc_U() { [ -n "$1" ] || return 1 _cmdnc="$(command -v "$1" 2>/dev/null)" || : - [ -n "$_cmdnc" ] && [ -x "$_cmdnc" ] || return 1 + [ -n "$_cmdnc" ] && [ -f "$_cmdnc" ] && [ -x "$_cmdnc" ] || return 1 _tmpdir="$(mktemp -d /tmp/nc-u-XXXXXX)" [ -n "$_tmpdir" ] && [ -d "$_tmpdir" ] || return 1 >"$_tmpdir/output" @@ -306,7 +306,7 @@ test_nc_U "$var_nc_openbsd_bin" || { echo "*** Verifying selected POSIX sh is sane..." shbin="$var_sh_bin" -[ -n "$shbin" ] && [ -x "$shbin" ] && [ "$("$shbin" -c 'echo sh $(( 1 + 1 ))' 2>/dev/null)" = "sh 2" ] || { +[ -n "$shbin" ] && [ -f "$shbin" ] && [ -x "$shbin" ] && [ "$("$shbin" -c 'echo sh $(( 1 + 1 ))' 2>/dev/null)" = "sh 2" ] || { echo 'ERROR: invalid $Girocco::Config::posix_sh_bin setting' >&2 exit 1 } @@ -361,14 +361,14 @@ done echo "*** Verifying selected perl is sane..." perlbin="$var_perl_bin" -[ -n "$perlbin" ] && [ -x "$perlbin" ] && [ "$("$perlbin" -wle 'print STDOUT "perl ", + ( 1 + 1 )' 2>/dev/null)" = "perl 2" ] || { +[ -n "$perlbin" ] && [ -f "$perlbin" ] && [ -x "$perlbin" ] && [ "$("$perlbin" -wle 'print STDOUT "perl ", + ( 1 + 1 )' 2>/dev/null)" = "perl 2" ] || { echo 'ERROR: invalid $Girocco::Config::perl_bin setting' >&2 exit 1 } echo "*** Verifying selected gzip is sane..." gzipbin="$var_gzip_bin" -[ -n "$gzipbin" ] && [ -x "$gzipbin" ] && "$gzipbin" -V 2>&1 | grep -q gzip && \ +[ -n "$gzipbin" ] && [ -f "$gzipbin" ] && [ -x "$gzipbin" ] && "$gzipbin" -V 2>&1 | grep -q gzip && [ "$(echo Girocco | "$gzipbin" -c -n -9 | "$gzipbin" -c -d)" = "Girocco" ] || { echo 'ERROR: invalid $Girocco::Config::gzip_bin setting' >&2 exit 1 @@ -475,10 +475,10 @@ esac echo "*** Setting up basedir..." chown_make() { - if [ "$LOGNAME" = root -a -n "$SUDO_USER" -a "$SUDO_USER" != root ]; then - find "$@" -user root -print0 2>/dev/null | \ + if [ "$LOGNAME" = root ] && [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != root ]; then + find "$@" -user root -print0 2>/dev/null | xargs -0 chown "$SUDO_USER:$(id -gn "$SUDO_USER")" - elif [ "$LOGNAME" = root -a -z "$SUDO_USER" -o "$SUDO_USER" = root ]; then + elif [ "$LOGNAME" = root ] && { [ -z "$SUDO_USER" ] || [ "$SUDO_USER" = root ]; }; then echo "*** WARNING: running make as root w/o sudo may leave root-owned: $*" fi } @@ -552,10 +552,11 @@ unset PERLBIN unset SHBIN # Dump all the cfg_ and defined_ variables to shlib_vars.sh -get_girocco_config_var_list > "$basedir"/shlib_vars.sh +get_girocco_config_var_list >"$basedir"/shlib_vars.sh echo "*** Setting up darcs-fast-export from bzr-fastimport.git..." -if [ ! -d bzr-fastimport.git/exporters/darcs/ ]; then +if ! [ -f bzr-fastimport.git/exporters/darcs/darcs-fast-export ] || + ! [ -x bzr-fastimport.git/exporters/darcs/darcs-fast-export ]; then echo "ERROR: bzr-fastimport.git is not checked out! Did you _REALLY_ read INSTALL?" >&2 exit 1 fi @@ -563,7 +564,7 @@ mkdir -p "$basedir"/bin cp bzr-fastimport.git/exporters/darcs/darcs-fast-export "$basedir"/bin echo "*** Setting up hg-fast-export from fast-export.git..." -if [ ! -f fast-export.git/hg-fast-export.py -o ! -f fast-export.git/hg2git.py ]; then +if ! [ -f fast-export.git/hg-fast-export.py ] || ! [ -f fast-export.git/hg2git.py ]; then echo "ERROR: fast-export.git is not checked out! Did you _REALLY_ read INSTALL?" >&2 exit 1 fi @@ -571,15 +572,15 @@ mkdir -p "$basedir"/bin cp fast-export.git/hg-fast-export.py fast-export.git/hg2git.py "$basedir"/bin echo "*** Setting up markdown from markdown.git..." -if [ ! -f markdown.git/Markdown.pl ]; then +if ! [ -f markdown.git/Markdown.pl ]; then echo "ERROR: markdown.git is not checked out! Did you _REALLY_ read INSTALL?" >&2 exit 1 fi mkdir -p "$basedir"/bin -(PERLBIN="$perlbin" && export PERLBIN && \ +(PERLBIN="$perlbin" && export PERLBIN && perl -p -e 's/^#!.*perl/#!$ENV{PERLBIN}/ if $. == 1;' \ - markdown.git/Markdown.pl > "$basedir"/bin/Markdown.pl.$$ && \ - chmod a+x "$basedir"/bin/Markdown.pl.$$ && \ + markdown.git/Markdown.pl >"$basedir"/bin/Markdown.pl.$$ && + chmod a+x "$basedir"/bin/Markdown.pl.$$ && mv -f "$basedir"/bin/Markdown.pl.$$ "$basedir"/bin/Markdown.pl) test $? -eq 0 @@ -642,7 +643,7 @@ chmod 02775 "$cfg_chroot/etc" || echo "WARNING: Cannot chmod 02775 $cfg_chroot/e echo "*** Setting up gitweb from git.git..." -if [ ! -f git.git/Makefile ]; then +if ! [ -f git.git/Makefile ]; then echo "ERROR: git.git is not checked out! Did you _REALLY_ read INSTALL?" >&2 exit 1 fi @@ -656,47 +657,52 @@ rm -rf "$webroot" "$cgiroot" [ -n "$cgirootsub" ] || ! [ -d "$rcgiroot" ] || cp -pR "$rcgiroot" "$cgiroot" >/dev/null 2>&1 || : mkdir -p "$webroot" "$cgiroot" -(cd git.git && "$MAKE" --no-print-directory --silent NO_SUBDIR=: bindir="$(dirname "$cfg_git_bin")" \ - GITWEB_CONFIG="$cfg_basedir/gitweb/gitweb_config.perl" SHELL_PATH="$shbin" gitweb && \ - chown_make gitweb && \ - PERLBIN="$perlbin" && export PERLBIN && \ +( + cd git.git && + "$MAKE" --no-print-directory --silent NO_SUBDIR=: bindir="$(dirname "$cfg_git_bin")" \ + GITWEB_CONFIG="$cfg_basedir/gitweb/gitweb_config.perl" SHELL_PATH="$shbin" gitweb && + chown_make gitweb && + PERLBIN="$perlbin" && export PERLBIN && perl -p -e 's/^#!.*perl/#!$ENV{PERLBIN}/ if $. == 1;' \ - -e 's/^(\s*use\s+warnings\s*;.*)$/#$1/;' gitweb/gitweb.cgi > "$cgiroot"/gitweb.cgi.$$ && \ - chmod a+x "$cgiroot"/gitweb.cgi.$$ && \ - chown_make "$cgiroot"/gitweb.cgi.$$ && \ - mv -f "$cgiroot"/gitweb.cgi.$$ "$cgiroot"/gitweb.cgi && \ - cp gitweb/static/*.png gitweb/static/*.css gitweb/static/*.js "$webroot") + -e 's/^(\s*use\s+warnings\s*;.*)$/#$1/;' gitweb/gitweb.cgi >"$cgiroot"/gitweb.cgi.$$ && + chmod a+x "$cgiroot"/gitweb.cgi.$$ && + chown_make "$cgiroot"/gitweb.cgi.$$ && + mv -f "$cgiroot"/gitweb.cgi.$$ "$cgiroot"/gitweb.cgi && + cp gitweb/static/*.png gitweb/static/*.css gitweb/static/*.js "$webroot" +) test $? -eq 0 echo "*** Setting up git-browser from git-browser.git..." -if [ ! -f git-browser.git/git-browser.cgi ]; then +if ! [ -f git-browser.git/git-browser.cgi ]; then echo "ERROR: git-browser.git is not checked out! Did you _REALLY_ read INSTALL?" >&2 exit 1 fi mkdir -p "$webroot"/git-browser "$cgiroot" -(cd git-browser.git && \ - CFG="$cfg_basedir/gitweb/git-browser.conf" && export CFG && \ +( + cd git-browser.git && + CFG="$cfg_basedir/gitweb/git-browser.conf" && export CFG && PERLBIN="$perlbin" && export PERLBIN && perl -p \ -e 's/^#!.*perl/#!$ENV{PERLBIN}/ if $. == 1;' \ - -e 's/"git-browser\.conf"/"$ENV{"CFG"}"/' git-browser.cgi > "$cgiroot"/git-browser.cgi.$$ && \ - chmod a+x "$cgiroot"/git-browser.cgi.$$ && \ - chown_make "$cgiroot"/git-browser.cgi.$$ && \ - mv -f "$cgiroot"/git-browser.cgi.$$ "$cgiroot"/git-browser.cgi && \ - cp -r *.html *.js *.css js.lib "$webroot"/git-browser && \ - cp -r JSON "$cgiroot") + -e 's/"git-browser\.conf"/"$ENV{"CFG"}"/' git-browser.cgi >"$cgiroot"/git-browser.cgi.$$ && + chmod a+x "$cgiroot"/git-browser.cgi.$$ && + chown_make "$cgiroot"/git-browser.cgi.$$ && + mv -f "$cgiroot"/git-browser.cgi.$$ "$cgiroot"/git-browser.cgi && + cp -r *.html *.js *.css js.lib "$webroot"/git-browser && + cp -r JSON "$cgiroot" +) test $? -eq 0 rm -f "$webroot"/git-browser/index.html -cat >"$basedir/gitweb"/git-browser.conf.$$ <"$basedir/gitweb"/git-browser.conf.$$ <<-EOT + gitbin: $cfg_git_bin + warehouse: $cfg_reporoot + doconfig: $cfg_basedir/gitweb/gitbrowser_config.perl EOT chown_make "$basedir/gitweb"/git-browser.conf.$$ mv -f "$basedir/gitweb"/git-browser.conf.$$ "$basedir/gitweb"/git-browser.conf -cat >"$webroot"/git-browser/GitConfig.js.$$ <"$webroot"/git-browser/GitConfig.js.$$ <<-EOT + cfg_gitweb_url="$cfg_gitweburl/" + cfg_browsercgi_url="$cfg_webadmurl/git-browser.cgi" EOT chown_make "$webroot"/git-browser/GitConfig.js.$$ mv -f "$webroot"/git-browser/GitConfig.js.$$ "$webroot"/git-browser/GitConfig.js @@ -712,7 +718,7 @@ rm -rf "$basedir/cgi" ln -fs "$cfg_basedir"/Girocco "$cgiroot" [ -z "$cfg_webreporoot" ] || { rm -f "$cfg_webreporoot" && ln -s "$cfg_reporoot" "$cfg_webreporoot"; } if [ -z "$cfg_httpspushurl" ]; then - grep -v 'rootcert[.]html' gitweb/indextext.html > "$basedir/gitweb/indextext.html" + grep -v 'rootcert[.]html' gitweb/indextext.html >"$basedir/gitweb/indextext.html" else cp gitweb/indextext.html "$basedir/gitweb" fi @@ -735,9 +741,9 @@ if [ -n "$cfg_httpspushurl" ]; then [ -d "$cfg_certsdir" ] wwwcertcn= if [ -e "$cfg_certsdir/girocco_www_crt.pem" ]; then - wwwcertcn="$( \ - openssl x509 -in "$cfg_certsdir/girocco_www_crt.pem" -noout -subject | \ - sed -e 's,[^/]*,,' \ + wwwcertcn="$( + openssl x509 -in "$cfg_certsdir/girocco_www_crt.pem" -noout -subject | + sed -e 's,[^/]*,,' )" fi wwwcertdns= @@ -751,12 +757,12 @@ if [ -n "$cfg_httpspushurl" ]; then wwwcertdnsfile="$(cat "$cfg_certsdir/girocco_www_crt.dns")" fi needroot= - [ -e "$cfg_certsdir/girocco_client_crt.pem" -a \ - -e "$cfg_certsdir/girocco_client_key.pem" -a \ - -e "$cfg_certsdir/girocco_www_key.pem" -a \ - -e "$cfg_certsdir/girocco_www_crt.pem" -a "$wwwcertcn" = "/CN=$cfg_httpsdnsname" -a \ - -e "$cfg_certsdir/girocco_root_crt.pem" ] || needroot=1 - if [ -n "$needroot" -a ! -e "$cfg_certsdir/girocco_root_key.pem" ]; then + [ -e "$cfg_certsdir/girocco_client_crt.pem" ] && + [ -e "$cfg_certsdir/girocco_client_key.pem" ] && + [ -e "$cfg_certsdir/girocco_www_key.pem" ] && + [ -e "$cfg_certsdir/girocco_www_crt.pem" ] && [ "$wwwcertcn" = "/CN=$cfg_httpsdnsname" ] && + [ -e "$cfg_certsdir/girocco_root_crt.pem" ] || needroot=1 + if [ -n "$needroot" ] && ! [ -e "$cfg_certsdir/girocco_root_key.pem" ]; then rm -f "$cfg_certsdir/girocco_root_crt.pem" "$cfg_certsdir/girocco_root_key.pem" umask 0077 openssl genrsa -f4 -out "$cfg_certsdir/girocco_root_key.pem" $bits @@ -765,7 +771,7 @@ if [ -n "$cfg_httpspushurl" ]; then umask 0022 echo "Created new root key" fi - if [ ! -e "$cfg_certsdir/girocco_root_crt.pem" ]; then + if ! [ -e "$cfg_certsdir/girocco_root_crt.pem" ]; then "$basedir/bin/CACreateCert" --root --key "$cfg_certsdir/girocco_root_key.pem" \ --out "$cfg_certsdir/girocco_root_crt.pem" "girocco $cfg_nickname root certificate" rm -f "$cfg_certsdir/girocco_www_crt.pem" "$cfg_certsdir/girocco_www_chain.pem" @@ -774,7 +780,7 @@ if [ -n "$cfg_httpspushurl" ]; then rm -f "$cfg_chroot/etc/sshcerts"/*.pem echo "Created new root certificate" fi - if [ ! -e "$cfg_certsdir/girocco_www_key.pem" ]; then + if ! [ -e "$cfg_certsdir/girocco_www_key.pem" ]; then umask 0077 openssl genrsa -f4 -out "$cfg_certsdir/girocco_www_key.pem" $bits chmod 0600 "$cfg_certsdir/girocco_www_key.pem" @@ -782,20 +788,20 @@ if [ -n "$cfg_httpspushurl" ]; then umask 0022 echo "Created new www key" fi - if [ ! -e "$cfg_certsdir/girocco_www_crt.pem" ] || \ + if ! [ -e "$cfg_certsdir/girocco_www_crt.pem" ] || [ "$wwwcertcn" != "/CN=$cfg_httpsdnsname" ] || [ "$wwwcertdns" != "$wwwcertdnsfile" ]; then openssl rsa -in "$cfg_certsdir/girocco_www_key.pem" -pubout | "$basedir/bin/CACreateCert" --server --key "$cfg_certsdir/girocco_root_key.pem" \ --cert "$cfg_certsdir/girocco_root_crt.pem" $wwwcertdns \ --out "$cfg_certsdir/girocco_www_crt.pem" "$cfg_httpsdnsname" - printf '%s\n' "$wwwcertdns" > "$cfg_certsdir/girocco_www_crt.dns" + printf '%s\n' "$wwwcertdns" >"$cfg_certsdir/girocco_www_crt.dns" echo "Created www certificate" fi - if [ ! -e "$cfg_certsdir/girocco_www_chain.pem" ]; then - cat "$cfg_certsdir/girocco_root_crt.pem" > "$cfg_certsdir/girocco_www_chain.pem" + if ! [ -e "$cfg_certsdir/girocco_www_chain.pem" ]; then + cat "$cfg_certsdir/girocco_root_crt.pem" >"$cfg_certsdir/girocco_www_chain.pem" echo "Created www certificate chain file" fi - if [ ! -e "$cfg_certsdir/girocco_client_key.pem" ]; then + if ! [ -e "$cfg_certsdir/girocco_client_key.pem" ]; then umask 0037 openssl genrsa -f4 -out "$cfg_certsdir/girocco_client_key.pem" $bits chmod 0640 "$cfg_certsdir/girocco_client_key.pem" @@ -803,7 +809,7 @@ if [ -n "$cfg_httpspushurl" ]; then umask 0022 echo "Created new client key" fi - if [ ! -e "$cfg_certsdir/girocco_client_crt.pem" ]; then + if ! [ -e "$cfg_certsdir/girocco_client_crt.pem" ]; then openssl rsa -in "$cfg_certsdir/girocco_client_key.pem" -pubout | "$basedir/bin/CACreateCert" --subca --key "$cfg_certsdir/girocco_root_key.pem" \ --cert "$cfg_certsdir/girocco_root_crt.pem" \ @@ -813,27 +819,27 @@ if [ -n "$cfg_httpspushurl" ]; then rm -f "$cfg_chroot/etc/sshcerts"/*.pem echo "Created client certificate" fi - if [ ! -e "$cfg_certsdir/girocco_client_suffix.pem" ]; then - cat "$cfg_certsdir/girocco_client_crt.pem" > "$cfg_certsdir/girocco_client_suffix.pem" + if ! [ -e "$cfg_certsdir/girocco_client_suffix.pem" ]; then + cat "$cfg_certsdir/girocco_client_crt.pem" >"$cfg_certsdir/girocco_client_suffix.pem" echo "Created client certificate suffix file" fi - cat "$cfg_rootcert" > "$webroot/${cfg_nickname}_root_cert.pem" + cat "$cfg_rootcert" >"$webroot/${cfg_nickname}_root_cert.pem" if [ -n "$cfg_mob" ]; then - if [ ! -e "$cfg_certsdir/girocco_mob_user_key.pem" ]; then + if ! [ -e "$cfg_certsdir/girocco_mob_user_key.pem" ]; then openssl genrsa -f4 -out "$cfg_certsdir/girocco_mob_user_key.pem" $bits chmod 0644 "$cfg_certsdir/girocco_mob_user_key.pem" rm -f "$cfg_certsdir/girocco_mob_user_crt.pem" echo "Created new mob user key" fi - if [ ! -e "$cfg_certsdir/girocco_mob_user_crt.pem" ]; then + if ! [ -e "$cfg_certsdir/girocco_mob_user_crt.pem" ]; then openssl rsa -in "$cfg_mobuserkey" -pubout | "$basedir/bin/CACreateCert" --client --key "$cfg_clientkey" \ --cert "$cfg_clientcert" \ --out "$cfg_certsdir/girocco_mob_user_crt.pem" 'mob' echo "Created mob user client certificate" fi - cat "$cfg_mobuserkey" > "$webroot/${cfg_nickname}_mob_key.pem" - cat "$cfg_mobusercert" "$cfg_clientcertsuffix" > "$webroot/${cfg_nickname}_mob_user.pem" + cat "$cfg_mobuserkey" >"$webroot/${cfg_nickname}_mob_key.pem" + cat "$cfg_mobusercert" "$cfg_clientcertsuffix" >"$webroot/${cfg_nickname}_mob_user.pem" else rm -f "$webroot/${cfg_nickname}_mob_key.pem" "$webroot/${cfg_nickname}_mob_user.pem" fi diff --git a/jailsetup.sh b/jailsetup.sh index 26e156e..dcfcf2d 100755 --- a/jailsetup.sh +++ b/jailsetup.sh @@ -11,13 +11,13 @@ set -e -curdir="`pwd`" +curdir="$(pwd)" srcdir="$curdir/src" getent="$srcdir/getent" . ./shlib.sh # find_std_utility should always come up with the full path to the standard -# version of the utility who's name is passed as "$1" +# version of the utility whose name is passed as "$1" getconf="/usr/bin/getconf" [ -x "$getconf" ] || getconf="/bin/getconf" [ -x "$getconf" ] || getconf="getconf" @@ -31,7 +31,7 @@ find_std_utility() ( "command" -v "$1" ) 2>/dev/null -dbonly='' +dbonly= [ "$1" != "dbonly" ] || dbonly=1 reserved_users="root sshd _sshd mob git lock bundle nobody everyone $cfg_cgi_user $cfg_mirror_user" @@ -40,7 +40,7 @@ reserved_users="root sshd _sshd mob git lock bundle nobody everyone $cfg_cgi_use sshd_user=sshd if ! "$getent" passwd sshd >/dev/null && ! "$getent" passwd _sshd >/dev/null; then if [ -n "$dbonly" ]; then - if [ ! -s etc/passwd ]; then + if ! [ -s etc/passwd ]; then # Only complain on initial etc/passwd creation echo "WARNING: no sshd or _sshd user, omitting entries from chroot etc/passwd" fi @@ -62,7 +62,7 @@ if ! "$getent" passwd "$cfg_cgi_user" >/dev/null; then echo "*** Error: You do not have \"$cfg_cgi_user\" user in system yet." >&2 exit 1 fi -if [ -n "$dbonly" -a -z "$cfg_owning_group" ]; then +if [ -n "$dbonly" ] && [ -z "$cfg_owning_group" ]; then cfg_owning_group="$("$getent" passwd "$cfg_mirror_user" | cut -d : -f 4)" elif ! "$getent" group "$cfg_owning_group" >/dev/null; then echo "*** Error: You do not have \"$cfg_owning_group\" group in system yet." >&2 @@ -70,7 +70,7 @@ elif ! "$getent" group "$cfg_owning_group" >/dev/null; then fi # One last paranoid check before we go writing all over everything -if [ -z "$cfg_chroot" -o "$cfg_chroot" = "/" ]; then +if [ -z "$cfg_chroot" ] || [ "$cfg_chroot" = "/" ]; then echo "*** Error: chroot location is not set or is invalid." >&2 echo "*** Error: perhaps you have an incorrect Config.pm?" >&2 exit 1 @@ -87,10 +87,10 @@ chmod 0555 var/empty || echo "WARNING: Cannot chmod a=rx $cfg_chroot/var/empty" # Set up basic user/group configuration; if there isn't any already -mobpass='' +mobpass= [ -n "$cfg_mob" ] || mobpass='x' mkdir -p etc -if [ ! -s etc/passwd ]; then +if ! [ -s etc/passwd ]; then cat >etc/passwd <etc/group <etc/girocco/.gitconfig </dev/null || echo "WARNING: Cannot chmod g+w the sshkeys, sshcerts and/or sshactive files" # Note time of last install -> etc/sshactive/_install +>etc/sshactive/_install [ -z "$dbonly" ] || exit 0 @@ -232,9 +232,9 @@ case "$sysname" in esac chrootsetup="$curdir/chrootsetup_$sysname.sh" -if ! [ -r "$chrootsetup" -a -s "$chrootsetup" ]; then +if ! [ -f "$chrootsetup" ] || ! [ -r "$chrootsetup" ] || ! [ -s "$chrootsetup" ]; then echo "*** Error: $chrootsetup not found" >&2 - echo "*** Error: creating a chroot for a `uname -s` system is not supported" >&2 + echo "*** Error: creating a chroot for a $(uname -s) system is not supported" >&2 exit 1 fi @@ -246,7 +246,7 @@ fi make_valid_dir() { _check="$(echo "$1" | tr -s /)" _check="${_check%/}" - [ -z "$_check" -o "$_check" = "/" ] && return 1 + [ -n "$_check" ] && [ "$_check" != "/" ] || return 1 if [ -z "$2" ]; then # must start with '/' case "$_check" in /*) :;; *) return 1; esac @@ -406,7 +406,7 @@ if [ -n "$GIROCCO_CHROOT_EXTRA_INSTALLS" ]; then fi # Note time of last jailsetup -> etc/sshactive/_jailsetup +>etc/sshactive/_jailsetup # Update permissions on the database files chown $cfg_cgi_user:$cfg_owning_group etc/passwd etc/group @@ -417,14 +417,14 @@ chown $cfg_mirror_user:$cfg_owning_group etc etc/girocco etc/girocco/.gitconfig if [ -n "$nosshdir" ]; then rm -rf etc/ssh ln -s . etc/ssh - [ ! -f /etc/moduli ] || { cp -p /etc/moduli etc/; chown 0:0 etc/moduli; } + ! [ -f /etc/moduli ] || { cp -p /etc/moduli etc/; chown 0:0 etc/moduli; } else - [ ! -e etc/ssh -o -d etc/ssh ] || rm -rf etc/ssh + ! [ -e etc/ssh ] || [ -d etc/ssh ] || rm -rf etc/ssh mkdir -p etc/ssh - [ ! -f /etc/ssh/moduli ] || { cp -p /etc/ssh/moduli etc/ssh/; chown 0:0 etc/ssh/moduli; } + ! [ -f /etc/ssh/moduli ] || { cp -p /etc/ssh/moduli etc/ssh/; chown 0:0 etc/ssh/moduli; } fi mkdir -p var/run/sshd -if [ ! -s etc/ssh/sshd_config ]; then +if ! [ -s etc/ssh/sshd_config ]; then cat >etc/ssh/sshd_config </dev/null; then bits="$cfg_rsakeylength" fi yes | ssh-keygen -b "$bits" -t rsa -N "" -C Girocco -f etc/ssh/ssh_host_rsa_key fi -if [ -z "$cfg_disable_dsa" -a ! -s etc/ssh/ssh_host_dsa_key ]; then +if [ -z "$cfg_disable_dsa" ] && ! [ -s etc/ssh/ssh_host_dsa_key ]; then # ssh-keygen can only create 1024 bit DSA keys yes | ssh-keygen -b 1024 -t dsa -N "" -C Girocco -f etc/ssh/ssh_host_dsa_key fi @@ -478,4 +478,4 @@ chown 0:0 etc/ssh/ssh_* etc/ssh/sshd_* echo "--- Add to your boot scripts: mount --bind $reporoot $chroot/$jailreporoot" echo "--- Add to your boot scripts: mount --bind /proc $chroot/proc" echo "--- Add to your syslog configuration: listening on socket $chroot/dev/log" -echo "--- To restart a running jail's sshd: sudo kill -HUP \`cat $chroot/var/run/sshd.pid\`" +echo "--- To restart a running jail's sshd: sudo kill -HUP \$(cat $chroot/var/run/sshd.pid)" diff --git a/jobd/combine-packs.sh b/jobd/combine-packs.sh index 511047f..db80c6e 100755 --- a/jobd/combine-packs.sh +++ b/jobd/combine-packs.sh @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Version 1.1.19 +# Version 1.1.20 USAGE=" printf '%s\n' path-to-pack[.idx|.pack] ... | @@ -78,7 +78,8 @@ Unless the --sort-tags-by-id option is used then perl will be used if available if perl does not appear to be available. A 40-char hex sha1 is taken to be objects/pack/pack-.idx relative to - the current git directory (as output by \`git rev-parse --git-dir\`). + the current git directory (as output by \`git rev-parse --git-dir\` or + by \`git rev-parse --git-common-dir\` for Git version 2.5 or later). If a does not exist and contains no '/' characters then it is retried as objects/pack/ instead. @@ -175,7 +176,7 @@ cleanup_on_exit() { ewf= [ -n "$td" ] && [ -e "$td/success" ] || ewf=1 [ -z "$td" ] || ! [ -e "$td" ] || rm -rf "$td" || : - [ -z "$gdo" -o -z "$zap" ] || command find "$gdo/pack" -maxdepth 1 -type f -name "*.$zap" -print0 | xargs -0 rm -f || : + [ -z "$gdo" ] || [ -z "$zap" ] || command find "$gdo/pack" -maxdepth 1 -type f -name "*.$zap" -print0 | xargs -0 rm -f || : [ -z "$ewf" ] || echo "combine_packs: exiting with failure" >&2 || : } @@ -190,7 +191,7 @@ die() { # In case we are in a sub shell force the entire command to exit # The trap on TERM will make sure cleanup still happens in this case extrapid= - [ -z "$td" ] || [ ! -s "$td/popid" ] || extrapid="$(cat "$td/popid")" || : + [ -z "$td" ] || ! [ -s "$td/popid" ] || extrapid="$(cat "$td/popid")" || : kill $cp_pid $extrapid || : exit 1 } @@ -289,12 +290,13 @@ while [ $# -ge 1 ]; do case "$1" in break ;; esac; done -[ -z "$ignoremiss$dozap" -o -z "$objectlist" ] || die "invalid options" +[ -z "$ignoremiss$dozap" ] || [ -z "$objectlist" ] || die "invalid options" # Always make sure we get the specified objects GIT_NO_REPLACE_OBJECTS=1 export GIT_NO_REPLACE_OBJECTS -gd="$(git rev-parse --git-dir)" +gd="$(git rev-parse --git-dir)" && [ -n "$gd" ] || + die "git rev-parse --git-dir failed" gv="$(git --version)" gv="${gv#[Gg]it version }" gv="${gv%%[!0-9.]*}" @@ -304,30 +306,39 @@ EOT : "${gvmaj:=0}" "${gvmin:=0}" "${gvpat:=0}" # git rev-parse added --no-walk support in 1.5.3 which is required # git cat-file added --batch-check support in 1.5.6 which is required -if [ $gvmaj -lt 1 ] || [ $gvmaj -eq 1 -a $gvmin -lt 5 ] || - [ $gvmaj -eq 1 -a $gvmin -eq 5 -a $gvpat -lt 6 ]; then +if [ $gvmaj -lt 1 ] || { [ $gvmaj -eq 1 ] && [ $gvmin -lt 5 ]; } || + { [ $gvmaj -eq 1 ] && [ $gvmin -eq 5 ] && [ $gvpat -lt 6 ]; }; then die "combine-packs requires at least Git version 1.5.6" fi +tmp="$gd" +gd="$(cd "$gd" && pwd -P)" || die "cd failed: $tmp" +# git rev-parse added --git-common-dir in 2.5 +if [ $gvmaj -gt 2 ] || { [ $gvmaj -eq 2 ] && [ $gvmin -ge 5 ]; }; then + # rev-parse --git-common-dir is broken and may give an + # incorrect result without a suitable current directory + tmp="$gd" + gd="$(cd "$gd" && cd "$(git rev-parse --git-common-dir)" && pwd -P)" && + [ -n "$gd" ] || + die "git rev-parse --git-common-dir failed from: $tmp" +fi # gcfbf is Git Cat-File --Batch-check=Format Option :) gcfbf= -if [ $gvmaj -gt 1 ] || [ $gvmaj -eq 1 -a $gvmin -gt 8 ] || - [ $gvmaj -eq 1 -a $gvmin -eq 8 -a $gvpat -ge 5 ] ; then +if [ $gvmaj -gt 1 ] || { [ $gvmaj -eq 1 ] && [ $gvmin -gt 8 ]; } || + { [ $gvmaj -eq 1 ] && [ $gvmin -eq 8 ] && [ $gvpat -ge 5 ]; }; then gcfbf='=%(objectname) %(objecttype)' fi # gcfbo is Git Cat-File --Buffer Option :) gcfbo= -if [ $gvmaj -gt 2 ] || [ $gvmaj -eq 2 -a $gvmin -ge 6 ]; then +if [ $gvmaj -gt 2 ] || { [ $gvmaj -eq 2 ] && [ $gvmin -ge 6 ]; }; then gcfbo=--buffer fi [ -n "$noperl" ] || perlbin="$(cmd_path perl)" && [ -n "$perlbin" ] || noperl=1 -tmp="$gd" -gd="$(cd "$gd" && pwd -P)" || die "cd failed: $tmp" if [ "${GIT_OBJECT_DIRECTORY+set}" = "set" ] && [ -z "$envok" ]; then # GIT_OBJECT_DIRECTORY may only be set to $gd/objects without --envok godok= - if [ -n "$GIT_OBJECT_DIRECTORY" ] && [ -d "$GIT_OBJECT_DIRECTORY" ] && \ - [ -d "$gd/objects" ] && godfp="$(cd "$GIT_OBJECT_DIRECTORY" && pwd -P)" && \ - gdofp="$(cd "$gd/objects" && pwd -P)" && [ -n "$godfp" ] && [ -n "$gdofp" ] && \ + if [ -n "$GIT_OBJECT_DIRECTORY" ] && [ -d "$GIT_OBJECT_DIRECTORY" ] && + [ -d "$gd/objects" ] && godfp="$(cd "$GIT_OBJECT_DIRECTORY" && pwd -P)" && + gdofp="$(cd "$gd/objects" && pwd -P)" && [ -n "$godfp" ] && [ -n "$gdofp" ] && [ "$gdofp" = "$godfp" ]; then godok=1 fi @@ -364,8 +375,9 @@ for arg; do nonopts=$(( $nonopts + 1 )) esac done -if [ $# -gt 0 ] && [ $nonopts -gt 1 ] || [ $nonopts -eq 1 -a -n "$lastargopt" ] || \ - [ $nonopts -eq 1 -a -z "$lastarg" ]; then +if [ $# -gt 0 ] && [ $nonopts -gt 1 ] || + { [ $nonopts -eq 1 ] && [ -n "$lastargopt" ]; } || + { [ $nonopts -eq 1 ] && [ -z "$lastarg" ]; }; then die "invalid options" fi if [ $nonopts -eq 1 ]; then @@ -374,16 +386,16 @@ else packbase="$gdo/pack/pack" fi pbd="$(dirname "$packbase")" -[ -e "$pbd" -a -d "$pbd" ] || die "no such directory: $packbase" +[ -e "$pbd" ] && [ -d "$pbd" ] || die "no such directory: $packbase" packbase="$(cd "$(dirname "$packbase")" && pwd -P)/$(basename "$packbase")" pbd="$(dirname "$packbase")" -[ -e "$pbd" -a -d "$pbd" ] || die "internal failure realpathing: $packbase" +[ -e "$pbd" ] && [ -d "$pbd" ] || die "internal failure realpathing: $packbase" packbasecheck="$packbase" case "$packbase" in "$gd"/?*) packbase="${packbase#$gd/}" esac [ $nonopts -eq 1 ] || packbasearg="$packbase" -[ -z "$zap" -o -n "$packbasearg" ] || die "--replace does not allow specifying pack-base" +[ -z "$zap" ] || [ -n "$packbasearg" ] || die "--replace does not allow specifying pack-base" if [ -n "$zap" ] && [ "$(dirname "$packbasecheck")" != "$gdo/pack" ] ; then die "--replace and pack base dir not /pack" >&2 fi @@ -418,17 +430,19 @@ get_pack_base() { _name="${_name%.pack}" ;; esac - if ! [ -e "$_name.idx" -o -e "$_name.pack" ]; then + if ! [ -e "$_name.idx" ] && ! [ -e "$_name.pack" ]; then case "$_name" in */*) :;; *) _name="$gdo/pack/$_name" esac fi - if ! [ -f "$_name.idx" -a -s "$_name.idx" -a -f "$_name.pack" -a -s "$_name.pack" ]; then + if ! [ -f "$_name.idx" ] || ! [ -s "$_name.idx" ] || + ! [ -f "$_name.pack" ] || ! [ -s "$_name.pack" ]; then [ -z "$ignoremiss" ] || return 0 die "no such pack found matching: $1" >&2 fi _name="$(cd "$(dirname "$_name")" && pwd -P)/$(basename "$_name")" - if ! [ -f "$_name.idx" -a -s "$_name.idx" -a -f "$_name.pack" -a -s "$_name.pack" ]; then + if ! [ -f "$_name.idx" ] || ! [ -s "$_name.idx" ] || + ! [ -f "$_name.pack" ] || ! [ -s "$_name.pack" ]; then die "internal failure realpathing: $1" >&2 fi _namecheck="$_name" @@ -446,7 +460,7 @@ get_pack_base() { # ALL the files to be renamed to the renamed name BEFORE removing anything move_aside() { for _f; do - ! [ -f "$_f" ] || \ + ! [ -f "$_f" ] || ln -f "$_f" "$(dirname "$_f")/old$(basename "$_f")" done for _f; do @@ -569,7 +583,8 @@ while read -r newpack; do fi [ -z "$names" ] || echo "$newpack" done -[ $? -eq 0 -a ! -e "$failed" -a -e "$listok" -a -e "$packok" ] || die "unspecified failure" +[ $? -eq 0 ] && ! [ -e "$failed" ] && [ -e "$listok" ] && [ -e "$packok" ] || + die "unspecified failure" if [ -n "$zap" ]; then find "$gdo/pack" -maxdepth 1 -type f -name "*.$zap" -print | while read -r remove; do diff --git a/jobd/gc.sh b/jobd/gc.sh index 06bf8ef..b500d4e 100755 --- a/jobd/gc.sh +++ b/jobd/gc.sh @@ -46,7 +46,7 @@ createlock() { sleep 30 fi for _try in p p n; do - if (set -C; > "$1.lock") 2>/dev/null; then + if (set -C; >"$1.lock") 2>/dev/null; then echo "$1.lock" return 0 fi @@ -207,7 +207,7 @@ combine_small_packs() { _didprogress=1 } _newp="$(list_packs $_lpo | combine_packs --names $noreusedeltaopt)" - _newc="$(echo $(echo "$_newp" | LC_ALL=C wc -w))" + _newc="$(( $(echo "$_newp" | LC_ALL=C wc -w) ))" # be paranoid and exit the loop if we haven't reduced the number of packs [ $_newc -lt $_cnt ] || break _minsmallpacks=2 @@ -257,7 +257,7 @@ pack_is_complete() { _headmatch="${3#ref:}" _headmatch="${_headmatch# }" _headmatchpat="$(echo "$_headmatch" | LC_ALL=C sed -e 's/\([.$]\)/\\\1/g')" - _headsha="$(LC_ALL=C grep -e "^$octet20 $_headmatchpat\$" < "$2" | \ + _headsha="$(LC_ALL=C grep -e "^$octet20 $_headmatchpat\$" <"$2" | LC_ALL=C cut -d ' ' -f 1)" case "$_headsha" in $octet20) :;; *) return 1 @@ -272,7 +272,7 @@ pack_is_complete() { mkdir pack_is_complete_test/refs mkdir pack_is_complete_test/objects mkdir pack_is_complete_test/objects/pack - echo "$_headsha" > pack_is_complete_test/HEAD + echo "$_headsha" >pack_is_complete_test/HEAD ln -s "$1" pack_is_complete_test/objects/pack/ ln -s "${1%.pack}.idx" pack_is_complete_test/objects/pack/ ln -s "$2" pack_is_complete_test/packed-refs @@ -298,7 +298,7 @@ lock_gc() { if [ "$(find "$lockf" -maxdepth 1 -mmin -720 -print 2>/dev/null)" ]; then apid= ahost= - read -r apid ahost ajunk < "$lockf" || : + read -r apid ahost ajunk <"$lockf" || : if [ "$apid" ] && [ "$ahost" ]; then if [ "$ahost" != "$hn" ] || pidactive "$apid"; then active=1 @@ -314,7 +314,7 @@ lock_gc() { echo >&2 "[$proj] gc already running on machine '$ahost' pid '$apid'" exit 1 fi - printf "%s %s" "$$" "$hn" > "$lockf.lock" + printf "%s %s" "$$" "$hn" >"$lockf.lock" chmod 0664 "$lockf.lock" mv -f "$lockf.lock" "$lockf" } @@ -345,17 +345,17 @@ make_repack_dir() { ln -s ../info repack/info ln -s ../objects repack/objects ln -s ../refs repack/refs - _lines=$(( $(LC_ALL=C wc -l < packed-refs) )) - sed 's, refs/, refs/!/,' < packed-refs > repack/packed-refs + _lines=$(( $(LC_ALL=C wc -l repack/packed-refs optref="$(git rev-list -n 1 --all 2>/dev/null)" || : if [ -n "$optref" ]; then - echo "$optref refs/tags/!" >> repack/packed-refs + echo "$optref refs/tags/!" >>repack/packed-refs _lines=$(( $_lines + 1 )) - echo "$optref" > repack/HEAD + echo "$optref" >repack/HEAD else - cat HEAD > repack/HEAD + cat HEAD >repack/HEAD fi - if [ $(LC_ALL=C wc -l < repack/packed-refs) -ne "$_lines" ]; then + if [ $(LC_ALL=C wc -l &2 "[$proj] error: make_repack_dir failed packed-refs line count sanity check" exit 1 fi @@ -385,10 +385,10 @@ remove_crud() { # this can happen when things are interrupted at just the wrong time. # Note that the objects/pack directory is created by git init and should # always exist. - find objects/pack -maxdepth 1 -type f -mmin +60 -name "pack-$octet20.?*" -print | \ - LC_ALL=C sed -e 's/^objects\/pack\/pack-//; s/\..*$//' | LC_ALL=C sort -u | \ + find objects/pack -maxdepth 1 -type f -mmin +60 -name "pack-$octet20.?*" -print | + LC_ALL=C sed -e 's/^objects\/pack\/pack-//; s/\..*$//' | LC_ALL=C sort -u | while read packsha; do - [ ! -e "objects/pack/pack-$packsha.pack" ] || continue + ! [ -e "objects/pack/pack-$packsha.pack" ] || continue rm -f "objects/pack/pack-$packsha".?* done @@ -483,7 +483,7 @@ mirror_url="$(get_mirror_url)" svn_mirror= ! is_svn_mirror_url "$mirror_url" || svn_mirror=1 gfi_mirror= -if [ -f gfi-packs -a -s gfi-packs ] && is_gfi_mirror_url "$mirror_url"; then +if [ -f gfi-packs ] && [ -s gfi-packs ] && is_gfi_mirror_url "$mirror_url"; then gfi_mirror=1 fi @@ -532,14 +532,14 @@ if [ -n "$isminigc" ]; then miniactive= if [ -f .svnpack ] && [ -n "$svn_mirror" ]; then miniactive=1 - progress "+ [$proj] mini garbage check (`date`)" + progress "+ [$proj] mini garbage check ($(date))" make_svn_pack fi if [ -z "$cfg_delay_gfi_redelta" ] && [ -n "$gfi_mirror" ]; then # $Girocco::Config::delay_gfi_redelta is false, force redeltification now if [ -z "$miniactive" ]; then miniactive=1 - progress "+ [$proj] mini garbage check (`date`)" + progress "+ [$proj] mini garbage check ($(date))" fi repack_gfi_packs fi @@ -550,7 +550,7 @@ if [ -n "$isminigc" ]; then if [ "${packcnt:-0}" -ge 10 ]; then if [ -z "$miniactive" ]; then miniactive=1 - progress "+ [$proj] mini garbage check (`date`)" + progress "+ [$proj] mini garbage check ($(date))" fi if [ -n "$gfi_mirror" ]; then repack_gfi_packs @@ -568,16 +568,16 @@ if [ -n "$isminigc" ]; then rm -f .delaygc git config --unset gitweb.lastgc rm -f "$lockf" - progress "- [$proj] mini garbage check triggering full gc too many packs (`date`)" + progress "- [$proj] mini garbage check triggering full gc too many packs ($(date))" exit 0 fi fi rm -f "$lockf" if [ -n "$miniactive" ]; then git update-server-info - progress "- [$proj] mini garbage check (`date`)" + progress "- [$proj] mini garbage check ($(date))" else - progress "= [$proj] mini garbage check nothing but crud removal to do (`date`)" + progress "= [$proj] mini garbage check nothing but crud removal to do ($(date))" fi exit 0 fi @@ -599,13 +599,13 @@ isfork= lastparentgcsecs= [ -z "$isfork" ] || lastparentgcsecs="$(config_get_date_seconds lastparentgc)" || : lastreceivesecs= -if lastreceivesecs="$(config_get_date_seconds lastreceive)" && \ - lastgcsecs="$(config_get_date_seconds lastgc)" && \ +if lastreceivesecs="$(config_get_date_seconds lastreceive)" && + lastgcsecs="$(config_get_date_seconds lastgc)" && [ $lastreceivesecs -lt $lastgcsecs ]; then # We've run gc since we last received, so maybe we can skip, # check if not fork or fork and lastparentgc < lastgc if [ -n "$isfork" ]; then - if [ -n "$lastparentgcsecs" ] && \ + if [ -n "$lastparentgcsecs" ] && [ $lastparentgcsecs -lt $lastgcsecs ]; then # We've run gc since our parent ran gc so we can skip skipgc=1 @@ -650,7 +650,7 @@ fi # Do not skip gc if the repo is dirty if [ -n "$skipgc" ] && ! is_dirty; then - progress "= [$proj] garbage check nothing but crud removal to do (`date`)" + progress "= [$proj] garbage check nothing but crud removal to do ($(date))" config_set lastgc "$gcstart" rm -f "$lockf" exit 0 @@ -672,7 +672,7 @@ if [ -n "$bumptime" ]; then gcstart="$(date "$datefmt")" fi -progress "+ [$proj] garbage check (`date`)" +progress "+ [$proj] garbage check ($(date))" newdeltas= [ -z "$alwaysredelta" ] || newdeltas=-f @@ -683,7 +683,7 @@ if [ -z "$newdeltas" ] && [ -n "$gfi_mirror" ]; then newdeltas=-f fi fi -if [ -z "$newdeltas" ] && [ -n "$noreusedeltaopt" ] && \ +if [ -z "$newdeltas" ] && [ -n "$noreusedeltaopt" ] && [ $(list_packs --exclude-no-idx --count-objects objects/pack) -le $var_redelta_threshold ]; then # There aren't enough objects to worry about so just redelta to get the best pack newdeltas=-f @@ -799,7 +799,7 @@ list_packs --exclude-no-idx objects/pack | xargs touch -c 2>/dev/null || : if [ -z "$newdeltas" ]; then bmpack="$(list_packs --exclude-no-bitmap --exclude-no-idx --max-matches 1 objects/pack)" [ -n "$bmpack" ] || bmpack="$(list_packs --exclude-no-idx --max-matches 1 --object-limit -1 --include-boundary objects/pack)" - if [ -n "$bmpack" ] && [ -f "$bmpack" -a -s "$bmpack" ]; then + if [ -n "$bmpack" ] && [ -f "$bmpack" ] && [ -s "$bmpack" ]; then sleep 1 touch -c "$bmpack" 2>/dev/null || : fi @@ -814,7 +814,7 @@ fi # alternates file, we disable writing bitmaps which avoids the warning and any # possibility of a client warning as well. nobm= -[ -z "$var_have_git_172" ] || ! [ -s objects/info/alternates ] || \ +[ -z "$var_have_git_172" ] || ! [ -s objects/info/alternates ] || nobm='-c repack.writebitmaps=false -c pack.writebitmaps=false' progress "~ [$proj] running full gc repack${nobm:+ (bitmaps disabled)}" cd repack @@ -823,14 +823,14 @@ cd repack git $nobm repack $packopts -A -d -l $quiet $newdeltas $@ cd .. rm -rf repack -[ ! -e .gc_failed ] || exit 1 +! [ -e .gc_failed ] || exit 1 # These, if they exist, are now meaningless and need to be removed rm -f gfi-packs .needsgc .svnpack .svnpackgc allpacks="$(echo objects/pack/pack-$octet20.pack)" curhead="$(cat HEAD)" pkrf= -[ ! -e packed-refs ] || pkrf=packed-refs -eval "reposizek=$(( $(echo 0 $(du -k $pkrf $allpacks 2>/dev/null | LC_ALL=C awk '{print $1}') | \ +! [ -e packed-refs ] || pkrf=packed-refs +eval "reposizek=$(( $(echo 0 $(du -k $pkrf $allpacks 2>/dev/null | LC_ALL=C awk '{print $1}') | LC_ALL=C sed -e 's/ / + /g') ))" git update-server-info # The -A option to `git repack` may have caused some loose objects to pop @@ -856,10 +856,10 @@ if has_forks "$proj"; then get_repo_list "$forkdir/[^/]*:" | while read fork; do # Ignore forks that do not exist or are symbolic links - [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \ + ! [ -L "$cfg_reporoot/$fork.git" ] && [ -d "$cfg_reporoot/$fork.git" ] || continue # Or do not have a non-zero length alternates file - [ -s "$cfg_reporoot/$fork.git/objects/info/alternates" ] || \ + [ -s "$cfg_reporoot/$fork.git/objects/info/alternates" ] || continue # Match objects in parent project for d in objects/$octet; do @@ -891,23 +891,23 @@ fi # alive by an unreachable object that refers to it that's not old enough to # be pruned yet. prunecmd='git prune --expire 1_day_ago' -[ -n "$show_progress" ] || \ +[ -n "$show_progress" ] || prunecmd="{ $prunecmd 2>&1 || touch .gc_failed; } | cat" progress "~ [$proj] pruning expired unreachable loose objects" eval "$prunecmd" -[ ! -e .gc_failed ] || exit 1 +! [ -e .gc_failed ] || exit 1 # darcs:// mirrors have a xxx.log file that will grow endlessly # if this is a mirror and the file exists, shorten it to 10000 lines # also take this opportunity to optimize the darcs repo -if [ ! -e .nofetch ] && [ -n "$cfg_mirror" ]; then +if ! [ -e .nofetch ] && [ -n "$cfg_mirror" ]; then url="$(config_get baseurl)" || : case "$url" in darcs://*) if [ -n "$cfg_mirror_darcs" ]; then url="${url%/}" basedarcs="$(basename "${url#darcs:/}")" if [ -f "$basedarcs.log" ]; then - tail -n 10000 "$basedarcs.log" > "$basedarcs.log.$$" + tail -n 10000 "$basedarcs.log" >"$basedarcs.log.$$" mv -f "$basedarcs.log.$$" "$basedarcs.log" fi if [ -d "$basedarcs.darcs" ]; then @@ -926,7 +926,7 @@ fi # Create a matching .bndl header file for the all-in-one pack we just created # but only if we're not a fork (otherwise the bundle would not be complete) # and we are running at least Git version 1.7.2 (pack_is_complete always fails otherwise) -if [ ! -s objects/info/alternates ] && [ -n "$var_have_git_172" ]; then +if ! [ -s objects/info/alternates ] && [ -n "$var_have_git_172" ]; then # There should only be one pack in $allpacks but if there was a # simultaneous push... # The one we just created will have a .idx and will NOT have a .keep @@ -937,13 +937,13 @@ if [ ! -s objects/info/alternates ] && [ -n "$var_have_git_172" ]; then [ -s "$pk" ] || continue pkbase="${pk%.pack}" [ -s "$pkbase.idx" ] || continue - [ ! -e "$pkbase.keep" ] || continue + ! [ -e "$pkbase.keep" ] || continue if pkhead="$(pack_is_complete "$PWD/$pk" "$PWD/packed-refs" "$curhead")"; then pkfound="$pkbase" break; fi done - if [ -n "$pkfound" -a -n "$pkhead" ]; then + if [ -n "$pkfound" ] && [ -n "$pkhead" ]; then { symref= case "$curhead" in "ref: refs/"?*|"ref:refs/"?*|"refs/"?*) @@ -953,14 +953,14 @@ if [ ! -s objects/info/alternates ] && [ -n "$var_have_git_172" ]; then bndlurl= [ -z "$cfg_httpbundleurl" ] || bndlurl=" url=$cfg_httpbundleurl/$proj.git/clone.bundle" echo "# v2 git bundle" - LC_ALL=C sed -ne "/^$octet20 refs\/[^ $tab]*\$/ p" < packed-refs + LC_ALL=C sed -ne "/^$octet20 refs\/[^ $tab]*\$/ p" "$pkbase.bndl" + } >"$pkbase.bndl" bndletag="$("$cfg_basedir/bin/rangecgi" --etag -m 1 "$pkbase.bndl" "$pkbase.pack")" || : bndlsha="$(printf '%s' "$bndletag" | git hash-object --stdin)" || : if [ -n "$bndletag" ]; then @@ -969,8 +969,8 @@ if [ ! -s objects/info/alternates ] && [ -n "$var_have_git_172" ]; then bndlshaprefix="${bndlsha%$bndlshatrailer}" bndlname="$(TZ=UTC date +%Y%m%d_%H%M%S)-${bndlshaprefix:-0}" [ -d bundles ] || mkdir bundles - echo "${pkbase#objects/pack/}.bndl" > "bundles/$bndlname" - echo "${pkbase#objects/pack/}.pack" >> "bundles/$bndlname" + echo "${pkbase#objects/pack/}.bndl" >"bundles/$bndlname" + echo "${pkbase#objects/pack/}.pack" >>"bundles/$bndlname" ln -s -f -n "$bndlname" bundles/latest esac fi @@ -986,4 +986,4 @@ config_set_raw girocco.reposizek "${reposizek:-0}" config_set lastgc "$gcstart" rm -f "$lockf" -progress "- [$proj] garbage check (`date`)" +progress "- [$proj] garbage check ($(date))" diff --git a/jobd/jobd.sh b/jobd/jobd.sh index 1abc41a..3735c7f 100755 --- a/jobd/jobd.sh +++ b/jobd/jobd.sh @@ -6,4 +6,3 @@ . @basedir@/shlib.sh exec "$cfg_basedir"/jobd/jobd.pl "$@" - diff --git a/jobd/update.sh b/jobd/update.sh index ed72584..b3e8cfa 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -44,7 +44,7 @@ git_darcs_fetch() ( --export-marks="$(pwd)/dfe-marks" \ --import-marks="$(pwd)/dfe-marks" "$1" 3>&- || _e1=$? echo $_e1 >&3 - } | \ + } | { _e2=0 git fast-import \ @@ -57,7 +57,7 @@ git_darcs_fetch() ( ) EOT exec 3>&- - [ "$_err1" = 0 -a "$_err2" = 0 ] + [ "$_err1" = 0 ] && [ "$_err2" = 0 ] return $? ) @@ -78,7 +78,7 @@ git_bzr_fetch() ( --export-marks="$(pwd)/bfe-marks" \ --import-marks="$(pwd)/bfe-marks" "$1" 3>&- || _e1=$? echo $_e1 >&3 - } | \ + } | { _e2=0 git fast-import \ @@ -91,7 +91,7 @@ git_bzr_fetch() ( ) EOT exec 3>&- - [ "$_err1" = 0 -a "$_err2" = 0 ] + [ "$_err1" = 0 ] && [ "$_err2" = 0 ] return $? ) @@ -116,9 +116,9 @@ if [ -e .nofetch ]; then progress "x [$proj] update disabled (.nofetch exists)" exit 0 fi -progress "+ [$proj] update (`date`)" +progress "+ [$proj] update ($(date))" -# Any pre-existing FETCH_HEAD from a previous fetch failed or not is garbage +# Any pre-existing FETCH_HEAD from a previous fetch, failed or not, is garbage rm -f FETCH_HEAD # A previous failed update attempt can leave a huge tmp_pack_XXXXXX file behind. @@ -158,9 +158,9 @@ esac bang echo "Mirroring from URL \"$url\"" bang echo "" statusok="$(git config --bool gitweb.statusupdates 2>/dev/null || echo true)" -mailaddrs='' -[ "$statusok" = "false" -o -z "$mail" ] || mailaddrs="$mail" -[ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] || \ +mailaddrs= +[ "$statusok" = "false" ] || [ -z "$mail" ] || mailaddrs="$mail" +[ -z "$cfg_admincc" ] || [ "$cfg_admincc" = "0" ] || [ -z "$cfg_admin" ] || if [ -z "$mailaddrs" ]; then mailaddrs="$cfg_admin"; else mailaddrs="$mailaddrs,$cfg_admin"; fi bang_eval "git for-each-ref --format '%(refname) %(objectname)' >.refs-temp" @@ -200,15 +200,15 @@ case "$url" in # We require svn info to succeed on the URL otherwise it's # simply not a valid URL and without using -s on the init it # will not otherwise be tested until the fetch - bang eval 'svn --non-interactive --username anonsvn --password anonsvn info "$svnurl" > /dev/null' + bang eval 'svn --non-interactive --username anonsvn --password anonsvn info "$svnurl" >/dev/null' bang mkdir svn-new-url GIT_DIR=svn-new-url bang git init --bare --quiet # We initially use -s for the init which will possibly shorten # the URL. However, the shortening can fail if a password is # not required for the longer version but is for the shorter, # so try again without -s if the -s version fails. - cmdstr='git svn init --username=anonsvn --prefix "" -s "$svnurl" < /dev/null > /dev/null 2>&1 || ' - cmdstr="$cmdstr"'git svn init --username=anonsvn --prefix "" "$svnurl" < /dev/null > /dev/null 2>&1' + cmdstr='git svn init --username=anonsvn --prefix "" -s "$svnurl" /dev/null 2>&1 || ' + cmdstr="$cmdstr"'git svn init --username=anonsvn --prefix "" "$svnurl" /dev/null 2>&1' GIT_DIR=svn-new-url bang eval "$cmdstr" gitsvnurl="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.url)" || : gitsvnfetch="$(GIT_DIR=svn-new-url git config --get svn-remote.svn.fetch)" || : @@ -227,15 +227,16 @@ case "$url" in gitsvnprefixold="${gitsvnprefixold%$gitsvnsuffixold}" git config --remove-section 'svn-remote.svnnew' 2>/dev/null || : git config 'svn-remote.svnnew.url' "$gitsvnurl" - { git config --get-regexp '^svn-remote\.svn\.' || :; } | \ - { while read sname sval; do + git config --get-regexp '^svn-remote\.svn\.' | + while read -r sname sval; do case "$sname" in svn-remote.svn.fetch|svn-remote.svn.branches|svn-remote.svn.tags) sname="${sname#svn-remote.svn.}" sval="${sval#$gitsvnprefixold}" bang git config --add "svn-remote.svnnew.$sname" "${gitsvnprefixnew}$sval" esac - done; } + done + test $? -eq 0 bang git config -f svn/.metadata svn-remote.svn.reposRoot "$gitsvnurl" bang git config --remove-section svn-remote.svn bang git config --rename-section svn-remote.svnnew svn-remote.svn @@ -253,7 +254,7 @@ case "$url" in >.svnpack sleep 1 fi - GIT_DIR=. bang git svn fetch --log-window-size=$var_log_window_size --username=anonsvn --quiet < /dev/null + GIT_DIR=. bang git svn fetch --log-window-size=$var_log_window_size --username=anonsvn --quiet .needsgc fi @@ -430,7 +431,7 @@ if [ -n "$refschanged" ]; then fi bang config_set lastchange "$(date '+%a, %d %b %Y %T %z')" bang_eval "git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \ - --count=1 refs/heads > info/lastactivity" + --count=1 refs/heads >info/lastactivity" ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || : # While unlikely, it is conceivable that several ref updates have occurred that # did not actually create any packs. In that case we could build up a large @@ -462,4 +463,4 @@ if is_banged; then bang_reset fi -progress "- [$proj] update (`date`)" +progress "- [$proj] update ($(date))" diff --git a/jobs/gitwebcache.sh b/jobs/gitwebcache.sh index 9b94c26..2bf6382 100755 --- a/jobs/gitwebcache.sh +++ b/jobs/gitwebcache.sh @@ -4,14 +4,17 @@ set -e -LOCK_FILE=/tmp/gitwebcache-$cfg_tmpsuffix.lock +LOCK_FILE="/tmp/gitwebcache-$cfg_tmpsuffix.lock" # Make sure we don't run twice. -if [ -s ${LOCK_FILE} ] && kill -0 $(cat ${LOCK_FILE}) 2>/dev/null; then - echo "Already running gitwebcache.sh (stuck?) with pid $(cat ${LOCK_FILE})" >&2 +if [ -s "$LOCK_FILE" ] && kill -0 "$(cat "$LOCK_FILE")" 2>/dev/null; then + echo "Already running gitwebcache.sh (stuck?) with pid $(cat "$LOCK_FILE")" >&2 exit 1 fi -echo $$ >${LOCK_FILE} +trap 'rm -f "$LOCK_FILE"' EXIT +trap 'exit 130' INT +trap 'exit 143' TERM +echo $$ >"$LOCK_FILE" cd "$cfg_cgiroot" @@ -23,4 +26,5 @@ REQUEST_METHOD=HEAD && export REQUEST_METHOD perl -e 'do "./gitweb.cgi"; END { fill_project_list_info([], "rebuild-cache") }' >/dev/null 2>&1 -rm ${LOCK_FILE} +rm -f "$LOCK_FILE" +trap - EXIT INT TERM diff --git a/jobs/updateweb.sh b/jobs/updateweb.sh index 0045f92..ad2f87b 100755 --- a/jobs/updateweb.sh +++ b/jobs/updateweb.sh @@ -4,30 +4,34 @@ set -e -REPO_DIR=/home/repo/repo -LOCK_FILE=/tmp/updateweb-$cfg_tmpsuffix.lock -REMOTE=origin -BRANCH=rorcz +REPO_DIR="/home/repo/repo" +LOCK_FILE="/tmp/updateweb-$cfg_tmpsuffix.lock" +REMOTE="origin" +BRANCH="rorcz" # Make sure we don't run twice. -if [ -s ${LOCK_FILE} ] && kill -0 $(cat ${LOCK_FILE}) 2>/dev/null; then - echo "Already running updateweb.sh (stuck?) with pid $(cat ${LOCK_FILE})" >&2 +if [ -s "$LOCK_FILE" ] && kill -0 "$(cat "$LOCK_FILE")" 2>/dev/null; then + echo "Already running updateweb.sh (stuck?) with pid $(cat "$LOCK_FILE")" >&2 exit 1 fi -echo $$ >${LOCK_FILE} +trap 'rm -f "$LOCK_FILE"' EXIT +trap 'exit 130' INT +trap 'exit 143' TERM +echo $$ >"$LOCK_FILE" -cd "${REPO_DIR}" +cd "$REPO_DIR" git fetch origin if [ -n "$(git rev-list $BRANCH..$REMOTE/$BRANCH)" ]; then case "$(git describe --always --dirty=..dirty)" in *..dirty) echo "updateweb.sh: refusing to update because worktree is dirty" >&2 - rm ${LOCK_FILE} + rm -f "$LOCK_FILE" exit 1 esac - git merge --ff-only $REMOTE/$BRANCH && \ - git submodule update --init --recursive && \ - make -s && \ + git merge --ff-only "$REMOTE/$BRANCH" && + git submodule update --init --recursive && + make -s && make install || : fi -rm ${LOCK_FILE} +rm -f "$LOCK_FILE" +trap - EXIT INT TERM diff --git a/make-apache-conf.sh b/make-apache-conf.sh index 6c72f4d..573ef3b 100755 --- a/make-apache-conf.sh +++ b/make-apache-conf.sh @@ -16,7 +16,7 @@ trap 'exit 143' TERM __girocco_conf="$GIROCCO_CONF" [ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config" -perl -I. -M"$__girocco_conf" -- - apache.conf.in > apache.conf.$$ <<'EOT' +perl -I. -M"$__girocco_conf" -- - apache.conf.in >apache.conf.$$ <<'EOT' #line 21 "make-apache-conf.sh" use strict; use warnings; diff --git a/shlib.sh b/shlib.sh index 35fdf09..88a3e1e 100644 --- a/shlib.sh +++ b/shlib.sh @@ -9,8 +9,8 @@ octet4="$octet$octet$octet$octet" octet19="$octet4$octet4$octet4$octet4$octet$octet$octet" octet20="$octet4$octet4$octet4$octet4$octet4" nullsha="0000000000000000000000000000000000000000" -# tab -tab="$(printf '\t')" +# tab (single \t between single quotes) +tab=' ' # set a sane umask that never excludes any user or group permissions umask $(printf '0%03o' $(( $(umask) & ~0770 )) ) @@ -26,7 +26,7 @@ vcmp() { while _a="${1%%.*}" _b="${2%%.*}" - [ -n "$_a" -o -n "$_b" ] + [ -n "$_a" ] || [ -n "$_b" ] do if [ "${_a:-0}" -lt "${_b:-0}" ]; then echo -1 @@ -99,7 +99,7 @@ get_girocco_config_var_list() ( eval "$_cfg_vars" printf '%s\n' "$_cfg_vars" printf 'var_group=%s\n' "${cfg_owning_group:-$(id -gn)}" - _gver="$("$cfg_git_bin" version 2>/dev/null | \ + _gver="$("$cfg_git_bin" version 2>/dev/null | LC_ALL=C sed -ne 's/^[^0-9]*\([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*$/\1/p')" printf 'var_git_ver=%s\n' "$_gver" printf 'var_git_exec_path="%s"\n' "$("$cfg_git_bin" --exec-path 2>/dev/null)" @@ -124,7 +124,7 @@ get_girocco_config_var_list() ( printf "var_redelta_threshold=%s\n" \ "$(perl -I@basedir@ $__girocco_extrainc -M$__girocco_conf \ -MGirocco::Util -e 'print calc_redeltathreshold')" - if [ -n "$cfg_upload_pack_window" ] && [ "$cfg_upload_pack_window" -ge 2 ] && \ + if [ -n "$cfg_upload_pack_window" ] && [ "$cfg_upload_pack_window" -ge 2 ] && [ "$cfg_upload_pack_window" -le 50 ]; then printf "var_upload_window=%s\n" "$cfg_upload_pack_window" else @@ -132,13 +132,13 @@ get_girocco_config_var_list() ( fi printf 'var_log_window_size=%s\n' "${cfg_svn_log_window_size:-250}" # We parse the output of `locale -a` and select a suitable UTF-8 locale. - _guess_locale="$(locale -a | LC_ALL=C grep -viE '^(posix|c)(\..*)?$' | \ - LC_ALL=C grep -iE '\.utf-?8$' | LC_ALL=C sed -e 's/\.[Uu][Tt][Ff]-*8$//' | \ - LC_ALL=C sed -e '/en_US/ s/^/0 /; /en_US/ !s/^/1 /' | LC_ALL=C sort | \ + _guess_locale="$(locale -a | LC_ALL=C grep -viE '^(posix|c)(\..*)?$' | + LC_ALL=C grep -iE '\.utf-?8$' | LC_ALL=C sed -e 's/\.[Uu][Tt][Ff]-*8$//' | + LC_ALL=C sed -e '/en_US/ s/^/0 /; /en_US/ !s/^/1 /' | LC_ALL=C sort | head -n 1 | LC_ALL=C cut -d ' ' -f 2)" [ -z "$_guess_locale" ] || printf 'var_utf8_locale=%s.UTF-8\n' "$_guess_locale" # On some broken platforms running xargs without -r and empty input runs the command - printf 'var_xargs_r=%s\n' "$(: | command xargs echo -r)" + printf 'var_xargs_r=%s\n' "$( .banglog - echo "" >> .banglog - echo "$bang_cmd failed with error code $bang_errcode" >> .banglog + >.banged + cat "$bang_log" >.banglog + echo "" >>.banglog + echo "$bang_cmd failed with error code $bang_errcode" >>.banglog if [ -n "$show_progress" ]; then echo "" echo "$bang_cmd failed with error code $bang_errcode" @@ -411,19 +411,18 @@ bang_failed() { rm -f .bangagain fi bangcount="$(git config --int girocco.bang.count 2>/dev/null)" || : - : ${bangcount:=0} - bangcount=$(( $bangcount + 1 )) + bangcount=$(( ${bangcount:-0} + 1 )) git config --int girocco.bang.count $bangcount if [ $bangcount -eq 1 ]; then git config girocco.bang.firstfail "$(TZ=UTC date "+%Y-%m-%d %T UTC")" fi - if [ $bangcount -ge $cfg_min_mirror_failure_message_count ] && \ - [ "$(git config --bool girocco.bang.messagesent 2>/dev/null || :)" != "true" ] && \ + if [ $bangcount -ge $cfg_min_mirror_failure_message_count ] && + [ "$(git config --bool girocco.bang.messagesent 2>/dev/null || :)" != "true" ] && ! check_interval "girocco.bang.firstfail" $cfg_min_mirror_failure_message_interval; then bangmailok="$(git config --bool gitweb.statusupdates 2>/dev/null || echo true)" - bangaddrs='' - [ "$bangmailok" = "false" -o -z "$mail" ] || bangaddrs="$mail" - [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] || + bangaddrs= + [ "$bangmailok" = "false" ] || [ -z "$mail" ] || bangaddrs="$mail" + [ -z "$cfg_admincc" ] || [ "$cfg_admincc" = "0" ] || [ -z "$cfg_admin" ] || if [ -z "$bangaddrs" ]; then bangaddrs="$cfg_admin"; else bangaddrs="$bangaddrs,$cfg_admin"; fi rsubj= [ $bangcount -le 1 ] || rsubj=" repeatedly" @@ -446,8 +445,8 @@ bang_failed() { git config --bool girocco.bang.messagesent true fi bangthrottle= - [ $bangcount -lt 15 ] || \ - check_interval "girocco.bang.firstfail" $(( $cfg_min_mirror_interval * 3 / 2 )) || \ + [ $bangcount -lt 15 ] || + check_interval "girocco.bang.firstfail" $(( $cfg_min_mirror_interval * 3 / 2 )) || bangthrottle=1 bang_trap $bangthrottle [ -n "$bang_errcode" ] && [ "$bang_errcode" != "0" ] || bang_errcode=1 @@ -495,7 +494,7 @@ was_banged_message_sent() { # Progress report - if show_progress is set, shows the given message. progress() { - [ ! -n "$show_progress" ] || echo "$@" + [ -z "$show_progress" ] || echo "$*" } # Project config accessors; must be run in project directory @@ -540,13 +539,13 @@ is_root() { is_git_dir() { # Just like Git's test except we ignore GIT_OBJECT_DIRECTORY # And we are slightly more picky (must be refs/.+ not refs/.*) - [ -d "$1/objects" -a -x "$1/objects" ] || return 1 - [ -d "$1/refs" -a -x "$1/refs" ] || return 1 + [ -d "$1/objects" ] && [ -x "$1/objects" ] || return 1 + [ -d "$1/refs" ] && [ -x "$1/refs" ] || return 1 if [ -L "$1/HEAD" ]; then _hr="$(readlink "$1/HEAD")" case "$_hr" in "refs/"?*) :;; *) return 1;; esac fi - [ -f "$1/HEAD" -a -r "$1/HEAD" ] || return 1 + [ -f "$1/HEAD" ] && [ -r "$1/HEAD" ] || return 1 read -r _hr <"$1/HEAD" || return 1 case "$_hr" in $octet20 | ref:refs/?*) @@ -576,7 +575,7 @@ has_forks() { [ -n "$_prj" ] || return 1 [ -d "$cfg_reporoot/$_prj" ] || return 1 is_git_dir "$cfg_reporoot/$_prj.git" || return 1 - test $(get_repo_list "$_prj/[^/][^/]*:" | LC_ALL=C wc -l) -gt 0 + test $(get_repo_list "$_prj/[^/:][^/:]*:" | LC_ALL=C wc -l) -gt 0 } # returns empty string and error for empty string otherwise one of @@ -651,7 +650,7 @@ is_svn_mirror_url() { get_mirror_url() { _gitdir="${1:-.}" # always return empty for non-mirrors - [ ! -e "$_gitdir/.nofetch" ] || return 0 + ! [ -e "$_gitdir/.nofetch" ] || return 0 _url="$(GIT_DIR="$_gitdir" config_get baseurl 2>/dev/null)" || : _url="${_url##* }" [ -n "$_url" ] || return 1 @@ -666,6 +665,7 @@ get_mirror_url() { # automatically strips any leading "disabled " prefix before testing get_mirror_type() { _url="$(get_mirror_url "$@")" || return 1 + [ -n "$_url" ] || return 0 get_url_mirror_type "$_url" } @@ -742,7 +742,7 @@ git_hg_fetch() ( set_utf8_locale _python="${PYTHON:-python}" rm -f hg2git-marks.old hg2git-marks.new - if [ -f hg2git-marks -a -s hg2git-marks ]; then + if [ -f hg2git-marks ] && [ -s hg2git-marks ]; then LC_ALL=C sed 's/^:\([^ ][^ ]*\) \([^ ][^ ]*\)$/\2 \1/' hg2git-marks.old - if [ -n "$var_have_git_171" ] && \ + if [ -n "$var_have_git_171" ] && git rev-parse --quiet --verify refs/notes/hg >/dev/null; then - if [ -z "$var_have_git_185" ] || \ + if [ -z "$var_have_git_185" ] || ! LC_ALL=C cmp -s hg2git-marks hg2git-marks.old; then _nm='hg-fast-export' GIT_AUTHOR_NAME="$_nm" @@ -792,7 +792,7 @@ git_hg_fetch() ( [ -z "$_af" ] || _cmd="$_cmd"' --authors "$_af"' eval "$_cmd" 3>&- || _e1=$? echo $_e1 >&3 - } | \ + } | { _e2=0 git fast-import \ @@ -805,9 +805,9 @@ git_hg_fetch() ( ) EOT exec 3>&- - [ "$_err1" = 0 -a "$_err2" = 0 ] || return 1 + [ "$_err1" = 0 ] && [ "$_err2" = 0 ] || return 1 mv -f hg2git-marks.new hg2git-marks rm -f hg2git-marks.old - git for-each-ref --format='%(refname) %(objectname)' refs/heads | \ + git for-each-ref --format='%(refname) %(objectname)' refs/heads | LC_ALL=C sed -e 's,^refs/heads/,:,' >hg2git-heads ) diff --git a/taskd/clone.sh b/taskd/clone.sh index ff87075..b6af8d6 100755 --- a/taskd/clone.sh +++ b/taskd/clone.sh @@ -24,7 +24,7 @@ git_darcs_fetch() ( "$cfg_basedir"/bin/darcs-fast-export \ --export-marks="$(pwd)/dfe-marks" "$1" 3>&- || _e1=$? echo $_e1 >&3 - } | \ + } | { _e2=0 git fast-import \ @@ -36,7 +36,7 @@ git_darcs_fetch() ( ) EOT exec 3>&- - [ "$_err1" = 0 -a "$_err2" = 0 ] + [ "$_err1" = 0 ] && [ "$_err2" = 0 ] return $? ) @@ -56,7 +56,7 @@ git_bzr_fetch() ( bzr fast-export --plain \ --export-marks="$(pwd)/bfe-marks" "$1" 3>&- || _e1=$? echo $_e1 >&3 - } | \ + } | { _e2=0 git fast-import \ @@ -68,7 +68,7 @@ git_bzr_fetch() ( ) EOT exec 3>&- - [ "$_err1" = 0 -a "$_err2" = 0 ] + [ "$_err1" = 0 ] && [ "$_err2" = 0 ] return $? ) @@ -77,9 +77,9 @@ send_clone_failed() { # We must now close the .clonelog file that is open on stdout and stderr exec >/dev/null 2>&1 failaddrs="$(config_get owner)" || : - [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] || \ + [ -z "$cfg_admincc" ] || [ "$cfg_admincc" = "0" ] || [ -z "$cfg_admin" ] || if [ -z "$failaddrs" ]; then failaddrs="$cfg_admin"; else failaddrs="$failaddrs,$cfg_admin"; fi - [ -z "$failaddrs" ] || \ + [ -z "$failaddrs" ] || { cat </dev/null)" + config set owner "$(ls -ldH "${url#file://}" 2>/dev/null | awk '{print $3}')" fi mailaddrs="$(config_get owner)" || : -[ -z "$cfg_admin" ] || \ +[ -z "$cfg_admin" ] || if [ -z "$mailaddrs" ]; then mailaddrs="$cfg_admin"; else mailaddrs="$mailaddrs,$cfg_admin"; fi # Make sure we don't get any unwanted loose objects @@ -225,15 +225,15 @@ case "$url" in # We require svn info to succeed on the URL otherwise it's # simply not a valid URL and without using -s on the init it # will not otherwise be tested until the fetch - svn --non-interactive --username anonsvn --password anonsvn info "$svnurl" > /dev/null + svn --non-interactive --username anonsvn --password anonsvn info "$svnurl" >/dev/null # We initially use -s for the init which will possibly shorten # the URL. However, the shortening can fail if a password is # not required for the longer version but is for the shorter, # so try again without -s if the -s version fails. # We must use GIT_DIR=. here or ever so "helpful" git-svn will # create a .git subdirectory! - GIT_DIR=. git svn init --username=anonsvn --prefix "" -s "$svnurl" < /dev/null || \ - GIT_DIR=. git svn init --username=anonsvn --prefix "" "$svnurl" < /dev/null + GIT_DIR=. git svn init --username=anonsvn --prefix "" -s "$svnurl" /dev/null || :; } | \ + svn --non-interactive --username anonsvn --password anonsvn ls "$gitsvnurl/${gitsvnprefix}" 2>/dev/null | { while read file; do case $file in # skip the already-handled standard ones and any with a space or tab *' '*|*' '*) :;; @@ -277,6 +277,7 @@ case "$url" in git config --unset svn-remote.svn.tags git config --replace-all svn-remote.svn.fetch ':refs/heads/master' fi; } + test $? -eq 0 # remember the starting time so we can easily combine fetched loose objects # we sleep for 1 second after creating .svnpack to make sure all objects are newer if ! [ -e .svnpack ]; then @@ -285,7 +286,7 @@ case "$url" in sleep 1 fi # Again, be careful to use GIT_DIR=. here or else new .git subdirectory! - GIT_DIR=. git svn fetch --log-window-size=$var_log_window_size --username=anonsvn --quiet < /dev/null + GIT_DIR=. git svn fetch --log-window-size=$var_log_window_size --username=anonsvn --quiet .refs-temp 2>.pkts-temp || \ + GIT_SSL_NO_VERIFY=1 GIT_TRACE_PACKET=1 git ls-remote origin >.refs-temp 2>.pkts-temp || { # Since everything was redirected, on failure there'd be no output, # so let's make some failure output @@ -369,16 +370,18 @@ case "$url" in if [ -z "$headref" ] || [ "$ref" = "${symrefcap:-refs/heads/master}" ]; then headref="$ref" fi - [ "$headref" = "${symrefcap:-refs/heads/master}" -a $matchcnt -gt 1 ] && break + if [ "$headref" = "${symrefcap:-refs/heads/master}" ] && [ $matchcnt -gt 1 ]; then + break + fi done <<-EOT - $(LC_ALL=C grep -E "^$head[ $tab]+refs/heads/[^ $tab]+\$" <.refs-temp | \ + $(LC_ALL=C grep -E "^$head[ $tab]+refs/heads/[^ $tab]+\$" <.refs-temp | LC_ALL=C awk '{print $2}') EOT # Warn if there was more than one match and $symrefcap is empty # or $symrefcap is not the same as $headref since our choice might # differ from the source repository's HEAD - if [ $matchcnt -ge 1 -a "$symrefcap" != "$headref" ] && \ - [ -n "$symrefcap" -o $matchcnt -gt 1 ]; then + if [ $matchcnt -ge 1 ] && [ "$symrefcap" != "$headref" ] && + { [ -n "$symrefcap" ] || [ $matchcnt -gt 1 ]; }; then showheadwarn=1 fi fi @@ -394,9 +397,9 @@ case "$url" in if [ -z "$headref" ] || [ "$ref" = "refs/heads/master" ]; then headref="$ref" fi - [ "$headref" = "refs/heads/master" ] && break + [ "$headref" != "refs/heads/master" ] || break done <<-EOT - $(LC_ALL=C grep -E "^$octet20[ $tab]+refs/heads/[^ $tab]+\$" <.refs-temp | \ + $(LC_ALL=C grep -E "^$octet20[ $tab]+refs/heads/[^ $tab]+\$" <.refs-temp | LC_ALL=C awk '{print $2}') EOT fi @@ -410,7 +413,7 @@ case "$url" in [ "$(git config --bool fetch.prune 2>/dev/null || :)" != "false" ] || pruneopt= # remember the starting time so we can easily detect new packs for fast-import mirrors # we sleep for 1 second after creating .gfipack to make sure all packs are newer - if is_gfi_mirror_url "$url" && [ ! -e .gfipack ]; then + if is_gfi_mirror_url "$url" && ! [ -e .gfipack ]; then rm -f .gfipack >.gfipack sleep 1 @@ -446,7 +449,7 @@ git pack-refs --all git config gitweb.lastreceive "$(date '+%a, %d %b %Y %T %z')" git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \ - --count=1 refs/heads > info/lastactivity || : + --count=1 refs/heads >info/lastactivity || : ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || : # Don't leave a multi-megabyte useless FETCH_HEAD behind @@ -472,7 +475,7 @@ emptynote=" WARNING: You have mirrored an empty repository. " headnote= -[ -n "$showheadwarn" -a -n "$headref" ] && +[ -z "$showheadwarn" ] || [ -z "$headref" ] || headnote=" NOTE: HEAD has been set to a symbolic ref to \"$headref\". Use the \"Project settings\" link to choose a different HEAD symref. diff --git a/taskd/mail.sh b/taskd/mail.sh index 7b12c4a..b7ae6ca 100755 --- a/taskd/mail.sh +++ b/taskd/mail.sh @@ -172,9 +172,9 @@ read_tag_fields() prep_for_email() { # --- Arguments - oldrev=$(git rev-parse --revs-only "$1" --) - newrev=$(git rev-parse --revs-only "$2" --) - [ "$oldrev" != "$newrev" ] || return 1 + oldrev="$(git rev-parse --revs-only "$1" --)" || : + newrev="$(git rev-parse --revs-only "$2" --)" || : + [ -n "$oldrev" ] && [ -n "$newrev" ] && [ "$oldrev" != "$newrev" ] || return 1 scratch="${newrev#????????????????}" newrev16="${newrev%$scratch}" refname="$3" @@ -184,11 +184,11 @@ prep_for_email() # 0000->1234 (create) # 1234->2345 (update) # 2345->0000 (delete) - if LC_ALL=C expr "$oldrev" : '0*$' >/dev/null + if [ -n "$oldrev" ] && [ "${oldrev#*[!0]}" = "$oldrev" ] then change_type="create" else - if LC_ALL=C expr "$newrev" : '0*$' >/dev/null + if [ -n "$newrev" ] && [ "${newrev#*[!0]}" = "$newrev" ] then change_type="delete" else @@ -197,8 +197,8 @@ prep_for_email() fi # --- Get the revision types - newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) + newrev_type="$(git cat-file -t "$newrev" 2>/dev/null)" || : + oldrev_type="$(git cat-file -t "$oldrev" 2>/dev/null)" || : case "$change_type" in create|update) rev="$newrev" @@ -216,38 +216,38 @@ prep_for_email() # - tracking branch # - unannoted tag # - annotated tag - case "$refname","$rev_type" in - refs/tags/*,commit) + case "$refname:$rev_type" in + refs/tags/*:commit) # un-annotated tag refname_type="tag" - short_refname=${refname#refs/tags/} + short_refname="${refname#refs/tags/}" ;; - refs/tags/*,tag) + refs/tags/*:tag) # annotated tag refname_type="annotated tag" - short_refname=${refname#refs/tags/} + short_refname="${refname#refs/tags/}" # change recipients if [ -n "$announcerecipients" ]; then recipients="$announcerecipients" fi ;; - refs/heads/*,commit|refs/heads/*,tag) + refs/heads/*:commit|refs/heads/*:tag) # branch refname_type="branch" - short_refname=${refname#refs/heads/} + short_refname="${refname#refs/heads/}" ;; - refs/remotes/*,commit) + refs/remotes/*:commit|refs/remotes/*:tag) # tracking branch refname_type="tracking branch" - short_refname=${refname#refs/remotes/} + short_refname="${refname#refs/remotes/}" echol >&2 "*** Push-update of tracking branch, $refname" echol >&2 "*** - no email generated." return 1 ;; - refs/mob/*,commit|refs/mob/*,tag) + refs/mob/*:commit|refs/mob/*:tag) # personal mob ref refname_type="personal mob ref" - short_refname=${refname#refs/mob/} + short_refname="${refname#refs/mob/}" echol >&2 "*** Push-update of personal mob ref, $refname" echol >&2 "*** - no email generated." return 1 @@ -264,13 +264,13 @@ prep_for_email() if [ -z "$recipients" ]; then case "$refname_type" in "annotated tag") - config_name="hooks.announcelist" + config_name="neither hooks.announcelist nor hooks.mailinglist is" ;; *) - config_name="hooks.mailinglist" + config_name="hooks.mailinglist is not" ;; esac - echol >&2 "*** $config_name is not set so no email will be sent" + echol >&2 "*** $config_name set so no email will be sent" echol >&2 "*** for $refname update $oldrev->$newrev" return 1 fi @@ -301,9 +301,9 @@ generate_email() # Email parameters # The email subject will contain the best description of the ref # that we can build from the parameters - describe=$(git describe $rev 2>/dev/null) + describe="$(git describe $rev 2>/dev/null)" || : if [ -z "$describe" ]; then - describe=$rev + describe="$rev" fi generate_email_header @@ -384,9 +384,9 @@ generate_create_branch_email() echol "those revisions in full, below." echol "" - echol $LOGBEGIN + echol "$LOGBEGIN" show_new_revisions - echol $LOGEND + echol "$LOGEND" # If any revisions were shown by show_new_revisions then we show # a diffstat from the last shown revisions's parent (or the empty tree @@ -396,13 +396,13 @@ generate_create_branch_email() # the last shown revision has parents. # This is to show the truth of what happened in this change. - if [ -n "$LAST_SHOWN_REVISION" ] && [ -n "$LAST_SHOWN_NPARENTS" ] && [ -n "$LAST_SHOWN_NBOUNDARY" ] && \ + if [ -n "$LAST_SHOWN_REVISION" ] && [ -n "$LAST_SHOWN_NPARENTS" ] && [ -n "$LAST_SHOWN_NBOUNDARY" ] && [ "$LAST_SHOWN_NPARENTS" -le 1 ] && [ "$LAST_SHOWN_NBOUNDARY" -le "$LAST_SHOWN_NPARENTS" ]; then if [ "$LAST_SHOWN_NPARENTS" -eq 0 ]; then # Note that since Git 1.5.5 the empty tree object is ALWAYS available # whether or not it's actually present in the repository. - # Set oldrev to the result of $(git hash-object -t tree --stdin < /dev/null) + # Set oldrev to the result of $(git hash-object -t tree --stdin /dev/null) + prevtag="$(git describe --abbrev=0 "$peeledobject^" 2>/dev/null)" || : if [ -n "$prevtag" ]; then echol " replaces $prevtag" @@ -683,15 +683,15 @@ generate_atag_email() echol " on $taggerdate" echol "" - echol $LOGBEGIN + echol "$LOGBEGIN" while echol "tag $tagrev" echol "Tag: $tagtag" echol "Object: $tagobject ($tagtype)" - [ -z "$taggername" ] || \ + [ -z "$taggername" ] || echol "Tagger: $taggername" - [ -z "$taggerdate" ] || \ + [ -z "$taggerdate" ] || echol "Date: $taggerdate" echol "URL: <$projurl/$tagrev16>" echol "" @@ -714,11 +714,11 @@ generate_atag_email() # performed on them if [ -n "$prevtag" ]; then # Show changes since the previous release - git shortlog "$prevtag..$newrev" + git shortlog "$prevtag..$newrev" -- else # No previous tag, show all the changes since time # began - git shortlog $newrev + git shortlog "$newrev" -- fi ;; *) @@ -727,7 +727,7 @@ generate_atag_email() ;; esac - echol $LOGEND + echol "$LOGEND" } # @@ -737,9 +737,9 @@ generate_delete_atag_email() { echol " was $oldrev" echol "" - echol $LOGBEGIN - git diff-tree --no-color --date=$datefmt -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline $oldrev - echol $LOGEND + echol "$LOGBEGIN" + git diff-tree --no-color --date="$datefmt" -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline "$oldrev" -- + echol "$LOGEND" } # --------------- General references @@ -783,20 +783,20 @@ generate_general_email() echol "" if [ "$newrev_type" = "commit" ]; then - if [ -n "$(git rev-list --no-walk --merges $newrev)" ]; then + if [ -n "$(git rev-list --no-walk --merges "$newrev" --)" ]; then pfmt12="$pfmt1$pfmt1m$pfmt2" else pfmt12="$pfmt1$pfmt2" fi - echol $LOGBEGIN - git diff-tree --no-color --date=$datefmt --root -s --always --encoding=UTF-8 --format="$pfmt12$projurlesc/$newrev16$pfmt3" --abbrev=$habbr $newrev - echol $LOGEND + echol "$LOGBEGIN" + git diff-tree --no-color --date="$datefmt" --root -s --always --encoding=UTF-8 --format="$pfmt12$projurlesc/$newrev16$pfmt3" --abbrev=$habbr "$newrev" -- + echol "$LOGEND" else # What can we do here? The tag marks an object that is not # a commit, so there is no log for us to display. It's # probably not wise to output git cat-file as it could be a # binary blob. We'll just say how big it is - echol "$newrev is a $newrev_type, and is $(git cat-file -s $newrev) bytes long." + echol "$newrev is a $newrev_type, and is $(git cat-file -s "$newrev") bytes long." fi } @@ -807,9 +807,9 @@ generate_delete_general_email() { echol " was $oldrev" echol "" - echol $LOGBEGIN - git diff-tree --no-color --date=$datefmt -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline $oldrev - echol $LOGEND + echol "$LOGBEGIN" + git diff-tree --no-color --date="$datefmt" -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8 --pretty=oneline "$oldrev" -- + echol "$LOGEND" } @@ -841,10 +841,10 @@ show_new_revisions() if [ "$change_type" = create ] then # Show all revisions exclusive to this (new) branch. - revspec=$newrev + revspec="$newrev" else # Branch update; show revisions not part of $oldrev. - revspec=$oldrev..$newrev + revspec="$oldrev..$newrev" fi if [ "${MAIL_SH_OTHER_BRANCHES+set}" = "set" ]; then @@ -862,7 +862,7 @@ show_new_revisions() fi # if [ -z "$custom_showrev" ] # then -# git rev-list --pretty --stdin $revspec +# git rev-list --pretty --stdin "$revspec" -- # else while read onerev mark pcnt && [ -n "$onerev" ] && [ -n "$mark" ] && [ -n "$pcnt" ] do @@ -877,7 +877,7 @@ show_new_revisions() if [ -n "$custom_showrev" ]; then eval $(printf "$custom_showrev" $onerev) else - if [ ${summaryonly:-false} = false ]; then + if [ "${summaryonly:-false}" = "false" ]; then if [ ${pcnt:-1} -gt 1 ]; then opts="-p --cc" pfmt12="$pfmt1$pfmt1m$pfmt2" @@ -896,14 +896,14 @@ show_new_revisions() fi scratch="${onerev#????????????????}" onerev16="${onerev%$scratch}" - git diff-tree --no-color --date=$datefmt $opts --always --encoding=UTF-8 --format="$pfmt12$projurlesc/$onerev16$pfmt3" --abbrev=$habbr -B -C --root $onerev + git diff-tree --no-color --date="$datefmt" $opts --always --encoding=UTF-8 --format="$pfmt12$projurlesc/$onerev16$pfmt3" --abbrev=$habbr -B -C --root "$onerev" -- echo fi done </dev/null || :)" != "true" ] || reverseopt=--reverse -announcerecipients=$(git config hooks.announcelist) -envelopesender=$(git config hooks.envelopesender) -emailprefix=$(git config hooks.emailprefix || echol "[$cfg_name] ") -custom_showrev=$(git config hooks.showrev) +announcerecipients="$(git config hooks.announcelist)" || : +envelopesender="$(git config hooks.envelopesender)" || : +emailprefix="$(git config hooks.emailprefix || echol "[$cfg_name] ")" || : +custom_showrev="$(git config hooks.showrev)" || : # --- Main loop # Allow dual mode: run from the command line just like the update hook, or # if no arguments are given then run as a hook script # If --stdout is first argument send all output there instead (handled above) # Optional 4th (projectname), 5th (sender) and 6th (extra header) arguments -if [ -n "$1" -a -n "$2" -a -n "$3" ]; then +if [ -n "$1" ] && [ -n "$2" ] && [ -n "$3" ]; then # Handle a single update rather than a batch on stdin # Output will still be sent to sendmail unless --stdout is used # Same 3 args as update hook ( ) diff --git a/toolbox/backup-db.sh b/toolbox/backup-db.sh index 93ba9f3..a5220c3 100755 --- a/toolbox/backup-db.sh +++ b/toolbox/backup-db.sh @@ -26,13 +26,13 @@ set -e # rotate_file basename suffix rotate_file2_9() { - [ -f "$1.8.$2" ] && mv -f "$1.8.$2" "$1.9.$2" - [ -f "$1.7.$2" ] && mv -f "$1.7.$2" "$1.8.$2" - [ -f "$1.6.$2" ] && mv -f "$1.6.$2" "$1.7.$2" - [ -f "$1.5.$2" ] && mv -f "$1.5.$2" "$1.6.$2" - [ -f "$1.4.$2" ] && mv -f "$1.4.$2" "$1.5.$2" - [ -f "$1.3.$2" ] && mv -f "$1.3.$2" "$1.4.$2" - [ -f "$1.2.$2" ] && mv -f "$1.2.$2" "$1.3.$2" + ! [ -f "$1.8.$2" ] || mv -f "$1.8.$2" "$1.9.$2" + ! [ -f "$1.7.$2" ] || mv -f "$1.7.$2" "$1.8.$2" + ! [ -f "$1.6.$2" ] || mv -f "$1.6.$2" "$1.7.$2" + ! [ -f "$1.5.$2" ] || mv -f "$1.5.$2" "$1.6.$2" + ! [ -f "$1.4.$2" ] || mv -f "$1.4.$2" "$1.5.$2" + ! [ -f "$1.3.$2" ] || mv -f "$1.3.$2" "$1.4.$2" + ! [ -f "$1.2.$2" ] || mv -f "$1.2.$2" "$1.3.$2" return 0 } @@ -41,12 +41,12 @@ backup_file() { rotate_file2_9 "$1" gz if [ -f "$1.1" ]; then rm -f "$1.2.gz" - gzip -n9 < "$1.1" > "$1.2.gz" && \ - touch -r "$1.1" "$1.2.gz" && \ + gzip -n9 <"$1.1" >"$1.2.gz" && + touch -r "$1.1" "$1.2.gz" && chmod a-w "$1.2.gz" fi if [ -f "$1" ]; then - cp -pf "$1" "$1.1" && \ + cp -pf "$1" "$1.1" && chmod a-w "$1.1" fi return 0 @@ -56,12 +56,12 @@ backup_file() { backup_dir() ( set -e rotate_file2_9 "$1" tar.gz - [ -f "$1.1.tar.gz" ] && mv -f "$1.1.tar.gz" "$1.2.tar.gz" + ! [ -f "$1.1.tar.gz" ] || mv -f "$1.1.tar.gz" "$1.2.tar.gz" if [ -d "$1" ]; then cd "$(dirname "$1")" base="$(basename "$1")" rm -f "$base.1.tar.gz" - tar -c -f - $base | gzip -n9 > "$base.1.tar.gz" + tar -c -f - $base | gzip -n9 >"$base.1.tar.gz" chmod a-w "$base.1.tar.gz" fi return 0 diff --git a/toolbox/clear-all-htmlcache.sh b/toolbox/clear-all-htmlcache.sh index 0c9ced5..59b2d15 100755 --- a/toolbox/clear-all-htmlcache.sh +++ b/toolbox/clear-all-htmlcache.sh @@ -10,7 +10,7 @@ set -e umask 002 base="$cfg_reporoot" -cut -d : -f 1 < "$cfg_chroot/etc/group" | grep -v ^_repo | \ +cut -d : -f 1 <"$cfg_chroot/etc/group" | grep -v "^_repo" | ( count=0 while read proj; do diff --git a/toolbox/edit-user-email.sh b/toolbox/edit-user-email.sh index 6c7a105..00a92f9 100755 --- a/toolbox/edit-user-email.sh +++ b/toolbox/edit-user-email.sh @@ -4,12 +4,12 @@ set -e . @basedir@/shlib.sh -if [ -z "$1" -o -z "$2" -o -z "$3" ]; then - echo "Syntax: ./edit-user-email.sh " +if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then + echo "Usage: $0 " exit 1 fi ETC="$cfg_chroot/etc" -COUNT=`grep -E -c "^$1:" "$ETC/passwd"` +COUNT="$(grep -E -c "^$1:" "$ETC/passwd")" if [ "$COUNT" -ne "1" ]; then echo "fatal: user '$1' doesn't appear to exist (or exists multiple times, or contains regexpy characters)." exit 1 @@ -28,10 +28,10 @@ sed \ -e "b" \ -e ": show" \ -e "w /dev/stderr" \ - "$ETC/passwd" > "$ETC/passwd.$$" + "$ETC/passwd" >"$ETC/passwd.$$" mv -f "$ETC/passwd.$$" "$ETC/passwd" rm -f "$ETC/passwd.$$" -if [ -n "$cfg_update_pwd_db" -a "$cfg_update_pwd_db" != "0" ]; then +if [ -n "$cfg_update_pwd_db" ] && [ "$cfg_update_pwd_db" != "0" ]; then "$cfg_basedir/bin/update-pwd-db" "$ETC/passwd" "$1" fi echo "All changed lines listed above." diff --git a/toolbox/make-all-gc-eligible.sh b/toolbox/make-all-gc-eligible.sh index d392833..7fafe1c 100755 --- a/toolbox/make-all-gc-eligible.sh +++ b/toolbox/make-all-gc-eligible.sh @@ -10,7 +10,7 @@ set -e umask 002 base="$cfg_reporoot" -cut -d : -f 1 < "$cfg_chroot/etc/group" | grep -v ^_repo | \ +cut -d : -f 1 <"$cfg_chroot/etc/group" | grep -v "^_repo" | ( count=0 while read proj; do diff --git a/toolbox/perform-pre-gc-linking.sh b/toolbox/perform-pre-gc-linking.sh index 98c468c..199d7a3 100755 --- a/toolbox/perform-pre-gc-linking.sh +++ b/toolbox/perform-pre-gc-linking.sh @@ -97,14 +97,14 @@ if ! cd "$cfg_reporoot/$proj.git"; then fi apid= ahost= -{ read -r apid ahost ajunk < gc.pid; } >/dev/null 2>&1 || : +{ read -r apid ahost ajunk /dev/null 2>&1 || : if [ -n "$apid" ] && [ -n "$ahost" ]; then echo "ERROR: refusing to run, $cfg_reporoot/$proj.git/gc.pid file exists" echo "ERROR: is gc already running on machine '$ahost' pid '$apid'?" exit 1 fi -if [ -z "$force" ] && ! [ -e .nogc -o -e .bypass ]; then +if [ -z "$force" ] && ! [ -e .nogc ] && ! [ -e .bypass ]; then echo "WARNING: no .nogc or .bypass file found in $cfg_reporoot/$proj.git" echo "WARNING: jobd.pl could run gc.sh while you're fussing with $proj" echo "WARNING: either create one of those files or re-run with --force" @@ -136,7 +136,7 @@ trap 'echo "pre-packing-and-linking failed" >&2; exit 1' EXIT list_packs --exclude-no-idx objects/pack | xargs touch -c 2>/dev/null || : bmpack="$(list_packs --exclude-no-bitmap --exclude-no-idx --max-matches 1 objects/pack)" [ -n "$bmpack" ] || bmpack="$(list_packs --exclude-no-idx --max-matches 1 --object-limit -1 --include-boundary objects/pack)" -if [ -n "$bmpack" ] && [ -f "$bmpack" -a -s "$bmpack" ]; then +if [ -n "$bmpack" ] && [ -f "$bmpack" ] && [ -s "$bmpack" ]; then sleep 1 touch -c "$bmpack" 2>/dev/null || : fi @@ -173,15 +173,15 @@ if has_forks "$proj"; then get_repo_list "$forkdir/[^/]*:" | while read fork; do # Ignore forks that do not exist or are symbolic links - [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \ + ! [ -L "$cfg_reporoot/$fork.git" ] && [ -d "$cfg_reporoot/$fork.git" ] || continue # Or do not have a non-zero length alternates file - [ -s "$cfg_reporoot/$fork.git/objects/info/alternates" ] || \ + [ -s "$cfg_reporoot/$fork.git/objects/info/alternates" ] || continue if [ -n "$lpacks" ]; then # Install the "loose objects" pack(s) into the fork [ -d "$cfg_reporoot/$fork.git/objects/pack" ] || ( - cd "$cfg_reporoot/$fork.git" && \ + cd "$cfg_reporoot/$fork.git" && mkdir -p objects/pack ) for lpack in $lpacks; do @@ -190,7 +190,7 @@ if has_forks "$proj"; then done if ! [ -e "$cfg_reporoot/$fork.git/.needsgc" ]; then # Trigger a mini gc in the fork if it now has too many packs - packs="$(list_packs --quiet --count --exclude-no-idx "$cfg_reporoot/$fork.git/objects/pack" || :)" + packs="$(list_packs --quiet --count --exclude-no-idx "$cfg_reporoot/$fork.git/objects/pack")" || : if [ -n "$packs" ] && [ "$packs" -ge 20 ]; then >"$cfg_reporoot/$fork.git/.needsgc" fi @@ -234,10 +234,10 @@ if has_forks "$proj"; then get_repo_list "$forkdir/[^/]*:" | while read fork; do # Ignore forks that do not exist or are symbolic links - [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \ + ! [ -L "$cfg_reporoot/$fork.git" ] && [ -d "$cfg_reporoot/$fork.git" ] || continue # Or do not have a non-zero length alternates file - [ -s "$cfg_reporoot/$fork.git/objects/info/alternates" ] || \ + [ -s "$cfg_reporoot/$fork.git/objects/info/alternates" ] || continue # Match objects in parent project for d in objects/$octet; do @@ -253,7 +253,7 @@ if has_forks "$proj"; then xargs "$var_sh_bin" -c 'ln -f "$@" '"'$cfg_reporoot/$fork.git/objects/pack/'" sh || : if ! [ -e "$cfg_reporoot/$fork.git/.needsgc" ]; then # Trigger a mini gc in the fork if it now has too many packs - packs="$(list_packs --quiet --count --exclude-no-idx "$cfg_reporoot/$fork.git/objects/pack" || :)" + packs="$(list_packs --quiet --count --exclude-no-idx "$cfg_reporoot/$fork.git/objects/pack")" || : if [ -n "$packs" ] && [ "$packs" -ge 20 ]; then >"$cfg_reporoot/$fork.git/.needsgc" fi diff --git a/toolbox/project-changed.sh b/toolbox/project-changed.sh index cef6ca3..d6505cf 100755 --- a/toolbox/project-changed.sh +++ b/toolbox/project-changed.sh @@ -26,7 +26,7 @@ if [ "$#" -ne 1 ] || [ -z "$p" ]; then fi "$cfg_basedir/gitweb/genindex.sh" "$p" || : if [ -d "$cfg_reporoot/$p.git" ]; then - ! [ -d "$cfg_reporoot/$p.git/htmlcache" ] || \ + ! [ -d "$cfg_reporoot/$p.git/htmlcache" ] || >"$cfg_reporoot/$p.git/htmlcache/changed" else echo "WARNING: no such directory: $cfg_reporoot/$p.git" diff --git a/toolbox/remove-user.sh b/toolbox/remove-user.sh index 750c98e..f6b61d0 100755 --- a/toolbox/remove-user.sh +++ b/toolbox/remove-user.sh @@ -5,19 +5,19 @@ set -e . @basedir@/shlib.sh if [ -z "$1" ]; then - echo "Syntax: ./remove-user.sh " + echo "Usage: $0 " exit 1 fi u="$1" qu="$(printf '%s' "$u" | sed -e 's/\./\\./g' -e 's/+/[+]/g')" ETC="$cfg_chroot/etc" -COUNT=$(grep -E -c "^$qu:" "$ETC/passwd" || :) +COUNT="$(grep -E -c "^$qu:" "$ETC/passwd")" || : if [ "$COUNT" -ne "1" ]; then echo "fatal: user '$u' doesn't appear to exist (or exists multiple times, or contains regexpy characters)." exit 1 fi ENTRY="$(grep -E "^$qu:" "$ETC/passwd" | cut -d : -f 1-5)" -GRPS=$( (grep -E '^[^:]+:[^:]+:[^:]+.*(:|,)'"$qu"'(,|:|$)' "$ETC/group" || :) | cut -d : -f 1 ) +GRPS="$( (grep -E '^[^:]+:[^:]+:[^:]+.*(:|,)'"$qu"'(,|:|$)' "$ETC/group" || :) | cut -d : -f 1 )" || : if [ "$GRPS" ]; then echo "User '$u' is still part of these groups:" $GRPS echo "fatal: this simplistic script cannot remove users from groups." @@ -33,7 +33,7 @@ rm -f "$ETC/sshactive/$u",* || : ! [ -e "$ETC/sshkeys/$u" ] || echo "Warning: unable to remove $ETC/sshkeys/$u" >&2 [ "$(echo "$ETC/sshcerts/$cfg_nickname"_"$u"_user_*.pem)" = "$ETC/sshcerts/$cfg_nickname"_"$u"_user_"*".pem ] || echo "Warning: unable to remove $(echo "$ETC/sshcerts/$cfg_nickname"_"$u"_user_*.pem)" >&2 -if [ -n "$cfg_update_pwd_db" -a "$cfg_update_pwd_db" != "0" ]; then +if [ -n "$cfg_update_pwd_db" ] && [ "$cfg_update_pwd_db" != "0" ]; then "$cfg_basedir/bin/update-pwd-db" "$ETC/passwd" "$u" fi echo "User \"$ENTRY\" (+SSH key/certs) removed." diff --git a/toolbox/reports/project-disk-use.sh b/toolbox/reports/project-disk-use.sh index 4052da9..2265b5b 100755 --- a/toolbox/reports/project-disk-use.sh +++ b/toolbox/reports/project-disk-use.sh @@ -29,12 +29,12 @@ if [ "$1" = "-m" ]; then fi hasnice= -! command -v nice > /dev/null || hasnice=1 +! command -v nice >/dev/null || hasnice=1 hasionice= -! command -v ionice > /dev/null || hasionice=1 +! command -v ionice >/dev/null || hasionice=1 -nl="$(printf '\n*')" -nl="${nl%?}" +nl=' +' fmtcomma() { # remove leading 0s @@ -84,7 +84,7 @@ is_active() ( check_interval lastchange 2592000 # 30 days ) -projlist="$(cut -d : -f 1 < "$cfg_chroot/etc/group")" +projlist="$(cut -d : -f 1 <"$cfg_chroot/etc/group")" is_listed_proj() { echo "$projlist" | grep -q -e "^$1$" @@ -118,7 +118,7 @@ while IFS='' read -r proj; do x= is_listed_proj "$proj" || { x='!'; orphans="$(( $orphans + 1 ))"; } case "$proj" in */*) forks="$(( $forks + 1 ))"; esac - mirror="$(get_mirror_type "$proj.git" 2>/dev/null || :)" + mirror="$(get_mirror_type "$proj.git" 2>/dev/null)" || : [ -z "$mirror" ] || mirrors="$(( $mirrors + 1 ))" if is_active "$proj"; then if [ -n "$mirror" ]; then @@ -130,8 +130,8 @@ while IFS='' read -r proj; do : ${mirror:=M} usek="$(get_use_k "$proj.git")" repok= - [ -L "$proj.git/objects" -o ! -d "$proj.git/objects" ] || \ - repok="$(git --git-dir="$cfg_reporoot/$proj.git" config --get girocco.reposizek 2>/dev/null || :)" + [ -L "$proj.git/objects" ] || ! [ -d "$proj.git/objects" ] || + repok="$(git --git-dir="$cfg_reporoot/$proj.git" config --get girocco.reposizek 2>/dev/null)" || : repokpct= case "$repok" in [0-9]*) @@ -201,10 +201,10 @@ EOT echo "$message" echo "$message" | tr -c '\n' - echo "" - printf '%s' "$results" | sort -k1,1nr -k4,4 | \ + printf '%s' "$results" | sort -k1,1nr -k4,4 | while read -r a b c d; do printf "%10s %4s %s %s\n" "$(fmtcomma "$a")" "$b" "$c" "$d" - done | \ + done | sed -e 's/ [M-] / /g' | $topn fi } | eval "$domail" diff --git a/toolbox/reports/project-fsck-status.sh b/toolbox/reports/project-fsck-status.sh index 0fc38f2..9d51939 100755 --- a/toolbox/reports/project-fsck-status.sh +++ b/toolbox/reports/project-fsck-status.sh @@ -26,14 +26,14 @@ if [ "$1" = "-m" ]; then fi hasnice= -! command -v nice > /dev/null || hasnice=1 +! command -v nice >/dev/null || hasnice=1 hasionice= -! command -v ionice > /dev/null || hasionice=1 +! command -v ionice >/dev/null || hasionice=1 -nl="$(printf '\n*')" -nl="${nl%?}" +nl=' +' -projlist="$(cut -d : -f 1 < "$cfg_chroot/etc/group")" +projlist="$(cut -d : -f 1 <"$cfg_chroot/etc/group")" is_listed_proj() { echo "$projlist" | grep -q -e "^$1$" @@ -43,7 +43,7 @@ is_empty_proj() { # if packed-refs is empty and no files in refs then empty # we do NOT want to run any git command in case the repo is bad _pd="$cfg_reporoot/$1.git" - if [ -f "$_pd/packed-refs" -a -s "$_pd/packed-refs" ]; then + if [ -f "$_pd/packed-refs" ] && [ -s "$_pd/packed-refs" ]; then if [ $(LC_ALL=C sed -n '/^#/!p' <"$_pd/packed-refs" | LC_ALL=C wc -l) -gt 0 ]; then return 1 fi @@ -101,7 +101,7 @@ while IFS='' read -r proj; do ok=1 output="$(get_fsck_proj "$proj")" || ok= [ -z "$ok" ] || okcount="$(( $okcount + 1 ))" - [ -n "$ok" -o -n "$output" ] || output="git fsck failed with no output" + [ -n "$ok" ] || [ -n "$output" ] || output="git fsck failed with no output" if [ -n "$output" ]; then output="$(printf '%s\n' "$output" | LC_ALL=C sed 's/^/ /')$nl" if [ -n "$ok" ]; then @@ -145,7 +145,7 @@ EOT echo "-----------" echo "" printf '%s' "$errresults" - [ -z "$errresults" -o -z "$warnresults" ] || echo "" + [ -z "$errresults" ] || [ -z "$warnresults" ] || echo "" printf '%s' "$warnresults" echo "" fi diff --git a/toolbox/update-all-config.sh b/toolbox/update-all-config.sh index 4a185d9..0c283ed 100755 --- a/toolbox/update-all-config.sh +++ b/toolbox/update-all-config.sh @@ -12,8 +12,8 @@ set -e force= dryrun= -[ "$1" != "--force" -a "$1" != "-f" ] || { force=1; shift; } -[ "$1" != "--dry-run" -a "$1" != "-n" ] || { dryrun=1; shift; } +[ "$1" != "--force" ] && [ "$1" != "-f" ] || { force=1; shift; } +[ "$1" != "--dry-run" ] && [ "$1" != "-n" ] || { dryrun=1; shift; } case "$1" in -*) echo "Invalid options: $1" >&2; exit 1;; esac if is_root; then @@ -149,8 +149,8 @@ do_mkdir() { pmsg "$1/:" created ${result:+FAILED!} ${dryrun:+(dryrun)} } -nl="$(printf '\n.')" -nl="${nl%?}" +nl=' +' readconfiglist() { if [ -n "$dryrun" ] && ! [ -e config ]; then configlist= @@ -196,8 +196,8 @@ do_config() { oldval="$(configitem "$item")" || existsnot=1 ccmd=unset arg="$item" - [ -n "$existsnot" -o -z "$unset" ] || [ $(printf '%s' "$configlist" | grep "^${item%%.*}\.[^.][^.]*=" | wc -l) -ne 1 ] || { ccmd="remove-section"; arg="${item%%.*}"; } - [ -n "$dryrun" ] || [ -n "$unset" -a -n "$existsnot" ] || git config --file config ${unset:+--$ccmd} "$arg" "$@" 2>/dev/null || result=1 + [ -n "$existsnot" ] || [ -z "$unset" ] || [ $(printf '%s' "$configlist" | grep "^${item%%.*}\.[^.][^.]*=" | wc -l) -ne 1 ] || { ccmd="remove-section"; arg="${item%%.*}"; } + [ -n "$dryrun" ] || { [ -n "$unset" ] && [ -n "$existsnot" ]; } || git config --file config ${unset:+--$ccmd} "$arg" "$@" 2>/dev/null || result=1 if [ -n "$existsnot" ]; then [ -n "$unset" ] || pmsg "config $item:" created "\"$*\"" ${result:+FAILED!} ${dryrun:+(dryrun)} else @@ -223,9 +223,9 @@ false0vars='gc.auto receive.autogc' truevars='receive.updateserverinfo repack.writebitmaps transfer.fsckobjects' base="${cfg_reporoot%/}" -cmd='cut -d : -f 1 < "$cfg_chroot/etc/group" | grep -v ^_repo' +cmd='cut -d : -f 1 <"$cfg_chroot/etc/group" | grep -v ^_repo' [ $# -eq 0 ] || cmd='printf "%s\n" "$@"' -eval "$cmd" | \ +eval "$cmd" | ( while read -r proj; do proj="${proj#$base/}" @@ -251,17 +251,17 @@ eval "$cmd" | \ while read -r fixdir; do [ -z "$fixdir" ] || change_dperm "$fixdir" done <<-EOT - $(find $fixdpermsdirs -xdev -maxdepth 0 -type d \! -perm $dmode -print 2>/dev/null) + $(find $fixdpermsdirs -xdev -maxdepth 0 -type d ! -perm $dmode -print 2>/dev/null) EOT while read -r fixdir; do [ -z "$fixdir" ] || change_dpermrwx "$fixdir" done <<-EOT - $(find $fixdpermsrwx -xdev -type d \! -perm -$drwxmode -print 2>/dev/null) + $(find $fixdpermsrwx -xdev -type d ! -perm -$drwxmode -print 2>/dev/null) EOT while read -r fixdir; do [ -z "$fixdir" ] || change_dpermrx "$fixdir" done <<-EOT - $(find . -xdev -type d \! -perm -a+rx -print) + $(find . -xdev -type d ! -perm -a+rx -print) EOT for mkfile in $mkfiles; do if [ -e "$mkfile" ]; then @@ -279,7 +279,7 @@ eval "$cmd" | \ [ -z "$bad" ] || continue [ -n "$dryrun" ] || change_fperm config readconfiglist - cmplvl="$(configitem core.compression || :)" + cmplvl="$(configitem core.compression)" || : case "$cmplvl" in "5"|"") ;; @@ -292,7 +292,7 @@ eval "$cmd" | \ ;; esac [ -n "$cmplvl" ] || do_config core.compression 5 - grpshr="$(configitem core.sharedrepository || :)" + grpshr="$(configitem core.sharedrepository)" || : if [ -z "$grpshr" ] || isboolfalse "$grpshr"; then do_config core.sharedrepository 1 elif ! isbooltrue "$grpshr"; then @@ -303,7 +303,7 @@ eval "$cmd" | \ if laru="$(configitem core.logallrefupdates)"; then if isbool "$laru"; then setlaru= - isboolfalse "$laru" || \ + isboolfalse "$laru" || pmsg "WARNING: core.logallrefupdates is true (left unchanged)" else pmsg "WARNING: replacing non-boolean core.logallrefupdates value" @@ -320,22 +320,22 @@ eval "$cmd" | \ ! old="$(configitem "$bvar")" || isbool "$old" || do_config --unset "$bvar" "(not a boolean)" done for fvar in $falsevars; do - old="$(configitem "$fvar" || :)" + old="$(configitem "$fvar")" || : isboolfalse "$old" || do_config "$fvar" false done for fvar in $false0vars; do - old="$(configitem "$fvar" || :)" + old="$(configitem "$fvar")" || : isboolfalse "$old" || do_config "$fvar" 0 done for tvar in $truevars; do - old="$(configitem "$tvar" || :)" + old="$(configitem "$tvar")" || : isbooltrue "$old" || do_config "$tvar" true done if [ -n "$cfg_owning_group" ]; then while read -r fixgrp; do [ -z "$fixgrp" ] || change_group "$fixgrp" done <<-EOT - $(find . -xdev \( -type d -o -type f \) \! -group $cfg_owning_group -print) + $(find . -xdev \( -type d -o -type f \) ! -group $cfg_owning_group -print) EOT fi for fixfile in $fixfpermsfiles; do @@ -349,13 +349,13 @@ eval "$cmd" | \ fi done [ -z "$bad" ] || continue - for fixfile in $(find $fixfpermsdirs -xdev -type f \! -perm $fmode -print 2>/dev/null); do + for fixfile in $(find $fixfpermsdirs -xdev -type f ! -perm $fmode -print 2>/dev/null); do change_fperm "$fixfile" done while read -r fixfileread; do [ -z "$fixfileread" ] || change_fpermr "$fixfileread" done <<-EOT - $(find . -xdev -type f \! -perm -a+r -print) + $(find . -xdev -type f ! -perm -a+r -print) EOT while read -r fixfilenox; do [ -z "$fixfilenox" ] || change_fpermnox "$fixfilenox" @@ -366,11 +366,11 @@ eval "$cmd" | \ #case "$fixfilex" in ""|*.sample) :;; *) change_fpermx "$fixfilex"; esac : done <<-EOT - $(! [ -d hooks ] || find hooks -xdev -type f \! -perm -a+x -print - ! [ -d mob/hooks ] || find mob/hooks -xdev -type f \! -perm -a+x -print) + $(! [ -d hooks ] || find hooks -xdev -type f ! -perm -a+x -print + ! [ -d mob/hooks ] || find mob/hooks -xdev -type f ! -perm -a+x -print) EOT - bu="$(configitem gitweb.baseurl || :)" - [ -n "$bu" -o -e .nofetch ] || pmsg "WARNING: gitweb.baseurl is empty and .nofetch does not exist" - [ -z "$bu" -o ! -e .nofetch ] || pmsg "WARNING: .nofetch exists but gitweb.baseurl is not empty" + bu="$(configitem gitweb.baseurl)" || : + [ -n "$bu" ] || [ -e .nofetch ] || pmsg "WARNING: gitweb.baseurl is empty and .nofetch does not exist" + [ -z "$bu" ] || ! [ -e .nofetch ] || pmsg "WARNING: .nofetch exists but gitweb.baseurl is not empty" done ) diff --git a/toolbox/update-all-hooks.sh b/toolbox/update-all-hooks.sh index 908602e..1100481 100755 --- a/toolbox/update-all-hooks.sh +++ b/toolbox/update-all-hooks.sh @@ -10,8 +10,8 @@ set -e force= dryrun= -[ "$1" != "--force" -a "$1" != "-f" ] || { force=1; shift; } -[ "$1" != "--dry-run" -a "$1" != "-n" ] || { dryrun=1; shift; } +[ "$1" != "--force" ] && [ "$1" != "-f" ] || { force=1; shift; } +[ "$1" != "--dry-run" ] && [ "$1" != "-n" ] || { dryrun=1; shift; } case "$1" in -*) echo "Invalid options: $1" >&2; exit 1;; esac if is_root; then @@ -28,9 +28,9 @@ write_mob_hook() { base="${cfg_reporoot%/}" hookbin="$cfg_basedir/hooks" -cmd='cut -d : -f 1 < "$cfg_chroot/etc/group" | grep -v ^_repo' +cmd='cut -d : -f 1 <"$cfg_chroot/etc/group" | grep -v ^_repo' [ $# -eq 0 ] || cmd='printf "%s\n" "$@"' -eval "$cmd" | \ +eval "$cmd" | ( while read -r proj; do proj="${proj#$base/}" @@ -42,12 +42,12 @@ eval "$cmd" | \ for hook in pre-receive post-receive update; do if [ -f "$projdir/hooks/$hook" ]; then if ! cmp -s "$hookbin/$hook" "$projdir/hooks/$hook"; then - [ -n "$dryrun" ] || cat "$hookbin/$hook" > "$projdir/hooks/$hook" + [ -n "$dryrun" ] || cat "$hookbin/$hook" >"$projdir/hooks/$hook" updates="$updates $hook" fi - elif [ ! -e "$projdir/hooks/$hook" ]; then + elif ! [ -e "$projdir/hooks/$hook" ]; then [ -n "$dryrun" ] || [ -d "$projdir/hooks" ] || mkdir "$projdir/hooks" - [ -n "$dryrun" ] || cat "$hookbin/$hook" > "$projdir/hooks/$hook" + [ -n "$dryrun" ] || cat "$hookbin/$hook" >"$projdir/hooks/$hook" [ -n "$dryrun" ] || chmod 0775 "$projdir/hooks/$hook" updates="$updates +$hook" fi @@ -56,11 +56,11 @@ eval "$cmd" | \ for hook in pre-receive post-receive; do if [ -f "$projdir/mob/hooks/$hook" ]; then if ! write_mob_hook "$hook" | cmp -s - "$projdir/mob/hooks/$hook"; then - [ -n "$dryrun" ] || write_mob_hook "$hook" > "$projdir/mob/hooks/$hook" + [ -n "$dryrun" ] || write_mob_hook "$hook" >"$projdir/mob/hooks/$hook" updates="$updates mob/$hook" fi elif ! [ -e "$projdir/mob/hooks/$hook" ]; then - [ -n "$dryrun" ] || write_mob_hook "$hook" > "$projdir/mob/hooks/$hook" + [ -n "$dryrun" ] || write_mob_hook "$hook" >"$projdir/mob/hooks/$hook" [ -n "$dryrun" ] || chmod 0775 "$projdir/mob/hooks/$hook" updates="$updates +mob/$hook" fi @@ -93,8 +93,8 @@ eval "$cmd" | \ esac done <<-EOT $(cd "$projdir" - ! [ -d hooks ] || find hooks -xdev -type f \! -perm -a+rx -print - ! [ -d mob/hooks ] || find mob/hooks -xdev -type f \! -perm -a+rx -print) + ! [ -d hooks ] || find hooks -xdev -type f ! -perm -a+rx -print + ! [ -d mob/hooks ] || find mob/hooks -xdev -type f ! -perm -a+rx -print) EOT [ -z "$updates" ] || echo "$proj:$updates" ${dryrun:+(dryrun)} done diff --git a/toolbox/update-all-projects.sh b/toolbox/update-all-projects.sh index 94f651f..0d305e5 100755 --- a/toolbox/update-all-projects.sh +++ b/toolbox/update-all-projects.sh @@ -12,8 +12,8 @@ set -e force= dryrun= -[ "$1" != "--force" -a "$1" != "-f" ] || { force=1; shift; } -[ "$1" != "--dry-run" -a "$1" != "-n" ] || { dryrun=1; shift; } +[ "$1" != "--force" ] && [ "$1" != "-f" ] || { force=1; shift; } +[ "$1" != "--dry-run" ] && [ "$1" != "-n" ] || { dryrun=1; shift; } case "$1" in -*) echo "Invalid options: $1" >&2; exit 1;; esac umask 002 @@ -25,7 +25,7 @@ if [ -z "$cfg_owning_group" ]; then fi fi -mydir="$(cd -- "$(dirname "$0")" && pwd -P)" +mydir="$(cd "$(dirname "$0")" && pwd -P)" required='update-all-config.sh update-all-hooks.sh' bad= for r in $required; do diff --git a/toolbox/updatecheck.sh b/toolbox/updatecheck.sh index ab4824a..657794c 100755 --- a/toolbox/updatecheck.sh +++ b/toolbox/updatecheck.sh @@ -7,18 +7,18 @@ . @basedir@/shlib.sh cd "$cfg_reporoot" -cat "$cfg_chroot/etc/group" | cut -d : -f 1 | \ +cut -d : -f 1 <"$cfg_chroot/etc/group" | grep -v "^_repo" | while read dir; do echo "* $dir" >&2 if [ -e "$dir.git"/.nofetch ]; then -# echo "+l `date` $dir" +# echo "+l $(date) $dir" # (cd "$dir.git/objects" && [ "$(ls ?? 2>/dev/null)" ] && GIT_DIR=".." git repack -A -d -q) # GIT_DIR="$dir.git" git update-server-info -# echo "-l `date` $dir" +# echo "-l $(date) $dir" :; else - echo "+r `date` $dir" - "$cfg_basedir/jobd/update.sh" "${dir}" - echo "-r `date` $dir" + echo "+r $(date) $dir" + "$cfg_basedir/jobd/update.sh" "$dir" + echo "-r $(date) $dir" fi done 2>&1 -- 2.11.4.GIT