install.sh etc.: tighter "perl" specification

David Lee t.d.lee at DURHAM.AC.UK
Fri Jul 2 18:18:14 IST 2004


Julian,

I attach a pair of patches to tighten up both the determination of, and
the use of, "perl" where there are multiple possibilities, typically
"/usr/bin/perl" and "/usr/local/bin/perl".

Use: I change occurence of "perl ..." to "$PERL ...".  (And where it calls
"./CheckModuleVersion" this becomes "$PERL ./CheckModuleVersion".)  This

Determination:  The "ignore-perl" technique didn't allow flexibility in
choice of "perl".  It also potentially allowed ambiguity to slip through.
So I changed "ignore-perl" into "--perl=/path/to/perl", thereby making the
user with such a system have to think about which version they really
want.  (Behaviour with only a single "perl": progresses as before;
behaviour with two perls with no disambiguation stops as before.)

The two patches are:
   install.sh:  involves both determination and use.

   install.tar-fns.sh: involves use (so depends upon "install.sh").

As a side-effect, I tidied up the argument handling to be option-like.
(It also has the advantages of (a) compatibility with autoconf's
"./configure" for possible future flexibility and (b) transitionally
bringing this to the attention of folk who had use the "ignore-perl"
syntax.  But you can, if you wish, ignore this part of the change for the
time being.)

I'm also working on some of the annoying little wrinkles that beset the
installation of perl modules on Solaris (and other?) systems.  But more on
that later.

Hope that helps.  Best wishes.


--

:  David Lee                                I.T. Service          :
:  Systems Programmer                       Computer Centre       :
:                                           University of Durham  :
:  http://www.dur.ac.uk/t.d.lee/            South Road            :
:                                           Durham                :
:  Phone: +44 191 334 2752                  U.K.                  :

-------------------------- MailScanner list ----------------------
To leave, send    leave mailscanner    to jiscmail at jiscmail.ac.uk
Before posting, please see the Most Asked Questions at
http://www.mailscanner.biz/maq/     and the archives at
http://www.jiscmail.ac.uk/lists/mailscanner.html
-------------- next part --------------
--- install.sh.orig	Tue Jun  1 16:13:24 2004
+++ install.sh	Fri Jul  2 17:58:37 2004
@@ -18,6 +18,66 @@
   echo
 }
 
+###################
+# Parse arguments: "./install.sh --help" for more details.
+# This is blatantly plagiarised from the typical "./configure" produced by
+# "autoconf".  If we need to get more complicated, then we should probably
+# migrate towards using "autoconf" itself.  (Hence not optimising this part, to
+# preserve resemblance and encourage compability with "autoconf" conventions.)
+
+as_me=`(basename "$0") 2>/dev/null`
+
+ac_init_help=
+perl=
+nodeps=
+for ac_option
+do
+  ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
+
+  case $ac_option in
+  --perl=*)
+    perl=$ac_optarg ;;
+
+  --nodeps)
+    nodeps=$ac_option ;;
+
+  --help | -h)
+    ac_init_help=long ;;
+
+  -*) { echo "$as_me: error: unrecognized option: $ac_option
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; }
+    ;;
+
+  *) { echo "$as_me: error: unrecognized argument: $ac_option
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; }
+    ;;
+
+  esac
+done
+
+if test "$ac_init_help" = "long"; then
+    cat <<_ACEOF
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+  -h, --help              display this help and exit
+  --perl=PERL             location of perl binary to use
+  --nodeps                ignore dependencies when installing MailScanner
+
+_ACEOF
+
+fi
+
+test -n "$ac_init_help" && exit 0
+
+# Set variables for later use
+PERL=$perl
+NODEPS=$nodeps
+
+###################
+# Main program
+
 # Are we on an RPM system? If so, use rpm commands to do everything
 echo
 if [ -x /bin/rpmbuild ]; then
@@ -63,15 +123,11 @@
   DISTTYPE=rpm
 fi
 
-#
-# Read the installation-specific stuff and do any extra checks
-#
-. ./install.${DISTTYPE}-fns.sh
-
-# Check they don't have 2 Perl installations, this will cause all sorts
-# of grief later.
-echo
-if [ \! "x$1" = "xignore-perl" ] ; then
+# Have they not explicitly specified a perl installation?
+if [ "x$PERL" = "x" ] ; then
+  # Check they don't have 2 Perl installations, this will cause all sorts
+  # of grief later.
+  echo
   if [ -x /usr/bin/perl -a -f /usr/local/bin/perl -a -x /usr/local/bin/perl ] ;
   then
     echo You appear to have 2 versions of Perl installed,
@@ -82,22 +138,26 @@
     echo
     echo If you do not want to do that, and really want to continue,
     echo then you will need to run this script as
-    echo '        ./install.sh ignore-perl'
+    echo "        $0 --perl=/path/to/perl"
+    echo substituting \'/path/to\' appropriately. 
     echo
     exit 1
   else
