home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / bin / installwatch < prev    next >
Encoding:
Text File  |  2006-08-20  |  7.2 KB  |  356 lines

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