X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=amplot%2Famplot.sh.in;h=f771e7456f55d2a3e224ff90b0fa79a8dd660574;hb=d3b2175e084f88c8736ad7073eacbf4670147aec;hp=05a6ce8166829f7178d014fbaea949205cbd3270;hpb=34197d9f46a5f4e944378cbb65fca32ee0eec7b9;p=debian%2Famanda diff --git a/amplot/amplot.sh.in b/amplot/amplot.sh.in index 05a6ce8..f771e74 100644 --- a/amplot/amplot.sh.in +++ b/amplot/amplot.sh.in @@ -47,20 +47,82 @@ PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:$PATH export PATH AWK=@AWK@ -AVARFLAG=@AWK_VAR_ASSIGNMENT_OPT@ GNUPLOT=@GNUPLOT@ COMPRESS=@AMPLOT_COMPRESS@ +#+ +# Function to: +# Simplify gettext usage by allowing printf format +# strings for translators, use _() identifier for +# xgettext extraction similar to "C" usage and +# collapsing "printf `gettext fmt` ...", which is +# used everywhere, into one function. +#- +_() { + fmt="$1" + shift + printf "$fmt" $* +} + +# Function to check that awk can do command-line variable +# substitution. If no, then exit; if yes, set $AVARFLAG +# to the commandline switch used to introduce a variable. This +# check used to be performed at build time in configure; it's +# now performed at runtime. +test_awk() { + local tmpfile result + tmpfile=`mktemp /tmp/amplot.XXXXXX` + echo 'BEGIN{print i; exit}' > ${tmpfile} + result=`$AWK -f ${tmpfile} i=xx | wc -c` + if test "$result" -le 1; then + result=`$AWK -f ${tmpfile} -v i=xx | wc -c` + if test "$result" -le 1; then + echo "$AWK does not support command-line variable assignment; amplot cannot run" >&2 + rm -fr $tmpfile + exit 1 + else + AVARFLAG=-v + fi + else + AVARFLAG='' + fi + + rm -fr $tmpfile +} + +# Function to search for gnuplot and ensure it's working. This +# first tries the location detected/configured when amanda was built, +# then tries 'gnuplot', assuming it's in the user's path. If no +# working gnuplot executable is found, it exits with an error. The +# variable $GNUPLOT is set to the resulting executable. +find_gnuplot() { + if test "x$GNUPLOT" = "x"; then + # look for it in the user's PATH + GNUPLOT=gnuplot + fi + + if ${GNUPLOT} --version 2>/dev/null | grep '^gnuplot' >/dev/null; then + : # looks OK + else + echo "${GNUPLOT} was not found; amplot cannot run" + exit 1 + fi +} + +# check our environment, using functions from above +test_awk +find_gnuplot + if [ $# -eq 0 ] ; then - echo "Usage: $0 [-c] [-e] [-g] [-l] [-p] [-t hours] " - echo "amplot generates plot for screen with fixed dimensions" - echo " -c Compress the input amdump files after plotting" - echo " -e Extends x (time) axes if needed" - echo " -g Run gnuplot directly no postscript file generated DEFAULT" - echo " -l Landscape mode suitable for printing" - echo " -p Postscript output (color)" - echo " -b The postscipt will be b/w" - echo " -t T Set the right edge of the plot to be T hours" + _ 'Usage: %s [-c] [-e] [-g] [-l] [-p] [-t hours] \n' $0 + _ '%s generates plot for screen with fixed dimensions\n' $0 + _ ' -c Compress the input amdump files after plotting\n' + _ ' -e Extends x (time) axes if needed\n' + _ ' -g Run gnuplot directly no postscript file generated DEFAULT\n' + _ ' -l Landscape mode suitable for printing\n' + _ ' -p Postscript output (color)\n' + _ ' -b The postscipt will be b/w\n' + _ ' -t T Set the right edge of the plot to be T hours\n' exit 1 fi @@ -85,7 +147,7 @@ while :; do -b) bw=1; shift;; -t) shift if test "$#" -eq 0; then - echo "amplot: no argument for -t option" 1>&2 + _ '%s: no argument for -t option\n' $0 1>&2 exit 5 fi maxtime="$1"; shift;; @@ -93,7 +155,7 @@ while :; do esac done if [ $# -eq 0 ] ; then - echo "amplot: no input files" 1>&2 + _ '%s: no input files\n' $0 1>&2 exit 5 fi para=$para"$AVARFLAG maxtime=$maxtime" @@ -102,14 +164,14 @@ if [ $gnuplot -eq 1 ] ; then my_plot=$my_plot"p" # use the plot prog that pauses plot=" -geometry 800x700+40+0" para=$para"$AVARFLAG gnuplot=1 " - echo "Displaying graph on the screen, for next graph" + _ "Displaying graph on the screen, for next graph" if [ "$paper" -eq 1 ] ; then - echo "amplot: -l requires -p flag at the same time" 1>&2 + _ '%s: -l requires -p flag at the same time\n' $0 1>&2 exit 6 fi if [ "$bw" -eq 1 ] ; then - echo "amplot: -b requires -p flag at the same time" 1>&2 + _ '%s: -b requires -p flag at the same time\n' $0 1>&2 exit 6 fi fi @@ -129,7 +191,7 @@ do if [ -f "$f" ] ; then # found file disp=`$AWK -f $libexecdir/amcat.awk $AVARFLAG f="$f"` if [ -z "$disp" ] ; then - echo "Do not know how to [gz|z]cat this file" + _ 'Do not know how to [gz|z]cat this file\n' else /bin/rm -f $tmp_files $disp "$f" | $AWK -f $libexecdir/amplot.awk $para @@ -139,7 +201,7 @@ do fi fi else # check if file has been compressed - echo "No such file $i or $i.*[zZ]" + _ 'No such file %s or %s\n' "$i" "$i.*[zZ]" fi done @@ -147,7 +209,7 @@ done if [ "$list" != "" ] ; then # now compress the files we worked on # comment out next line if you do not want compression at the end - echo "Compressing $list" + _ 'Compressing %s\n' "$list" $COMPRESS $list fi exit 0