From: Kyle J. McKay Date: Sat, 12 Apr 2014 01:19:34 +0000 (-0700) Subject: shlib.sh: eliminate unnecessary perl calls X-Git-Url: https://repo.or.cz/w/girocco.git/commitdiff_plain/e2942ff101c5ef0718ea72f6d43509ffb5cbc855 shlib.sh: eliminate unnecessary perl calls Instead of running Perl every time shlib.sh starts up to export the Girocco::Config variables, run it once at install time and save the output so it can be run by shlib.sh with a "dot" command instead. --- diff --git a/install.sh b/install.sh index 4fbf48b..547abb3 100755 --- a/install.sh +++ b/install.sh @@ -95,6 +95,8 @@ perl -I. -M$GIROCCO_CONF -i -p \ "$cfg_basedir"/toolbox/* "$cfg_basedir"/bin/git-* "$cfg_basedir"/bin/create-* "$cfg_basedir"/bin/update-* \ "$cfg_basedir"/screen/* +# Dump all the cfg_ and defined_ variables to shlib_vars.sh +get_girocco_config_var_list > "$cfg_basedir"/shlib_vars.sh if [ -n "$cfg_mirror" ]; then echo "--- Remember to start $cfg_basedir/taskd/taskd.pl" diff --git a/shlib.sh b/shlib.sh index 95bdf94..3dde0cb 100644 --- a/shlib.sh +++ b/shlib.sh @@ -3,18 +3,34 @@ # This is generic shell library for all the scripts used by Girocco; # most importantly, it introduces all the $cfg_* shell variables. +get_girocco_config_var_list() { + # Export all the variables from Girocco::Config to suitable var= lines + # prefixing them with 'cfg_'. E.g. $cfg_admin is admin's mail address now + # and also setting a 'defined_cfg_' prefix to 1 if they are not undef. + __girocco_conf="$GIROCCO_CONF" + [ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config" + [ -z "$basedir" ] || __girocco_extrainc="-I$basedir" + perl -I@basedir@ $__girocco_extrainc -M$__girocco_conf -le \ + 'foreach (keys %Girocco::Config::) { + my $val = ${$Girocco::Config::{$_}}; $val ||= ""; + $val =~ s/([\\"!\$\`])/\\$1/gos; + $val =~ s/(?:\r\n|\r|\n)$//os; + print "cfg_$_=\"$val\""; + print "defined_cfg_$_=", + (defined(${$Girocco::Config::{$_}})?"1":""); + }' +} -# Import all the variables from Girocco::Config to the local environment, -# prefixing them with 'cfg_'. E.g. $cfg_admin is admin's mail address now. -__girocco_conf="$GIROCCO_CONF" -[ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config" -[ -z "$basedir" ] || __girocco_extrainc="-I$basedir" -eval $(perl -I@basedir@ $__girocco_extrainc -M$__girocco_conf -le \ - 'foreach (keys %Girocco::Config::) { - my $val = ${$Girocco::Config::{$_}}; $val ||= ""; - print "cfg_$_=\"$val\""; - }') - +# If basedir has been replaced, and shlib_vars.sh exists, get the config +# definitions from it rather than running Perl. +if [ "@basedir@" = '@'basedir'@' ] || ! [ -r "@basedir@/shlib_vars.sh" ]; then + # Import all the variables from Girocco::Config to the local environment, + eval "$(get_girocco_config_var_list)" +else + # Import the variables from shlib_vars.sh which avoids needlessly + # running another copy of Perl + . "@basedir@/shlib_vars.sh" +fi git() ( # some poorly behaving /bin/sh implementations do not