-    echo Good, you appear to only have 1 copy of Perl installed.
+    PERLPATH="/usr/bin /usr/local/bin"
+    PERL=`findprog perl $PERLPATH`
+    echo Good, you appear to only have 1 copy of Perl installed: $PERL
   fi
-fi
 
-# Check to see if they want to ignore dependencies in the final
-# MailScanner RPM install.
-if [ "x$1" = "xnodeps" -o "x$2" = "xnodeps" ]
-then
-  NODEPS='--nodeps'
-else
-  NODEPS=
 fi
+if [ \! -x $PERL ] ; then
+  echo No executable perl $PERL . Exiting.
+  exit 1
+fi
+
+#
+# Read the installation-specific stuff and do any extra checks
+#
+. ./install.${DISTTYPE}-fns.sh
 
 # JKF This needs to be a lot cleverer to correctly check
 # JKF /usr/perl5/bin and /usr/lib/perl5/*/bin and /usr/lib/perl5/bin as well.
@@ -141,7 +201,7 @@
 echo
 echo If this fails due to dependency checks, and you wish to ignore
 echo these problems, you can run
-echo '    ./install.sh nodeps'
+echo "    $0 --nodeps"
 sleep 2
 
 echo
@@ -153,7 +213,7 @@
 do
   # If the module version is already installed, go onto the next one
   # (unless it is MIME-tools which is always rebuilt.
-  if ./CheckModuleVersion ${MODNAME} ${VERS} ; then
+  if $PERL ./CheckModuleVersion ${MODNAME} ${VERS} ; then
     echo Oh good, module ${MODNAME} version ${VERS} is already installed.
     echo
     sleep 2
-------------- next part --------------
--- install.tar-fns.sh.orig	Tue Jun  1 16:13:24 2004
+++ install.tar-fns.sh	Thu Jul  1 21:34:48 2004
@@ -52,7 +52,7 @@
 
 # If we are using gcc on Solaris, we need to fix up the command-line flags
 if [ "x$CCISGCC" = "xyes" -a "x$ARCHITECT" = "xsolaris" ]; then
-  CONFIGPM=`perl -e 'foreach (@INC) { print("$_"),exit if (-f "$_/Config.pm"); }'`
+  CONFIGPM=`$PERL -e 'foreach (@INC) { print("$_"),exit if (-f "$_/Config.pm"); }'`
   echo
   echo As you are running gcc on Solaris, the Makefiles created when
   echo installing Perl modules won\'t work properly, so I am temporarily
@@ -60,7 +60,7 @@
   echo when I have finished.
   echo Found Config.pm in $CONFIGPM
   mkdir -p ${TMPINSTALL}${CONFIGPM}
-  perl -p -e 's/-KPIC|-xO3|-xdepend//g' $CONFIGPM/Config.pm > ${TMPINSTALL}${CONFIGPM}/Config.pm
+  $PERL -p -e 's/-KPIC|-xO3|-xdepend//g' $CONFIGPM/Config.pm > ${TMPINSTALL}${CONFIGPM}/Config.pm
   PERL5OPT="-I${TMPINSTALL}${CONFIGPM}"
   export PERL5OPT
   sleep 10
@@ -126,12 +126,12 @@
       (
         cd ${TMPBUILDDIR}/${MODFILE}-${VERS}
         if [ "x$TEST" = "xyes" ]; then
-          perl Makefile.PL
-          #[ "x$CCISGCC" = "xyes" ] && perl -pi.bak -e 's/-KPIC|-xO3|-xdepend//g' Makefile
+          $PERL Makefile.PL
+          #[ "x$CCISGCC" = "xyes" ] && $PERL -pi.bak -e 's/-KPIC|-xO3|-xdepend//g' Makefile
           $MAKE && $MAKE test && $MAKE install
         else
-          perl Makefile.PL && $MAKE && $MAKE install
-          [ "x$CCISGCC" = "xyes" ] && perl -pi.bak -e 's/-KPIC|-xO3|-xdepend//g' Makefile
+          $PERL Makefile.PL && $MAKE && $MAKE install
+          [ "x$CCISGCC" = "xyes" ] && $PERL -pi.bak -e 's/-KPIC|-xO3|-xdepend//g' Makefile
           $MAKE && $MAKE install
         fi
       )
@@ -202,7 +202,7 @@
   fi
   unpackarchive /opt `ls ${PERL_DIR}/MailScanner*.tar.gz | tail -1`
 
-  VERNUM=`cd ${PERL_DIR}; ls MailScanner*.tar.gz | perl -pe 's/^MailScanner-([0-9.]+).*$/$1/' | tail -1`
+  VERNUM=`cd ${PERL_DIR}; ls MailScanner*.tar.gz | $PERL -pe 's/^MailScanner-([0-9.]+).*$/$1/' | tail -1`
   echo Have just installed version ${VERNUM}.
 
   # Create the symlink if not already present


More information about the MailScanner mailing list