"Fossies" - the Fresh Open Source Software Archive

Member "checkinstall-1.6.2/installwatch/installwatch" (16 Nov 2008, 7291 Bytes) of package /linux/privat/old/checkinstall-1.6.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 #$Id: installwatch,v 0.6.7.0 2007/12/04 07:35:04 gna Exp $
    3 
    4 #set -x
    5 
    6 PREFIX=${PREFIX:-#PREFIX#}
    7 
    8 HACK="PREFIX"
    9 HACK="#$HACK#";
   10 
   11 if test "$PREFIX" = "$HACK" ; then
   12     echo 'This script has not been installed'
   13     echo 'Please run "make install"'
   14     exit 1
   15 fi
   16 
   17 LIBDIR=$DESTDIR$PREFIX/lib
   18 LIB64_PLATFORM=false
   19 case `uname -m` in
   20     x86_64|ppc64|s390x)
   21     LIB64_PLATFORM=true
   22     ;;
   23 esac
   24 if test -d $PREFIX/lib64 && test "$LIB64_PLATFORM" = "true" ; then
   25     LIBDIR=$PREFIX/lib64
   26 else
   27     LIBDIR=$PREFIX/lib
   28 fi
   29   
   30 BASE_TMP_DIR=/tmp
   31   
   32 INSTALLWATCH_VERSION=0.7.0beta7
   33   
   34  
   35 #
   36 # ##############################################################################
   37 #
   38 # Function definitions
   39 #
   40 #
   41 
   42 function ckversion {
   43     echo
   44     echo -n "installwatch $INSTALLWATCH_VERSION, "
   45     echo    "Copyright 1998 Pancrazio de Mauro"
   46     echo    "Copyright 2002 Felipe Eduardo Sanchez Diaz Duran"
   47     echo    "           This software is released under the GNU GPL."
   48 }
   49 
   50 function usage() {
   51 
   52     (
   53     ckversion
   54     echo
   55     echo "Usage: installwatch [options] [command [command arguments]]"
   56     echo "Options:"
   57     echo
   58     echo "-r, --root=<rootdir>           Sets the directory under which will be stored "
   59     echo "                               meta-infos and translated files. "
   60     echo "-t, --transl=<yes|no>          Toggle translation capabilities "
   61     echo "-b, --backup=<yes|no>          Toggle backup capabilities "
   62     echo "-e, --exclude=<dir1,...,dirN>  Sets a neutral directory list, that won't be"
   63     echo "                                concerned by translation or backups. "
   64     echo "-o, --logfile=<logfile>        Sets the log file to be used. "
   65     echo "-d, --dbgfile=<dbgfile>        Sets the debug file to be used. "
   66     echo "-v, --dbglvl=<dbglvl>          Sets the debug level to be used. "
   67     )
   68     exit 1
   69 }       
   70 
   71 function help_notice() {
   72     echo
   73     echo "Use --help or -h to get more information"
   74     echo
   75     exit 1 
   76 }
   77 
   78 function boolean_usage() {
   79     echo
   80     echo "$2 is an invalid value for $1" 
   81     help_notice
   82     exit 1
   83 }
   84 
   85 function make_temp {
   86     local mkt_refdir=$1
   87     local mkt_wrkdir=""
   88 
   89     mkt_wrkdir=`mktemp -q -d -p ${BASE_TMP_DIR}`
   90 
   91     eval $mkt_refdir=\$mkt_wrkdir
   92 }
   93 
   94 #
   95 #
   96 # Function definitions
   97 #
   98 # ##############################################################################
   99 #
  100 
  101 #
  102 # ##############################################################################
  103 #
  104 # Options and arguments parsing and validation
  105 #
  106 #
  107 
  108 CKNAME=`basename $0`
  109 PARAMS=`getopt -a -n $CKNAME -o +r:e:o:d:v:tb -l root:,transl:,backup:,exclude:,logfile:,dbgfile:,dbglvl:,help,version,copyright -- "$@"`
  110 
  111 [ $? -gt 0 ] && help_notice
  112 
  113 eval set -- $PARAMS
  114 
  115 unset INSTW_ROOTPATH
  116 unset INSTW_TRANSL
  117 unset INSTW_BACKUP
  118 unset INSTW_LOGFILE
  119 unset INSTW_DBGFILE
  120 unset INSTW_DBGLVL
  121 unset INSTW_EXCLUDE
  122 
  123 while [ "$1" != "--" ]; do
  124     case "$1" in
  125         -h|-H|--help)
  126             usage;;
  127         -r|--root)
  128             shift
  129             INSTW_ROOTPATH=`eval echo $1` 
  130             ;;
  131         -e|--exclude)
  132             shift
  133             INSTW_EXCLUDE=`eval echo $1`
  134             ;;
  135         -o|--logfile)
  136             shift
  137             INSTW_LOGFILE=`eval echo $1`
  138             ;;
  139         -d|--dbgfile)
  140             shift
  141             INSTW_DBGFILE=`eval echo $1`
  142             ;;
  143         -v|--dbglvl)
  144             shift
  145             INSTW_DBGLVL=`eval echo $1`
  146             ;;
  147         -t)
  148             INSTW_TRANSL=1
  149             ;;
  150         --transl)
  151             shift
  152             case `eval echo $1` in
  153                 "1"|"yes"|"")
  154                     INSTW_TRANSL=1
  155                     ;;
  156                 "0"|"no")
  157                     INSTW_TRANSL=0
  158                     ;;
  159                 *)
  160                     boolean_usage "--transl" $1
  161             esac
  162             ;;
  163         -b)
  164             INSTW_BACKUP=1
  165             ;;
  166         --backup)
  167             shift
  168             case `eval echo $1` in
  169                 "1"|"yes"|"")
  170                     INSTW_BACKUP=1
  171                     ;;
  172                 "0"|"no")
  173                     INSTW_BACKUP=0
  174                     ;;
  175                 *)
  176                     boolean_usage "--backup" $1
  177             esac
  178             ;;
  179         --copyright|--version)
  180             cat << EOF
  181 
  182 Copyright (C) 1998 Pancrazio `Ezio' de Mauro 
  183 Copyright (C) 2002 Felipe Eduardo Sanchez Diaz Duran <izto@asic-linux.com.mx>
  184 
  185     This program is free software; you can redistribute it and/or modify
  186     it under the terms of the GNU General Public License as published by
  187     the Free Software Foundation; either version 2 of the License, or
  188     (at your option) any later version.
  189 
  190     This program is distributed in the hope that it will be useful,
  191     but WITHOUT ANY WARRANTY; without even the implied warranty of
  192     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  193     GNU General Public License for more details.
  194 
  195     You should have received a copy of the GNU General Public License
  196     along with this program; if not, write to the Free Software
  197     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  198 
  199 EOF
  200             exit 0
  201             ;;
  202     esac
  203     shift
  204 done
  205 
  206   #
  207   # ##############################################
  208   #
  209 
  210   # do we have an installation process command
  211 shift
  212 if [ "$1" = "" ]; then
  213     echo
  214     echo "Error : You must specify a command !!!"
  215     echo
  216     usage
  217     exit 1
  218 fi
  219 
  220 if [ -u "$1" ]; then
  221     echo "Warning: `basename $0` may not work with suid programs" 
  222 fi
  223   # we must have a root path defined
  224 if [ "${INSTW_ROOTPATH}_" = "_" ]; then
  225     make_temp "INSTW_ROOTPATH"
  226     echo
  227     echo "INFO : Using a default root directory : ${INSTW_ROOTPATH}"
  228     echo
  229 fi
  230 if [ ! -d "${INSTW_ROOTPATH}" ]; then
  231     echo
  232     echo "The root directory is mandatory ."
  233     echo
  234     usage
  235     exit 1
  236 fi
  237 if [ "${INSTW_ROOTPATH:((${#INSTW_ROOTPATH}-1)):1}" = "/" ]; then
  238     INSTW_ROOTPATH="${INSTW_ROOTPATH%/}"
  239 fi
  240 
  241 export INSTW_ROOTPATH
  242 
  243 if [ "${INSTW_BACKUP}_" = "_" ]; then
  244     INSTW_BACKUP=0;
  245 fi  
  246 export INSTW_BACKUP
  247 
  248 if [ "${INSTW_TRANSL}_" = "_" ]; then
  249     INSTW_TRANSL=0;
  250 fi  
  251 export INSTW_TRANSL
  252 
  253 if [ "${INSTW_LOGFILE}_" = "_" ]; then
  254     INSTW_LOGFILE="${INSTW_ROOTPATH}/logfile"
  255 fi
  256 export INSTW_LOGFILE
  257 
  258 if [ "${INSTW_DBGFILE}_" = "_" ]; then
  259     INSTW_DBGFILE="${INSTW_ROOTPATH}/dbgfile"
  260 fi
  261 export INSTW_DBGFILE
  262 
  263 if [ "${INSTW_DBGLVL}_" = "_" ]; then
  264     INSTW_DBGLVL=0
  265 fi
  266 export INSTW_DBGLVL
  267 
  268 [ $INSTW_DBGLVL -gt 0 ] && echo "debug: INSTW_EXCLUD before sort =${INSTW_EXCLUDE}"
  269 INSTW_EXCLUDE="/dev,/proc,/tmp,/var/tmp,${INSTW_EXCLUDE}"
  270 OFS="$IFS"
  271 IFS=','
  272 INSTW_EXCLUDE=$(for name in $INSTW_EXCLUDE; do
  273     echo $name
  274     done | sort -u |
  275     while read elem; do
  276         echo -n "$elem,"
  277     done)
  278 export INSTW_EXCLUDE
  279 IFS="$OIFS"
  280 
  281 if [ "${INSTW_LOGFILE}_" != "_" ]; then
  282       # If INSTW_LOGFILE is a relative path, it must become absolute
  283     if echo ${INSTW_LOGFILE} | grep -qv '^/' ; then
  284         INSTW_LOGFILE="$(pwd)/${INSTW_LOGFILE}"
  285     fi
  286 
  287     export INSTW_LOGFILE
  288     if cat /dev/null >"${INSTW_LOGFILE}"; then
  289         true
  290     else
  291         echo
  292         echo "Error : Unable to prepare ${INSTW_LOGFILE}"
  293         echo
  294         exit 1
  295     fi
  296 fi
  297 
  298 if [ "${INSTW_DBGFILE}_" != "_" ]; then
  299       # If INSTW_DBGFILE is a relative path, it must become absolute
  300     if echo ${INSTW_DBGFILE} | grep -qv '^/' ; then
  301         INSTW_DBGFILE="$(pwd)/${INSTW_DBGFILE}"
  302     fi
  303 
  304     export INSTW_DBGFILE
  305     if cat /dev/null >"${INSTW_DBGFILE}"; then
  306         true
  307     else
  308         echo
  309         echo "Error : Unable to prepare ${INSTW_DBGFILE}"
  310         echo
  311         exit 1
  312     fi
  313 fi
  314 
  315 
  316 #
  317 #
  318 # Options and arguments parsing and validation
  319 #
  320 # ##############################################################################
  321 #
  322 
  323 if [ "$LD_PRELOAD" ]; then
  324     LD_PRELOAD="$LIBDIR/installwatch.so:$LD_PRELOAD"
  325 else
  326     LD_PRELOAD="$LIBDIR/installwatch.so"
  327 fi
  328 export LD_PRELOAD
  329 
  330 if [ $INSTW_DBGLVL -gt 0 ]; then 
  331    echo "debug: INSTW_EXCLUDE=${INSTW_EXCLUDE}"
  332    echo "debug: INSTW_ROOTPATH=${INSTW_ROOTPATH}"
  333    echo "debug: INSTW_LOGFILE=${INSTW_LOGFILE}"
  334    echo "debug: INSTW_DBGFILE=${INSTW_DBGFILE}"
  335    echo "debug: INSTW_DBGLVL=${INSTW_DBGLVL}"
  336 fi
  337 
  338 "$@"
  339 
  340 if [ $? -eq 0 ]; then
  341    FAIL=0
  342 else
  343    FAIL=1
  344 fi
  345 
  346 unset LD_PRELOAD
  347 
  348 exit $FAIL