From 0ba10ffe97ba57c27c2aec835ef7337663a7c72c Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 6 Sep 2016 01:34:00 -0700 Subject: [PATCH] install: set var_sh_bin and var_gzip_bin Set var_sh_bin as a convenience instead of having to always use ${cfg_posix_sh_bin:-/bin/sh} everywhere and change those uses to the more succinct $var_sh_bin. Set var_gzip_bin to the gzip executable (configurable with the new $Girocco::Config::gzip_bin setting) and validate it and also provide a gzip() wrapper function to run the selected executable. Signed-off-by: Kyle J. McKay --- Girocco/Config.pm | 3 +++ install.sh | 9 ++++++++- jailsetup.sh | 2 +- jobd/gc.sh | 3 +-- shlib.sh | 7 ++++++- toolbox/perform-pre-gc-linking.sh | 3 +-- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Girocco/Config.pm b/Girocco/Config.pm index 5c0fee0..e635b0b 100644 --- a/Girocco/Config.pm +++ b/Girocco/Config.pm @@ -46,6 +46,9 @@ our $posix_sh_bin = undef; # Path to Perl executable to use. Set to undef to use Perl found in $PATH our $perl_bin = undef; +# Path to gzip executable to use. Set to undef to use gzip found in $PATH +our $gzip_bin = undef; + # Path to the sendmail instance to use. It should understand the -f , -i and -t # options as well as accepting a list of recipient addresses in order to be used here. # You MUST set this, even if to '/usr/sbin/sendmail'! diff --git a/install.sh b/install.sh index 6637863..796d294 100755 --- a/install.sh +++ b/install.sh @@ -277,7 +277,7 @@ cp -p gitweb/*.sh gitweb/*.perl "$cfg_basedir/gitweb" [ "$GIROCCO_CONF" = "Girocco::Config" ] || cp "$(echo "$GIROCCO_CONF" | sed 's#::#/#g; s/$/.pm/')" "$cfg_basedir/Girocco/Config.pm" ln -s "$cfg_git_bin" "$cfg_basedir/bin/git" -shbin="${cfg_posix_sh_bin:-/bin/sh}" +shbin="$var_sh_bin" [ -n "$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 @@ -289,6 +289,13 @@ perlbin="$var_perl_bin" exit 1 } ln -s "$perlbin" "$cfg_basedir/bin/perl" +gzipbin="$var_gzip_bin" +[ -n "$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 +} +ln -s "$gzipbin" "$cfg_basedir/bin/gzip" echo "*** Preprocessing scripts..." SHBIN="$shbin" && export SHBIN diff --git a/jailsetup.sh b/jailsetup.sh index 2e66ac3..49c8f11 100755 --- a/jailsetup.sh +++ b/jailsetup.sh @@ -326,7 +326,7 @@ mv -f bin/git-askpass-password.new bin/git-askpass-password mv -f bin/git-shell-verify.new bin/git-shell-verify pull_in_bin "$cfg_basedir/bin/can_user_push" bin pull_in_bin "$cfg_basedir/bin/list_packs" bin -pull_in_bin "${cfg_posix_sh_bin:-/bin/sh}" bin/sh +pull_in_bin "$var_sh_bin" bin/sh pull_in_bin /bin/chmod bin pull_in_bin /bin/date bin pull_in_bin /bin/mkdir bin diff --git a/jobd/gc.sh b/jobd/gc.sh index be7db93..7da3079 100755 --- a/jobd/gc.sh +++ b/jobd/gc.sh @@ -737,7 +737,6 @@ if has_forks "$proj"; then # the parent in which case the objects making up the patch in the child fork are now # redundant (since they're now in the parent as well) and need to be removed from the # child fork which can only happen if the child fork runs gc. - shbin="${cfg_posix_sh_bin:-/bin/sh}" forkdir="$proj" # It is enough to copy objects just one level down and get_repo_list # takes a regular expression (which is automatically prefixed with '^') @@ -755,7 +754,7 @@ if has_forks "$proj"; then [ "$d" != "objects/$octet" ] || continue mkdir -p "$cfg_reporoot/$fork.git/$d" find "$d" -maxdepth 1 -type f -name "$octet19" -print0 | - xargs -0 "$shbin" -c 'ln -f "$@" '"'$cfg_reporoot/$fork.git/$d/'" sh || : + xargs -0 "$var_sh_bin" -c 'ln -f "$@" '"'$cfg_reporoot/$fork.git/$d/'" sh || : done # Update the fork's lastparentgc date (must be current, not $gcstart) git --git-dir="$cfg_reporoot/$fork.git" config \ diff --git a/shlib.sh b/shlib.sh index 04ac095..2072a92 100644 --- a/shlib.sh +++ b/shlib.sh @@ -66,7 +66,9 @@ get_girocco_config_var_list() ( # var_group cfg_owning_group if defined otherwise `id -gn` # var_git_ver The version number part from `git version` # var_git_exec_path The result of $cfg_git_bin --exec-dir + # var_sh_bin Full path to the posix sh interpreter to use # var_perl_bin Full path to the perl interpreter to use + # var_gzip_bin Full path to the gzip executable to use # var_have_git_171 Set to 1 if git version >= 1.7.1 otherwise '' # var_have_git_172 Set to 1 if git version >= 1.7.2 otherwise '' # var_have_git_173 Set to 1 if git version >= 1.7.3 otherwise '' @@ -88,7 +90,9 @@ get_girocco_config_var_list() ( 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)" + printf 'var_sh_bin="%s"\n' "${cfg_posix_sh_bin:-/bin/sh}" printf 'var_perl_bin="%s"\n' "${cfg_perl_bin:-$(unset -f perl; command -v perl)}" + printf 'var_gzip_bin="%s"\n' "${cfg_gzip_bin:-$(unset -f gzip; command -v gzip)}" printf 'var_have_git_171=%s\n' "$([ $(vcmp "$_gver" 1.7.1) -ge 0 ] && echo 1)" printf 'var_have_git_172=%s\n' "$([ $(vcmp "$_gver" 1.7.2) -ge 0 ] && echo 1)" printf 'var_have_git_173=%s\n' "$([ $(vcmp "$_gver" 1.7.3) -ge 0 ] && echo 1)" @@ -232,8 +236,9 @@ git() ( ) # see comments for git() -- callers must explicitly export all variables -# intended for the perl interpreter before using this function +# intended for the commands these functions run before calling them perl() { command "${var_perl_bin:-perl}" "$@"; } +gzip() { command "${var_gzip_bin:-gzip}" "$@"; } nc_openbsd() { "$cfg_nc_openbsd_bin" "$@"; } diff --git a/toolbox/perform-pre-gc-linking.sh b/toolbox/perform-pre-gc-linking.sh index af827bc..202b525 100755 --- a/toolbox/perform-pre-gc-linking.sh +++ b/toolbox/perform-pre-gc-linking.sh @@ -198,7 +198,6 @@ if has_forks "$proj"; then # the parent in which case the objects making up the patch in the child fork are now # redundant (since they're now in the parent as well) and need to be removed from the # child fork which can only happen if the child fork runs gc. - shbin="${cfg_posix_sh_bin:-/bin/sh}" forkdir="$proj" # It is enough to copy objects just one level down and get_repo_list # takes a regular expression (which is automatically prefixed with '^') @@ -216,7 +215,7 @@ if has_forks "$proj"; then [ "$d" != "objects/$octet" ] || continue mkdir -p "$cfg_reporoot/$fork.git/$d" find "$d" -maxdepth 1 -type f -name "$octet19" -print0 | - xargs -0 "$shbin" -c 'ln -f "$@" '"'$cfg_reporoot/$fork.git/$d/'" sh || : + xargs -0 "$var_sh_bin" -c 'ln -f "$@" '"'$cfg_reporoot/$fork.git/$d/'" sh || : done # Update the fork's lastparentgc date (must be current, not $gcstart) git --git-dir="$cfg_reporoot/$fork.git" config \ -- 2.11.4.GIT