"Fossies" - the Fresh Open Source Software Archive

Member "checkinstall-1.6.2/checkinstall" (26 Dec 2009, 83763 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.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 #!/bin/bash
    2 ##############################################################################
    3 #         $Id: checkinstall,v 1.6.2.17 2009/12/26 13:15:21 izto Exp $ 
    4 #                           ########################                         
    5 #                                                                            
    6 #
    7 #                             CheckInstall v1.6.2
    8 #
    9 #  Installs a compiled program from the program's source directory using     
   10 #  "make install" or any other command supplied on checkinstall's command  
   11 #  line. checkinstall will create a Slackware, RPM or Debian compatible package
   12 #  named after the source directory's name and install it using your standard  
   13 #  package administration utilities.                                      
   14 #                                                                            
   15 #  This version of checkinstall needs enough free space on the partition     
   16 #  holding the temp dir (see BASE_TEMP_DIR below) to write there a temporary 
   17 #  copy of the package.              
   18 #                                                                            
   19 #  Copyright (C) 2004 Felipe Eduardo Sanchez Diaz Duran <izto@asic-linux.com.mx>
   20 #  
   21 #
   22 #    This program is free software; you can redistribute it and/or modify
   23 #    it under the terms of the version 2 of the GNU General Public License
   24 #    as published by the Free Software Foundation
   25 #
   26 #    This program is distributed in the hope that it will be useful,
   27 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
   28 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   29 #    GNU General Public License for more details.
   30 #
   31 #    You should have received a copy of the GNU General Public License
   32 #    along with this program; if not, write to the Free Software
   33 #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   34 #
   35 ############################################################################
   36 
   37 
   38 # Trap the INT signal (ctrl-c, for example)
   39 trap trapint 2
   40 
   41 CHECKINSTALL_VERSION=1.6.2
   42 
   43 # locate the file or directory that the parameter corresponds to;
   44 # always prints absolute path
   45 function followlinks () {
   46     local entry="$1"
   47     local symlink
   48 
   49     case "$entry" in /*) true ;;
   50         *) entry="`pwd`/$entry";;
   51     esac
   52     if [ -L "$entry" ]; then
   53         symlink=`ls -l "$entry" | sed -e 's/.* -> //'`
   54         
   55         case "$symlink" in /*) entry="$symlink";;
   56             *) entry=`dirname "$entry"`/$symlink;;
   57         esac
   58         followlinks "$entry"
   59     else
   60         echo "$entry"
   61     fi
   62 }
   63 
   64 INSTALLDIR=`followlinks "$0"`
   65 INSTALLDIR=`dirname "$INSTALLDIR"`/..
   66 
   67 # gettext variables
   68 export TEXTDOMAINDIR="$INSTALLDIR"/lib/checkinstall/locale
   69 export TEXTDOMAIN=checkinstall
   70 
   71 # .spec file path
   72 DIRECTORIO_FUENTE=`pwd`
   73 PKG_BASENAME="`basename "$DIRECTORIO_FUENTE"`"
   74 SPEC_PATH=${PKG_BASENAME}.spec
   75 
   76 #############################################################################
   77                            # Function definitions #
   78                            ########################
   79 
   80 # Enable alias expansion in command substitution
   81 shopt -s expand_aliases 
   82 
   83 # Vefify that we have gettext available
   84 gettext "Bye." &> /dev/null
   85 
   86 if [ $? -gt 0 ]; then
   87    alias ck_gettext="echo -e"
   88 else
   89    alias ck_gettext="gettext -s --"
   90 fi
   91 
   92 ## gettext echo with newline at the end
   93 function echog() {
   94    local format="$1"
   95    shift
   96    printf -- "$(ck_gettext "$format")\n" "$@" >&2
   97 }
   98 
   99 ## gettext echo with NO newline at the end
  100 function   echogn() {
  101    local format="$1"
  102    shift
  103    printf -- "$(ck_gettext "$format")" "$@" >&2
  104 }
  105 
  106 
  107 
  108 function ckversion {
  109    echo
  110    echo "checkinstall $CHECKINSTALL_VERSION, Copyright 2009 Felipe Eduardo Sanchez Diaz Duran"
  111    echog "           This software is released under the GNU GPL."
  112 }
  113 
  114 
  115 
  116 function usage() {
  117 
  118 # If the user has a default pager defined in the PAGER environment variable,
  119 # we'll use that. If not, we'll use "more".
  120 
  121 ! [ "$PAGER" ] && PAGER=more
  122 
  123 
  124    echo
  125    echog "Usage: checkinstall [options] [command [command arguments]]"
  126    echog "Options:"
  127    echo
  128    echog "*Package type selection*"
  129    echo
  130    echog "-t,--type=<slackware|rpm|debian> Choose packaging system"
  131    echog "-S                               Build a Slackware package"
  132    echog "-R                               Build a RPM package"
  133    echog "-D                               Build a Debian package"
  134    echo
  135    echog "*Install options*"
  136    echo
  137    echog "--install=<yes|no>             Toggle created package installation"
  138    echog "--fstrans=<yes|no>             Enable/disable the filesystem translation code"
  139    echo
  140    echog "*Scripting options*"
  141    echo
  142    echog "-y, --default                  Accept default answers to all questions"
  143    echog "--pkgname=<name>               Set name"
  144    echog "--pkgversion=<version>         Set version"
  145    echog "-A, --arch, --pkgarch=<arch>   Set architecture"
  146    echog "--pkgrelease=<release>         Set release"
  147    echog "--pkglicense=<license>         Set license"
  148    echog "--pkggroup=<group>             Set software group"
  149    echog "--pkgsource=<source>           Set source location"
  150    echog "--pkgaltsource=<altsource>     Set alternate source location"
  151    echog "--pakdir=<directory>           The new package will be saved here"
  152    echog "--maintainer=<email addr>      The package maintainer (.deb)"
  153    echog "--provides=<list>              Features provided by this package"
  154    echog "--requires=<list>              Features required by this package"
  155    echog "--conflicts=<list>             Packages that this package cannot be installed with (.deb)"
  156    echog "--replaces=<list>              Packages that this package replaces (.deb)"
  157    echog "--rpmflags=<flags>             Pass this flags to the rpm installer"
  158    echog "--rpmi                         Use the -i flag for rpm when installing a .rpm"
  159    echog "--rpmu                         Use the -U flag for rpm when installing a .rpm"
  160    echog "--dpkgflags=<flags>            Pass this flags to the dpkg installer"
  161    echog "--spec=<path>                  .spec file location"
  162    echog "--nodoc                        Do not include documentation files"
  163    echo
  164    echog "*Info display options*"
  165    echo
  166    echog "-d<0|1|2>                      Set debug level"
  167    echog "-si                            Run an interactive install command"
  168    echog "--showinstall=<yes|no>         Toggle interactive install command"
  169    echog "-ss                            Run an interactive Slackware installation script"  
  170    echog "--showslack=<yes|no>           Toggle interactive Slackware installation script"
  171    echo
  172    echog "*Package tuning options*"
  173    echo
  174    echog "--autodoinst=<yes|no>          Toggle the creation of a doinst.sh script"
  175    echog "--strip=<yes|no>               Strip any ELF binaries found inside the package"
  176    echog "--stripso=<yes|no>             Strip any ELF binary libraries (.so files)" 
  177    echog "--addso=<yes|no>               Search for any shared libs and add"
  178    echog "                               them to /etc/ld.so.conf"
  179    echog "--reset-uids=<yes|no>          Reset perms for all files/dirs to 755 and"
  180    echog "                               the owner/group for all dirs to root.root"
  181    echog "--gzman=<yes|no>               Compress any man pages found inside the package"
  182    echog "--docdir=<path>                Where to put documentation files"
  183    echog "                               The package name+version gets automatically appended."
  184    echog "                               To avoid that prefix the path with a colon (:)."
  185    echog "--umask=<mask>                 Set the umask value"
  186    echog "--exclude=<file|dir[,...]>     Exclude these files/directories from the package"
  187    echog "--include=<listfile>           Force the inclusion in the package of the"
  188    echog "                               files/dirs listed in \"listfile\""
  189    echog "--inspect                      Inspect the package's file list"
  190    echog "--review-spec                  Review the spec file before creating a .rpm"
  191    echog "--review-control               Review the control file before creating a .deb"
  192    echog "--newslack                     Use the new (8.1+) Slackware description format"
  193    echog "                               (\"--newslack\" implies \"-S\")"
  194    echog "--with-tar=/path/to/tar        Manually set the path to the tar binary" 
  195    echog "                               in this system"
  196    echo
  197    echog "*Cleanup options*"
  198    echo
  199    echog "--deldoc=<yes|no>              Delete doc-pak upon termination"
  200    echog "--deldesc=<yes|no>             Delete description-pak upon termination"
  201    echog "--delspec=<yes|no>             Delete spec file upon termination"
  202    echog "--bk                           Backup any overwritten files"
  203    echog "--backup=<yes|no>              Toggle backup"
  204    echo
  205    echog "*About CheckInstall*"
  206    echo
  207    echog "--help, -h                     Show this message"
  208    echog "--copyright                    Show Copyright information"
  209    echog "--version                      Show version information"
  210    echo
  211    exit 1
  212 }
  213 
  214 function help_notice() {
  215  
  216 echo
  217 echog "Use --help or -h to get more information"
  218 echo
  219 exit 1 
  220 
  221 }
  222 
  223 function boolean_usage() {
  224    echo
  225    echog "%s is an invalid value for %s" "$2" "$1"
  226    help_notice
  227    exit 1
  228 }
  229 
  230 
  231 # 001117-BaP: Define a function or two
  232 
  233 function yorn {
  234 
  235 
  236    if [ "$1" ]; then     # If there is no default value specified
  237        DEFAULTYN="$1"     # then the default is "y"
  238     else
  239        DEFAULTYN="y"
  240     fi
  241     DEFAULTYN=`echo $DEFAULTYN | tr 'A-Z' 'a-z'`
  242 
  243     if [ "$DEFAULTYN" = "y" ]; then  
  244        echo -n " [y]: "              # Print the default option
  245     else
  246        echo -n " [n]: "
  247     fi
  248     
  249 if [ $ACCEPT_DEFAULT -eq 0 ]; then     # Should we accept all the defaults?
  250 
  251     read YN
  252     YN=`echo $YN | tr 'A-Z' 'a-z'`
  253     ! [ "$YN" ] && YN=$DEFAULTYN          # If the user pressed ENTER then 
  254 
  255 else
  256    YN=$DEFAULTYN
  257    echo $YN
  258 fi
  259 
  260     if [ "$YN" = "y" ] ;then    # We return something useful for a 
  261        return 0                 # simpler sintax ahead (12/dic/2000-Izto)
  262     else
  263        return 1
  264     fi
  265 
  266 
  267 }
  268 
  269 
  270 
  271 # dec/10/2000-Izto
  272 # Prints OK or FAILED! depending on previous command return value
  273 
  274 function okfail () {
  275  if [ $? -gt 0 ]; then
  276     echog ' FAILED!'
  277     return 1
  278  else
  279     echog 'OK'
  280     return 0
  281  fi
  282 }
  283 
  284 function restore_backup {
  285  # If we have translation turned on then we didn't do a backup
  286  if [ "${TRANSLATE}" = "1" ]; then return 0; fi
  287 
  288  # Else, restore the backup if it exists
  289  
  290  rm -rf ${TMP_DIR}/BACKUP/no-backup &> /dev/null
  291 
  292  ls ${TMP_DIR}/BACKUP/*  &> /dev/null
  293  if [ $? -eq 0 ]; then
  294     echogn "Restoring overwritten files from backup..."
  295     cd ${TMP_DIR}/BACKUP
  296        files=$(ls -A)
  297        $TAR -cpf - $files | $TAR -f - -xvpC / &> /dev/null
  298     okfail
  299     echo
  300  fi
  301 } 
  302 
  303 
  304 function trapint {
  305  echo
  306  echo
  307  echog "*** SIGINT received ***"
  308  cleanup
  309 }
  310 
  311 function cleanup {
  312  echo
  313  restore_backup
  314  echogn "Cleaning up..."
  315  cd "$DIRECTORIO_FUENTE"
  316  [ -n "${BUILDROOT}" ] && [ -d ${BUILDROOT} ] && rm -rf "${BUILDROOT}"
  317  if [ "$DEBUG" -eq 0 ]; then
  318     [ -n "${TMP_DIR}" ] && [ -d ${TMP_DIR} ] && rm -rf ${TMP_DIR}
  319     rm -f checkinstall-debug*
  320  else
  321     echogn "(Debugging mode on, KEEPING temp dir $TMP_DIR)..."
  322  fi
  323  [ -n "${RPMSOURCEDIR}" ] &&
  324    [ -f "${RPMSOURCEDIR}/SOURCES/${PKG_BASENAME}.tgz" ] &&
  325    rm -f "${RPMSOURCEDIR}/SOURCES/${PKG_BASENAME}.tgz"
  326 
  327  # If we had a pre-existing postinstall-pak, we keep it as it was.
  328  if [ -f ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ]; then
  329     mv ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ${DIRECTORIO_FUENTE}/postinstall-pak
  330  fi
  331 
  332  true; okfail
  333  echo
  334  echog "Bye."
  335  echo
  336  exit 1
  337 }
  338 
  339 # Function to copy a directory with permissions, honours setuid, setgid,
  340 # sticky bits, owner, group etc.
  341 #
  342 # A bit lengthy and slow but very few directories in the largest of
  343 # packages have to be copied like this.
  344  
  345 function  dircopy() {
  346    src_dir="$1" dest_dir="$2"
  347    getflags() {
  348      col=$1 dir="$2"
  349      permissions="`ls -ld "$dir" | awk '{print $1}'`"
  350      mask="."
  351      bit=2
  352      while [ $bit -lt $col ]; do mask="$mask."; bit=`expr $bit + 1`; done
  353      mask="$mask\(.\)"
  354      bit=$col
  355      while [ $bit -lt 10 ]; do mask="$mask."; bit=`expr $bit + 1`; done
  356      permission="`echo $permissions | sed "s/$mask/\1/" | grep -v -- '-'`"
  357      case "$permission" in
  358        s) echo "xs";; S) echo "s";; t) echo "xt";; T) echo "t";;
  359        *) echo $permission;;
  360      esac
  361    }
  362    col=2 chmod_args=""
  363    set=u flags=""
  364    while [ $col -le 4 ]; do
  365      flags="$flags`getflags $col "$src_dir"`"; col=`expr $col + 1`
  366    done
  367    [ -n "$flags" ] && {
  368      chmod_args="$set+$flags"
  369    }
  370    set=g flags=""
  371    while [ $col -le 7 ]; do
  372      flags="$flags`getflags $col "$src_dir"`"; col=`expr $col + 1`
  373    done
  374    [ -n "$flags" ] && {
  375      [ -n "$chmod_args" ] && chmod_args="$chmod_args,"
  376      chmod_args="$chmod_args$set+$flags"
  377    }
  378    set=o flags=""
  379    while [ $col -le 10 ]; do
  380      flags="$flags`getflags $col "$src_dir"`"; col=`expr $col + 1`
  381    done
  382    [ -n "$flags" ] && {
  383      [ -n "$chmod_args" ] && chmod_args="$chmod_args,"
  384      chmod_args="$chmod_args$set+$flags"
  385    }
  386    [ -d "$dest_dir" ] || {
  387      mkdir -p "$dest_dir"
  388      chmod 700 "$dest_dir"
  389    }
  390    [ -n "$chmod_args" ] && chmod $chmod_args "$dest_dir"
  391    chown "`ls -ld "$src_dir" | awk '{print $3}'`" "$dest_dir"
  392    chgrp "`ls -ld "$src_dir" | awk '{print $4}'`" "$dest_dir"
  393  }
  394 
  395 #
  396 # Read spec file if it exists or (pre)set variables if they don't exist
  397 #
  398 
  399 function getparameter () {
  400 
  401    RES=`egrep "$1" < ${SPEC_PATH} \
  402     | cut -f2 -d: | sed 's/^ *//g' | sed 's/ *$//g' `
  403    shift
  404    echo "$RES" | sed 's/^ *//g' | sed 's/ *$//g' 
  405 
  406 }
  407 
  408 # This function is used to properly escape shell commands, so
  409 # we don't interpret the install command twice. This is useful
  410 # for making commands like 'make CC="gcc -some -options" install'
  411 # work as expected.
  412 
  413 function shell_escape() {
  414     for str in "$@" ; do
  415         echo -n "\"$str\" "
  416     done;
  417     echo
  418 }
  419 
  420 # Output all the parents of the files given as arguments to stdout. Remove
  421 # duplicates.
  422 function list_parents {
  423     src="$*"
  424     files=`for f in $src; do
  425     echo "$f" | awk '
  426     BEGIN{
  427         FS = "/"
  428     }
  429     {
  430         for (i=1;i<NF;i++){
  431             for (j=1;j<=i;j++){
  432                 printf "%s",$(j)
  433                 if (j != i){
  434                         printf "/"
  435                     }
  436             }
  437             printf " "
  438         }
  439     }'
  440     done`
  441 
  442     echo "${files}"  | tr ' ' '\n' | uniq | tr '\n' ' '
  443     return $?
  444 }
  445 
  446 # Copy some file ($1) whose path is given relatively to some root ($2) to a
  447 # destination ($3). If --deref-parents appear as first argument, then symlink
  448 # parents will not be copied as symlinks but as ordinary directories. All
  449 # permissions are preserved. The directories the source file was in are
  450 # preserved up to the root. The files that were copied are displayed on stdout
  451 function copy_dir_hierarchy {
  452     deref_parents=0
  453     if [ `echo "${1}" | egrep '^--deref-parents'` ]; then
  454         deref_parents=1
  455         shift
  456     fi
  457     src="${1}"
  458     root="${2}"
  459     dest="${3}"
  460 
  461     # All directories the file is in, e.g if src is
  462     # ./usr/local/lib/installwatch.so, then files will be . ./usr ./usr/local
  463     # ./usr/local/lib
  464     files=`list_parents ${src}`
  465 
  466     # Only use tar if there are parents
  467     echo "${files}" | egrep '[^[:space:]]' >/dev/null
  468     if [ $? -eq 0 ]; then
  469         if [ deref_parents -eq 1 ]; then
  470             # Add the -h option to the tar command for dereferencing
  471             $TAR --no-recursion -C "${root}" -cphf - $files | $TAR -f - -xvpC \
  472                 "${dest}"
  473         else 
  474             $TAR --no-recursion -C "${root}" -cpf - $files | $TAR -f - -xvpC \
  475                 "${dest}"
  476         fi
  477 
  478     fi
  479 
  480     $TAR -C "${root}" -cpf - $src | $TAR -f - -xvpC \
  481         "${dest}"
  482 
  483     return $?
  484 }
  485 
  486 
  487                       #################################
  488                       # Function definition ends here #
  489 #############################################################################
  490 
  491 # Show the version information
  492 ckversion
  493 echo
  494 
  495 CHECKINSTALLRC=${CHECKINSTALLRC:-${INSTALLDIR}/checkinstallrc}
  496 if ! [ -f $CHECKINSTALLRC ]; then
  497    echog "The checkinstallrc file was not found at:\n$CHECKINSTALLRC"
  498    echo
  499    echog "Assuming default values."
  500 else
  501 # Get our default settings from the rc file
  502 source $CHECKINSTALLRC
  503 fi
  504 
  505 
  506 # Arguments parsing
  507 
  508 CKNAME=`basename "$0"`
  509 PARAMS=`getopt -a -n $CKNAME -o +d:DA:t:RShHy -l arch:,type:,si,showinstall::,ss,showslack::,deldoc::,delspec::,deldesc::,strip::,addso::,install::,stripso::,gzman::,bk,backup::,autodoinst::,reset-uids::,fstrans::,spec:,exclude:,include:,pkgname:,pkgversion:,pkgrelease:,pkglicense:,pkggroup:,pkgsource:,pkgaltsource:,pakdir:,docdir:,requires:,provides:,conflicts:,replaces:,maintainer:,dpkgflags:,rpmflags:,pkgarch:,umask:,with-tar:,inspect,review-spec,review-control,newslack,help,nodoc,rpmi,rpmu,version,copyright,default -- "$@"`
  510 
  511 [ $? -gt 0 ] && help_notice
  512 
  513 eval set -- $PARAMS
  514 
  515 while [ "$1" != "--" ]; do
  516    case "$1" in
  517       -h|-H|--help)
  518          usage;;
  519       -d)
  520          shift
  521          case `eval echo $1` in
  522             0) DEBUG=0;;
  523             1|'') DEBUG=1;;
  524             2) DEBUG=2;;
  525             3) DEBUG=3;;
  526             4) DEBUG=4;;
  527             *)
  528                boolean_usage "-D" $1
  529          esac
  530          ;;
  531       -A|--arch|--pkgarch)
  532          shift
  533          ARCHITECTURE=`eval echo $1`
  534          ;;
  535       --umask)
  536          shift
  537          CKUMASK=`eval echo $1`
  538          ;;
  539       --pkgname)
  540          shift
  541          NAME=`eval echo $1`
  542          ;;
  543       --pkgversion)
  544          shift
  545          VERSION=`eval echo $1`
  546          ;;
  547       --pkgrelease)
  548          shift
  549          RELEASE=`eval echo $1`
  550          ;;
  551       --pkglicense)
  552          shift
  553          LICENSE=`eval echo $1`
  554          ;;
  555       --pkggroup)
  556          shift
  557      # note: we use PKG_GROUP instead of GROUP since (t)csh sets GROUP.
  558          PKG_GROUP=`eval echo $1`
  559          ;;
  560       --pkgsource)
  561          shift
  562          SOURCE=`eval echo $1`
  563          ;;
  564       --pkgaltsource)
  565          shift
  566          ALTSOURCE=`eval echo $1`
  567          ;;
  568       --pakdir)
  569          shift
  570          PAK_DIR=`eval echo $1`
  571          ;;
  572       --with-tar)
  573          shift
  574          TAR=`eval echo $1`
  575          ;;
  576       --docdir)
  577          shift
  578          DOC_DIR=`eval echo $1`
  579          ;;
  580       --provides)
  581          shift
  582          PROVIDES=`eval echo $1`
  583          ;;
  584       --conflicts)
  585          shift
  586          CONFLICTS=`eval echo $1`
  587          ;;
  588       --replaces)
  589          shift
  590          REPLACES=`eval echo $1`
  591          ;;
  592       --requires)
  593          shift
  594          REQUIRES=`eval echo $1`
  595          ;;
  596       --maintainer)
  597          shift
  598          MAINTAINER=`eval echo $1`
  599          ;;
  600       --dpkgflags)
  601          shift
  602          DPKG_FLAGS=`eval echo $1`
  603          ;;
  604       --rpmflags)
  605          shift
  606          RPM_FLAGS=`eval echo $1`
  607          ;;
  608       -t|--type)
  609          shift
  610          INSTYPE=`echo $1 | tr 'a-z' 'A-Z'`
  611          case `eval echo $INSTYPE` in
  612             RPM|R)
  613                INSTYPE=R;;
  614             SLACKWARE|S)
  615                INSTYPE=S;;
  616             DEBIAN|D)
  617                INSTYPE=D;;
  618             *)
  619                echo
  620                echo "$1 is not a valid packaging system. Please use \'rpm\', \'slackware\' or \'debian\'"
  621                echo 
  622                echo
  623                exit 1
  624           esac
  625           ;;
  626        -R)
  627           INSTYPE=R
  628           CK_REDHAT=1
  629           ;;
  630        -S)
  631           INSTYPE=S
  632           CK_SLACKWARE=1
  633           ;;
  634        -D)
  635           INSTYPE=D
  636           CK_DEBIAN=1
  637           ;;
  638        --install)
  639           shift
  640           case `eval echo $1` in
  641              1|yes|'')
  642                 INSTALL=1;;
  643              0|no)
  644                 INSTALL=0;;
  645              *)
  646                 boolean_usage "--install" $1
  647           esac
  648           ;;
  649        --si)
  650           SHOW_INSTALL=1;;
  651        --showinstall)
  652           shift
  653           case `eval echo $1` in
  654              1|yes|'')
  655                 SHOW_INSTALL=1;;
  656              0|no)
  657                 SHOW_INSTALL=0;;
  658              *)
  659                 boolean_usage "--showinstall" $1
  660           esac
  661           ;;
  662        --ss)
  663           SHOW_SLACK_INSTALL=1;;
  664        --showslack)
  665           shift
  666           case `eval echo $1` in
  667              1|yes|'')
  668                 SHOW_SLACK_INSTALL=1;;
  669              0|no)
  670                 SHOW_SLACK_INSTALL=0;;
  671              *)
  672                 boolean_usage "--showslack" $1
  673           esac
  674           ;;
  675        --deldoc)
  676           shift
  677           case `eval echo $1` in
  678              1|yes|'')
  679                 DEL_DOCPAK=1;;
  680              0|no)
  681                 DEL_DOCPAK=0;;
  682              *)
  683                 boolean_usage "--deldoc" $1
  684           esac
  685           ;;
  686        --delspec)
  687           shift
  688           case `eval echo $1` in
  689              1|yes|'')
  690                 DEL_SPEC=1;;
  691              0|no)
  692                 DEL_SPEC=0;;
  693              *)
  694                 boolean_usage "--delspec" $1
  695           esac
  696           ;;
  697        --deldesc)
  698           shift
  699           case `eval echo $1` in
  700              1|yes|'')
  701                 DEL_DESC=1;;
  702              0|no)
  703                 DEL_DESC=0;;
  704              *)
  705                 boolean_usage "--deldesc" $1
  706           esac
  707           ;;
  708        --strip)
  709           shift
  710           case `eval echo $1` in
  711              1|yes|'')
  712                 STRIP_ELF=1;;
  713              0|no)
  714                 STRIP_ELF=0;;
  715              *)
  716                 boolean_usage "--strip" $1
  717           esac
  718           ;;
  719 
  720        --addso)
  721           shift
  722           case `eval echo $1` in
  723              1|yes|'')
  724                 ADD_SO=1;;
  725              0|no)
  726                 ADD_SO=0;;
  727              *)
  728                 boolean_usage "--strip" $1
  729           esac
  730           ;;
  731  
  732 
  733        --stripso)
  734           shift
  735           case `eval echo $1` in
  736              1|yes|'')
  737                 STRIP_SO_ELF=1
  738                 ;;
  739              0|no)
  740                 STRIP_SO_ELF=0;;
  741              *)
  742                 boolean_usage "--stripso" $1
  743              esac
  744           ;;
  745        --gzman)
  746           shift
  747           case `eval echo $1` in
  748              1|yes|'')
  749                 COMPRESS_MAN=1;;
  750              0|no)
  751                 COMPRESS_MAN=0;;
  752              *)
  753                 boolean_usage "--gzman" $1
  754           esac
  755           ;;
  756        --bk)
  757           BACKUP=1;;
  758        --backup)
  759           shift
  760           case `eval echo $1` in
  761              1|yes|'')
  762                 BACKUP=1;;
  763              0|no)
  764                 BACKUP=0;;
  765              *)
  766                 boolean_usage "--backup" $1
  767           esac
  768           ;;
  769        --default)
  770           ACCEPT_DEFAULT=1;;
  771        -y)
  772           ACCEPT_DEFAULT=1;;
  773        --nodoc)
  774           NODOC=1;;
  775        --rpmi)
  776           RPM_IU=i;;
  777        --rpmu)
  778           RPM_IU=U;;
  779        --newslack)
  780           NEW_SLACK=1;;
  781        --inspect)
  782           CK_INSPECT=1;;
  783        --review-spec)
  784           REVIEW_SPEC=1;;
  785        --review-control)
  786           REVIEW_CONTROL=1;;
  787        --spec)
  788       shift
  789       SPEC_PATH=`eval echo $1`
  790           if ! [ -f "$SPEC_PATH" ]; then
  791              echog "Warning: .spec file path \"%s\" not found.\nWarning: Defaulting to \"%s\"." "$SPEC_PATH" "${PKG_BASENAME}.spec"
  792           fi
  793           ;;
  794        --copyright|--version)
  795           cat << EOF
  796 
  797 Copyright (c) 2009 Felipe Eduardo Sanchez Diaz Duran <izto@asic-linux.com.mx>
  798 
  799     This program is free software; you can redistribute it and/or modify
  800     it under the terms of the version 2 of the GNU General Public License
  801     as published by the Free Software Foundation.
  802 
  803     This program is distributed in the hope that it will be useful,
  804     but WITHOUT ANY WARRANTY; without even the implied warranty of
  805     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  806     GNU General Public License for more details.
  807 
  808     You should have received a copy of the GNU General Public License
  809     along with this program; if not, write to the Free Software
  810     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  811 
  812 EOF
  813          exit 0;;
  814        --autodoinst)
  815           shift
  816           case `eval echo $1` in
  817              1|yes|'')
  818                 AUTODOINST=1;;
  819              0|no)
  820                 AUTODOINST=0;;
  821              *)
  822                 boolean_usage "--autodoinst" $1
  823           esac
  824           ;;
  825        --reset-uids)
  826           shift
  827           case `eval echo $1` in
  828              1|yes|'')
  829                 RESET_UIDS=1;;
  830              0|no)
  831                 RESET_UIDS=0;;
  832              *)
  833                 boolean_usage "--reset-uids" $1
  834           esac
  835           ;;
  836         --fstrans)
  837           shift
  838           case `eval echo $1` in
  839              1|yes|'')
  840                 TRANSLATE=1;;
  841              0|no)
  842                 TRANSLATE=0;;
  843              *)
  844                 boolean_usage "--fstrans" $1
  845           esac
  846           ;;
  847       --exclude)
  848          shift
  849          EXCLUDE=`eval echo $1`
  850          ;;
  851       --include)
  852          shift
  853          CK_INCLUDE_FILE=`eval echo $1`
  854          ;;
  855    esac
  856    shift
  857 done
  858 
  859 # See if we have and install command
  860 shift
  861 
  862 [ "$1" = "" ] && set -- make install
  863 
  864 # End of argument parsing
  865 
  866 #############################################################################
  867                    # We initialize some useful variables #
  868                    #######################################
  869 
  870 ################################################################
  871 # User-configurable variables were moved to the checkinstallrc #
  872 # file which is probably found at /usr/local/lib/checkinstall  #          
  873 #                                                              #
  874 #                  DO NOT modify them here!!                   #
  875 ################################################################
  876 
  877 
  878 # Debug level
  879 ! [ "$DEBUG" ] && DEBUG=0
  880 
  881 ! [ "$INSTALLWATCH_PREFIX" ] && INSTALLWATCH_PREFIX="$INSTALLDIR"
  882 ! [ "$INSTALLWATCH" ] && INSTALLWATCH=${INSTALLWATCH_PREFIX}/bin/installwatch
  883 
  884 # Which makepkg to use
  885 ! [ "$MAKEPKG" ] && MAKEPKG=/sbin/makepkg
  886 
  887 # Default MAKEPKG flags
  888 ! [ "$MAKEPKG_FLAGS" ] && MAKEPKG_FLAGS="-l y -c n"
  889 
  890 # Default architecture type
  891 ! [ "$ARCHITECTURE" ] && ARCHITECTURE=""
  892 
  893 # Default package type
  894 ! [ "$INSTYPE" ] && INSTYPE=""
  895 
  896 # Interactively show the results of the install command
  897 # This is useful for interactive installation commands
  898 ! [ "$SHOW_INSTALL" ] && SHOW_INSTALL=1
  899 
  900 # Show Slackware package installation script while it runs? Again, useful if
  901 # it's an interactive script
  902 ! [ "$SHOW_SLACK_INSTALL" ] && SHOW_SLACK_INSTALL=0
  903 
  904 # Automatic deletion of "doc-pak" upon termination
  905 ! [ "$DEL_DOCPAK" ] && DEL_DOCPAK=1
  906 
  907 # Automatic deletion of the spec file
  908 ! [ "$DEL_SPEC" ] && DEL_SPEC=1
  909 
  910 # Automatic deletion of "description-pak" 
  911 ! [ "$DEL_DESC" ] && DEL_DESC=1
  912 
  913 
  914 # Automatically strip all ELF binaries
  915 ! [ "$STRIP_ELF" ] && STRIP_ELF=1
  916 
  917 # Don't automatically strip all ELF binaries
  918 ! [ "$STRIP_SO_ELF" ] && STRIP_SO_ELF=0
  919 
  920 # Don't automatically search shared libraries
  921 # nor add them to /etc/ld.so.conf
  922 ! [ "$ADD_SO" ] && ADD_SO=0
  923 
  924 # Automatically compress all man pages
  925 ! [ "$COMPRESS_MAN" ] && COMPRESS_MAN=1
  926 
  927 # Backup all files modified by the install command supplied by the user
  928 ! [ "$BACKUP" ] && BACKUP=1 
  929 
  930 # Write description installing code to doinst.sh
  931 ! [ "$AUTODOINST" ] && AUTODOINST=1 
  932 
  933 # Are we going to use filesystem translation?
  934 ! [ "$TRANSLATE" ] && TRANSLATE=1
  935 
  936 # Reset the owner/group of all files to root.root?
  937 ! [ "$RESET_UIDS" ] && RESET_UIDS=0
  938 
  939 # We won't include anything under this directories
  940 ! [ "$EXCLUDE" ] && EXCLUDE=""
  941 
  942 # We will include anything listed in this file
  943 ! [ "$CK_INCLUDE_FILE" ] && CK_INCLUDE_FILE=""
  944 
  945 # Accept the default answer for all the questions
  946 ! [ "$ACCEPT_DEFAULT" ] && ACCEPT_DEFAULT=0
  947 
  948 # Use the default doc directory of /usr/doc
  949 ! [ "$DOC_DIR" ] && DOC_DIR=/usr/doc
  950 
  951 # Do not include common documentation
  952 ! [ "$NODOC" ] && NODOC=0
  953 
  954 # Use "-U" flag in rpm by default when installing a rpm package
  955 # This tells rpm to (U)pdate the package instead of (i)nstalling it.
  956 ! [ "$RPM_IU" ] && RPM_IU=U
  957 
  958 # Use the new (8.1+) Slackware description format
  959 ! [ "$NEW_SLACK" ] && NEW_SLACK=1
  960 
  961 # Inspect the file list before creating the package
  962 ! [ "$CK_INSPECT" ] && CK_INSPECT=0
  963 
  964 # Review the .spec file before creating a .rpm
  965 ! [ "$REVIEW_SPEC" ] && REVIEW_SPEC=0
  966 
  967 # Review the control file before creating a .deb
  968 ! [ "$REVIEW_CONTROL" ] && REVIEW_CONTROL=0
  969 
  970 # Set the umask
  971 ! [ "$CKUMASK" ] && CKUMASK=0022
  972 
  973 # No real installation if not explicitly asked
  974 ! [ "$INSTALL" ] && INSTALL=0
  975 
  976 # The place where we will be storing the temp files
  977 ! [ "$BASE_TMP_DIR" ] && BASE_TMP_DIR=/var/tmp
  978 
  979 # Default RPM FLAGS
  980 ! [ "$RPM_FLAGS" ] && RPM_FLAGS=" --force --nodeps --replacepkgs "
  981 
  982 # Default DPKG FLAGS
  983 ! [ "$DPKG_FLAGS" ] && DPKG_FLAGS=""
  984 
  985 # Default MAKEPKG FLAGS
  986 ! [ "$MAKEPKG_FLAGS" ] && MAKEPKG_FLAGS=""
  987 
  988 # Show the makepkg program's output?
  989 ! [ "$SHOW_MAKEPKG" ] && SHOW_MAKEPKG=0
  990 
  991 ####################
  992 # Non-configurable #
  993 ####################
  994 
  995 # Existing configuration files are always preserved
  996 [ -f description-pak ] && DEL_DESC=0
  997 [ -f SPEC_PATH ] && DEL_SPEC=0
  998 [ -d doc-pak ] && DEL_DOCPAK=0
  999 
 1000 
 1001 
 1002 INSTALLCMD=("$@")
 1003 [ -z "${INSTALLCMD[*]}" ] && INSTALLCMD=(make install)
 1004 
 1005 # The editor we use to review the file list and .spec or control file
 1006 if ! [ -x "$VISUAL" ]; then
 1007    if [ -x "$EDITOR" ]; then
 1008       VISUAL=$EDITOR
 1009    else
 1010       VISUAL=`which vi`
 1011    fi
 1012 fi
 1013 
 1014 # pkgtools in Slackware 8.1+ don't like the default tar binary and instead
 1015 # use "tar-1.13". We'll use that too if we can find it.
 1016 
 1017 BADTAR=0
 1018 
 1019 if [ "$TAR" ]; then
 1020    ! [ -x "$TAR" ] && BADTAR=1 
 1021 else
 1022    TAR=`which tar-1.13 2> /dev/null`
 1023 fi
 1024 
 1025 if ! [ -x "$TAR" ]; then
 1026    TAR="tar"
 1027 fi
 1028 
 1029 # If the user gave us a bad path to tar then we should warn him/her about it
 1030 if [ $BADTAR -gt 0 ]; then
 1031    echo
 1032    echog "Warning: The path to tar specified in the command line is invalid.\nWarning: It has been set to %s" "$TAR"
 1033    echo
 1034 fi
 1035 
 1036 [ $DEBUG -gt 0 ] && echo "debug: TAR=$TAR"
 1037 [ $DEBUG -gt 0 ] && echo "debug: VISUAL=$VISUAL"
 1038 
 1039                       #################################
 1040                       # Variable definition ends here #
 1041 #############################################################################
 1042 
 1043 
 1044 
 1045 if [ ! -x $INSTALLWATCH ]; then
 1046    echo
 1047    echog "I can't find $INSTALLWATCH."
 1048    echo
 1049    echog "I can't continue. Either install installwatch or\nmodify the INSTALLWATCH variable in this script,\nthen run checkinstall again."
 1050    echo
 1051    exit 1
 1052 fi
 1053 
 1054 echo
 1055 
 1056 # Set the umask. If not specified with "--umask" then we'll use 0022, a 
 1057 # standard, non-paranoid reasonable value.
 1058 
 1059 if [ $DEBUG -gt 0 ] ;then 
 1060    echo "debug: Setting umask => $CKUMASK"
 1061 fi
 1062 umask $CKUMASK
 1063 
 1064 
 1065 # Find a safe TMP_DIR
 1066 
 1067 TMP_DIR=`mktemp -q -d -p "${BASE_TMP_DIR}"`
 1068 RETURN=$?
 1069 
 1070 if [ "$TMP_DIR" = "$BASE_TMP_DIR" -o "$TMP_DIR" = "/" ]; then
 1071   echo 
 1072   echog "%s is an unacceptable value for the temp dir. Please \nedit the variable definition for %s and try again." "$TMP_DIR" "$TMP_DIR"
 1073   echo
 1074   echog "*** Aborting"
 1075   echo
 1076   exit 1
 1077 fi
 1078 
 1079 if [ $RETURN -gt 0 ]; then
 1080    echo
 1081    echog "**** Failed to create temp dir! \n**** Do you have write permission for %s? \n\n**** Aborting installation." "$BASE_TMP_DIR"
 1082    echo
 1083    exit  $RETURN
 1084 fi
 1085 
 1086 BUILD_DIR=${TMP_DIR}/package
 1087 mkdir $BUILD_DIR
 1088 
 1089 if [ $DEBUG -gt 0 ] ;then 
 1090    echo "debug: The temporary directory is: [ $TMP_DIR ]"
 1091    echo
 1092 fi
 1093 
 1094 
 1095 # 001117-BaP: We can create a default set of docs on the fly . . .
 1096 #   The list I've included should cover most packages adequately. If not,
 1097 #   then you should really create the package doc set *manually*
 1098 
 1099 
 1100 # Check if --nodoc was specified
 1101 if [ "$NODOC" = "0" ]; then 
 1102 
 1103 if  ! [ -d "$DIRECTORIO_FUENTE/doc-pak" ]; then
 1104     echogn "The package documentation directory ./doc-pak does not exist. \nShould I create a default set of package docs? "
 1105     if  yorn ; then
 1106         echo
 1107         echogn "Preparing package documentation..."
 1108         mkdir doc-pak
 1109          for f in ABOUT ABOUT-NLS ANNOUNCE AUTHORS *BUGS* CHANGES CONFIGURATION *COPYING* *COPYRIGHT* CREDITS ChangeLog Changelog CHANGELOG CONTRIBUTORS *FAQ* FEATURES FILES HACKING History HISTORY INSTALL* LICENSE LSM MANIFEST NEWS *README* *Readme* SITES *RELEASE* RELNOTES THANKS TIPS TODO VERSION CONFIGURATION* GPL License  Doc doc Docs* docs* Roadmap ROADMAP; do
 1110             if [ -e $f ]; then
 1111                if ! [ -L $f ]; then
 1112                   cp -a $f doc-pak
 1113                else
 1114                   cp -LpR $f doc-pak
 1115                fi
 1116 
 1117             fi
 1118         done
 1119         okfail
 1120         DOCS=`ls doc-pak`
 1121         if ! [ "$DOCS" ]; then
 1122            echo
 1123            echog "*** No known documentation files were found. The new package \n*** won\'t include a documentation directory."
 1124            rm -rf doc-pak                 # If doc-pak is empty then we
 1125         fi                                # don't need it
 1126     fi                                    
 1127     
 1128 fi
 1129 
 1130 fi # End of NODOC
 1131 
 1132 ##############################################################################
 1133 #
 1134 # Find out the packaging method to use
 1135 #
 1136 
 1137 
 1138 while ! [ "$INSTYPE" ]; do
 1139 
 1140    echo
 1141    echog "Please choose the packaging method you want to use."
 1142    echogn "Slackware [S], RPM [R] or Debian [D]? "
 1143    read INSTYPE
 1144 
 1145 echo
 1146 
 1147        case $INSTYPE in
 1148          S|s) 
 1149             INSTYPE=S
 1150             CK_SLACKWARE=1
 1151             ;;
 1152          R|r)
 1153             INSTYPE=R
 1154             CK_REDHAT=1
 1155             ;;
 1156          D|d)
 1157             INSTYPE=D
 1158             CK_DEBIAN=1
 1159             ;;
 1160          *)
 1161            echo
 1162            echog '*** Invalid type.'
 1163            echo
 1164            INSTYPE=""
 1165            ;;
 1166        esac
 1167 done
 1168 
 1169 ## Do we have a package description file? If we don't then 
 1170 ## we should write one
 1171 
 1172 cd "$DIRECTORIO_FUENTE"
 1173 
 1174 # If we already have a slack-desc we use it unless
 1175 # we have a description-pak too
 1176 
 1177 if [ -r slack-desc -a ! -r description-pak ]; then
 1178    cat -s slack-desc | grep -v \#  | grep -v \| | cut -d : -f 2 | sed '/./,/^$/!d' > description-pak
 1179 fi
 1180 
 1181 
 1182 if [ $ACCEPT_DEFAULT -eq 0 ]; then  # If --default is given, we skip this 
 1183  if ! [ -r description-pak ]; then
 1184    DESCRIPTION="Package created with checkinstall $CHECKINSTALL_VERSION"
 1185    echo
 1186    echogn "Please write a description for the package."
 1187 
 1188    # If we selected Slackware, then give the pkgtool warning
 1189 
 1190    if [ "$CK_SLACKWARE" ]; then 
 1191       echog " Remember that pkgtool shows\nonly the first one when listing packages so make that one descriptive."
 1192    fi
 1193    echo
 1194    echog "End your description with an empty line or EOF."
 1195    while [ "$DESCRIPTION" ]; do
 1196       echo -n ">> " 
 1197       read DESCRIPTION
 1198       [ "$DESCRIPTION" ] && echo "$DESCRIPTION" >> description-pak
 1199    done
 1200  fi
 1201 fi
 1202 
 1203 # We still don't have it??
 1204 ! [ -r description-pak ] && echo "Package created with checkinstall $CHECKINSTALL_VERSION" > description-pak
 1205 
 1206 # Warn the user if we're using the new Slackware description format
 1207 # and the description is bigger than 11 lines
 1208 
 1209 if [ $NEW_SLACK -gt 0 ]; then
 1210    if [ `wc -l < description-pak` -gt 11 ]; then
 1211       echo
 1212       echog "Warning: Your package description is bigger than 11 lines.\nWarning: The Slackware 8.1+ pkgtools might not like it."
 1213       echo
 1214    fi
 1215 fi
 1216 
 1217 
 1218 INSTYPE=`echo $INSTYPE | tr a-z A-Z`
 1219 
 1220 case $INSTYPE in
 1221    S|s) 
 1222       CK_SLACKWARE=1
 1223       echo
 1224       echog "********************************************\n**** Slackware package creation selected ***\n********************************************"
 1225    ;;
 1226    R|r)
 1227       CK_REDHAT=1
 1228       echo
 1229       echog "**************************************\n**** RPM package creation selected ***\n**************************************"
 1230    ;;
 1231    D|d)
 1232       CK_DEBIAN=1
 1233       echo
 1234       echog "*****************************************\n**** Debian package creation selected ***\n*****************************************"
 1235 esac
 1236 
 1237 ########## Acquire some info about the package ##########
 1238 
 1239 
 1240 # Figure out what kind of machine are we running on
 1241 
 1242 if ! [ "$ARCHITECTURE" ]; then
 1243    ARCHITECTURE=`uname -m`
 1244    echo $ARCHITECTURE | grep -e "i[3456]86" &> /dev/null
 1245    [ $? -eq 0 ] && ARCHITECTURE=i386  # Arch will be "i386" for any of
 1246                                     # i386, i486, i586 or i686.
 1247                                       # You can change this with "--arch"
 1248 
 1249    # Fix the PowerPC & Amd64 architecture description if we're on Debian
 1250    
 1251    if [ "$CK_DEBIAN" = "1" ] ; then
 1252       ARCHITECTURE=`dpkg-architecture -qDEB_HOST_ARCH`
 1253    fi
 1254 fi
 1255 
 1256 if [ -f "$SPEC_PATH" ]; then 
 1257    SUMMARY=`getparameter "^[Ss]ummary"`
 1258    NAME=`getparameter "^[Nn]ame"`
 1259    VERSION=`getparameter "^[Vv]ersion"`
 1260    RELEASE=`getparameter "^[Rr]elease"`
 1261    LICENSE=`getparameter "^[Cc]opyright"`
 1262    PKG_GROUP=`getparameter "^[Gg]roup"`
 1263    PROVIDES=`getparameter "^[Pp]rovides"`
 1264    REQUIRES=`getparameter "^[Rr]equires"`
 1265 fi
 1266       
 1267    OPTION=junk
 1268    while [ "$OPTION" ]; do
 1269 
 1270       # Some sanity checks
 1271       ! [ "$SUMMARY" ] && SUMMARY=`head -1 description-pak`
 1272       ! [ "$NAME" ] && NAME=`echo "$PKG_BASENAME" | rev | cut -f2- -d"-" | rev`
 1273 
 1274       if [ "$CK_DEBIAN" ]; then       # Make the name policy compliant
 1275       echo $NAME | grep -e "[[:upper:]]" &> /dev/null
 1276 
 1277          if [ $? -eq 0 ]; then
 1278             echo
 1279             echog "*** Warning: The package name \"%s\" contains upper case\n*** Warning: letters. dpkg might not like that so I changed\n*** Warning: them to lower case." "$NAME"
 1280             NAME=`echo $NAME | tr 'A-Z' 'a-z'`
 1281 
 1282 
 1283          fi
 1284       echo $NAME | grep -e '^[^0-9a-z]' &> /dev/null
 1285          if [ $? -eq 0 ]; then
 1286             echo
 1287         echog "*** Warning: The package name \"%s\" does not start with\n*** Warning: an alphanumetic character. dpkg might not like that so I prefixed\n*** Warning: it with a number 0." "$NAME"
 1288             NAME=`echo $NAME | sed -e 's/^/0/'`
 1289          fi
 1290       echo $NAME | grep -e '[^0-9a-z+.-]' &> /dev/null
 1291          if [ $? -eq 0 ]; then
 1292             echo
 1293             echog "*** Warning: The package name \"%s\" contains illegal\n*** Warning: characters. dpkg might not like that so I changed\n*** Warning: them to dashes." "$NAME"
 1294             NAME=`echo $NAME | sed -e 's/[^0-9a-z+.-]/-/g'`
 1295          fi
 1296       fi
 1297 
 1298 
 1299       ! [ "$VERSION" ] && VERSION=`echo "$PKG_BASENAME" | rev | cut -f1 -d"-" | rev`
 1300 
 1301       ## Did we get a usable version?
 1302 
 1303       if [  "$VERSION" = "$PKG_BASENAME" ]; then
 1304 
 1305          # If we did not then try getting it from the config.log file
 1306          if [ -f "$DIRECTORIO_FUENTE/config.log" ]; then
 1307             VERSION=`grep '#define VERSION' config.log| awk -F \" '{print $ 2}'`
 1308 
 1309          else
 1310 
 1311             # We use the current that if everything else fails
 1312             VERSION=`date +%Y%m%d` 
 1313          fi
 1314       fi
 1315 
 1316 
 1317 
 1318       if [ "$CK_DEBIAN" ]; then       # Check for a valid version for dpkg
 1319     NEWVERS=$(echo $VERSION | egrep '^([[:alnum:]]+:)?[[:alnum:]]+([-:.+~][[:alnum:]]+)*(-[.[:alnum:]]+)?$' 2> /dev/null)
 1320     while [ "$NEWVERS" != "$VERSION" ]; do
 1321             echo
 1322         echog "*** Warning: The package version \"%s\" is not a\n*** Warning: debian policy compliant one. Please specify an alternate one" "$VERSION"
 1323         if [ $ACCEPT_DEFAULT -eq 0 ] ; then
 1324         read VERSION
 1325         NEWVERS=$(echo $VERSION | egrep '^([[:alnum:]]+:)?[[:alnum:]]+([-:.+~][[:alnum:]]+)*(-[.[:alnum:]]+)?$' 2> /dev/null)
 1326         else
 1327         VERSION=0
 1328         NEWVERS=0
 1329         fi
 1330     done
 1331       fi
 1332 
 1333 
 1334 
 1335       if [ ! "$PAGER" ]; then         # no default pager defined
 1336          if [ "$CK_DEBIAN" ]; then    # use Debian's pager if on Debian
 1337             PAGER=/usr/bin/sensible-pager
 1338          else
 1339             PAGER=less             # use less otherwise
 1340          fi
 1341       fi
 1342 
 1343 
 1344 
 1345       ! [ "$RELEASE" ] && RELEASE="1"
 1346       ! [ "$LICENSE" ] && LICENSE="GPL"
 1347       ! [ "$PKG_GROUP" ] && [ "$CK_REDHAT" ] && PKG_GROUP="Applications/System"
 1348       ! [ "$PKG_GROUP" ] && [ "$CK_DEBIAN" ] && PKG_GROUP="checkinstall"
 1349       ! [ "$PKG_GROUP" ] && [ "$CK_SLACKWARE" ] && PKG_GROUP="Applications/System"
 1350 
 1351       ! [ "$ARCHITECTURE" ] && ARCHITECTURE="i386"
 1352       ! [ "$SOURCE" ] && SOURCE="$PKG_BASENAME"
 1353       ! [ "$ALTSOURCE" ] && ALTSOURCE=""
 1354       ! [ "$PROVIDES" ] && PROVIDES="$NAME"
 1355       ! [ "$REQUIRES" ] && REQUIRES=""
 1356       # bond: added this so it is easy to change the Maintainer: field
 1357       # just by setting the MAINTAINER environment variable
 1358 
 1359       # Try to find the hostname in the environment
 1360       if [ "$HOSTNAME" ]; then 
 1361          MAINTDOMAIN=$HOSTNAME
 1362       else
 1363          hostname -f &> /dev/null
 1364          if [ $? -gt 0]; then
 1365             MAINTDOMAIN="localhost"
 1366          else
 1367             MAINTDOMAIN=`hostname -f`
 1368          fi
 1369       fi
 1370       ! [ "$MAINTAINER" ] && MAINTAINER=${LOGNAME:-root}@${MAINTDOMAIN}
 1371       
 1372 
 1373       echo
 1374       echog "This package will be built according to these values: "
 1375       echo
 1376       # Debian maintainers use the Maintainer: field and want to be able
 1377       # to change it. If we are not on debian we don't need the field...
 1378       [ "$CK_DEBIAN" ] && echog "0 -  Maintainer: [ %s ]" "$MAINTAINER"
 1379 
 1380       echog "1 -  Summary: [ %s ]" "$SUMMARY"
 1381       echog "2 -  Name:    [ %s ]" "$NAME"
 1382       echog "3 -  Version: [ %s ]" "$VERSION"
 1383       echog "4 -  Release: [ %s ]" "$RELEASE"
 1384       echog "5 -  License: [ %s ]" "$LICENSE"
 1385       echog "6 -  Group:   [ %s ]" "$PKG_GROUP"
 1386       echog "7 -  Architecture: [ %s ]" "$ARCHITECTURE"
 1387       echog "8 -  Source location: [ %s ]" "$SOURCE"
 1388       echog "9 -  Alternate source location: [ %s ]" "$ALTSOURCE"
 1389       [ "$CK_REDHAT" -o "$CK_DEBIAN" ] &&
 1390           echog "10 - Requires: [ %s ]" "$REQUIRES"
 1391       [ "$CK_REDHAT" -o "$CK_DEBIAN" ] &&
 1392           echog "11 - Provides: [ %s ]" "$PROVIDES"
 1393       [ "$CK_DEBIAN" ] && echog "12 - Conflicts: [ %s ]" "$CONFLICTS"
 1394       [ "$CK_DEBIAN" ] && echog "13 - Replaces: [ %s ]" "$REPLACES"
 1395 
 1396       echo
 1397       echogn "Enter a number to change any of them or press ENTER to continue: "
 1398       if [ $ACCEPT_DEFAULT -eq 1 ]; then
 1399          echo
 1400          OPTION=""
 1401       else
 1402          read OPTION
 1403       fi
 1404 
 1405       case $OPTION in
 1406          1)
 1407             echog "Enter new summary: "
 1408             echo -n ">> "
 1409             read SUMMARY
 1410             ;;
 1411          2)
 1412             echog "Enter new name: "
 1413             echo -n ">> "
 1414             read NAME
 1415             ;;
 1416          3)
 1417             echog "Enter new version: "
 1418             echo -n ">> "
 1419             read VERSION
 1420             ;;
 1421          4)
 1422             echog "Enter new release number: "
 1423             echo -n ">> "
 1424             read RELEASE
 1425             ;;
 1426          5)
 1427             echog "Enter the license type: "
 1428             echo -n ">> "
 1429             read LICENSE
 1430             ;;
 1431          6)
 1432             echog "Enter the new software group: "
 1433             echo -n ">> "
 1434             read PKG_GROUP
 1435             ;;
 1436          7)
 1437             echog "Enter the architecture type: "
 1438             echo -n ">> "
 1439             read ARCHITECTURE
 1440             ;;
 1441          8)
 1442             echog "Enter the source location: "
 1443             echo -n ">> "
 1444             read SOURCE
 1445             ;;
 1446          9)
 1447             echog "Enter the alternate source location: "
 1448             echo -n ">> "
 1449             read ALTSOURCE
 1450             ;;
 1451          0) # bond: again, debian-specific
 1452         [ "$CK_DEBIAN" ] && {
 1453             echog "Enter the maintainer's name and e-mail address: "
 1454             echo -n ">> "
 1455             read MAINTAINER
 1456         }
 1457             ;;
 1458         10)
 1459             [ "$CK_REDHAT" -o "$CK_DEBIAN" ] && {
 1460             echog "Enter the additional requirements: "
 1461             echo -n ">> "
 1462             read REQUIRES
 1463             }
 1464             ;;
 1465         11)
 1466             # 01-12-06 UKo: new feature
 1467         [ "$CK_REDHAT" -o "$CK_DEBIAN" ] && {
 1468             echog "Enter the provided features: "
 1469             echo -n ">> "
 1470             read PROVIDES
 1471             }
 1472             ;;
 1473         12)
 1474             [ "$CK_DEBIAN" ] && { echog "Enter the conflicting packages: "
 1475             echo -n ">> "
 1476             read CONFLICTS
 1477             }
 1478             ;;
 1479         13)
 1480             [ "$CK_DEBIAN" ] && { echog "Enter the replaced packages: "
 1481             echo -n ">> "
 1482             read REPLACES
 1483             }
 1484             ;;
 1485       esac
 1486    done
 1487    
 1488    # The PKG_BASENAME is adjusted to reflect any changes
 1489    # in the NAME and VERSION of the package
 1490    # NOTE: on debian we use NAME alone, instead - see below
 1491 
 1492    PKG_BASENAME="$NAME-$VERSION" 
 1493 
 1494 ##############################################################################
 1495 
 1496 
 1497 #
 1498 # We run the program installation from the source directory       
 1499 #
 1500 
 1501 # Write a small script to run the install command. This way the LD_PRELOAD
 1502 # environment variable will be available to it, wich among other things
 1503 # will allow proper detection of new symbolic links and files created by
 1504 # subshells.
 1505 
 1506 [ $DEBUG -gt 0 ] && echo "debug: CK_INCLUDE_FILE = $CK_INCLUDE_FILE"
 1507 
 1508 TMP_SCRIPT=${TMP_DIR}/installscript.sh
 1509 
 1510 cat << EOF > $TMP_SCRIPT
 1511 #!/bin/sh
 1512 
 1513 cd "$DIRECTORIO_FUENTE"
 1514 EOF
 1515 
 1516 shell_escape "${INSTALLCMD[@]}" >> $TMP_SCRIPT
 1517 
 1518 cat << EOF >> $TMP_SCRIPT
 1519 # Report success or failure
 1520 if [ \$? -eq 0 ]; then
 1521    exit 0
 1522 else
 1523    exit 1
 1524 fi
 1525 
 1526 EOF
 1527 
 1528 # No one needs to see what we are doing. It's safer this way.
 1529 chmod 700 $TMP_SCRIPT
 1530 
 1531 
 1532 echo
 1533 echogn "Installing with %s..." "${INSTALLCMD[*]}"
 1534 
 1535 
 1536 #
 1537 #   We exclude as many "dangerous" directories as possible from translation.
 1538 # installwatch excludes itself some directories, but we put them all here,
 1539 # to be explicit.
 1540 #
 1541 IEXCLUDE="${DIRECTORIO_FUENTE},/dev,/proc,/tmp,/var/tmp"
 1542   
 1543 
 1544 # Run the install command, showing the results interactively if we were asked
 1545 # to do so in the configuration section (see the SHOW_INSTALL switch above)
 1546 INSTALL_FAILED=0
 1547 if [ $SHOW_INSTALL -eq 0 ]; then
 1548 
 1549    $INSTALLWATCH --logfile=${TMP_DIR}/newfiles.tmp --exclude="${IEXCLUDE}" \
 1550    --root=${TMP_DIR} --transl=${TRANSLATE} --backup=${BACKUP} --dbglvl=$DEBUG\
 1551    $TMP_SCRIPT &> /${TMP_DIR}/install.log
 1552 
 1553    okfail
 1554    INSTALL_FAILED=$?
 1555 else
 1556    echo
 1557    echo
 1558    echog "========================= Installation results ==========================="
 1559    $INSTALLWATCH --logfile=${TMP_DIR}/newfiles.tmp --exclude="${IEXCLUDE}" \
 1560    --root=${TMP_DIR} --transl=${TRANSLATE} --backup=${BACKUP} --dbglvl=$DEBUG\
 1561    $TMP_SCRIPT 2>&1
 1562    if [ $? -eq 0 ]; then 
 1563       echo
 1564       echog "======================== Installation successful =========================="
 1565    else        
 1566       INSTALL_FAILED=1
 1567    fi
 1568 fi
 1569 
 1570 # preserve LD_PRELOAD, might have been set by fakeroot 
 1571 # unset LD_PRELOAD
 1572 
 1573 
 1574 VIEWLOG="n"
 1575 if [ $INSTALL_FAILED -gt 0 ]; then 
 1576    echo
 1577    echog "****  Installation failed. Aborting package creation."
 1578    VIEWLOG="y"
 1579 fi
 1580 
 1581 if [ $SHOW_INSTALL -eq 0 ]; then
 1582    echo
 1583    echogn "Do you want to view the installation log file? "
 1584 
 1585    if  yorn $VIEWLOG ; then
 1586 
 1587       (echo
 1588        echogn ' ***************************************************************\n         Installation results. You can find them in\n       %s\n ***************************************************************\n' "${TMP_DIR}/install.log"
 1589        cat /${TMP_DIR}/install.log)  | $PAGER
 1590    fi
 1591 fi
 1592 
 1593 if [ $INSTALL_FAILED -gt 0 ]; then 
 1594    cleanup
 1595        exit $INSTALL_FAILED
 1596     fi
 1597 
 1598     # If translation was active, the installed files are under /transl
 1599     TRANSLROOT="/"
 1600     if [ "${TRANSLATE}" = "1" ]; then
 1601         TRANSLROOT="${TMP_DIR}/TRANSL"
 1602     fi
 1603 
 1604 
 1605     # Copy the documentation files           
 1606 
 1607 
 1608     if [ -d "$DIRECTORIO_FUENTE/doc-pak" ]; then    # Are there any files? 
 1609        echo
 1610        echo "Copying documentation directory..."
 1611            case "${DOC_DIR}" in
 1612                :*) doc_dir=`echo "${DOC_DIR}" | sed -e 's/://'`;;
 1613                *) doc_dir="${DOC_DIR}/${NAME}";;
 1614            esac
 1615        mkdir -p "${BUILD_DIR}/${doc_dir}"
 1616        copy_dir_hierarchy . "$DIRECTORIO_FUENTE/doc-pak" \
 1617                "${BUILD_DIR}/${doc_dir}"
 1618        chown -R root.root "${BUILD_DIR}/${doc_dir}"
 1619     fi
 1620     
 1621     # If we have a --include list file, copy the files listed there to /
 1622     # If translation is on, it will catch these too.
 1623     
 1624     if [ -f "${DIRECTORIO_FUENTE}/${CK_INCLUDE_FILE}" ]; then
 1625        cat "${DIRECTORIO_FUENTE}/${CK_INCLUDE_FILE}" | while read include_file; do
 1626            copy_dir_hierarchy --deref-parents "$include_file" "." "${BUILD_DIR}" &>/dev/null
 1627            done
 1628 
 1629     fi
 1630 
 1631 
 1632     #
 1633     # Extract the relevant files from the modified files list
 1634     #
 1635 
 1636     # Find regular files first
 1637     [ $DEBUG -gt 0 ] && echo "debug: BASE_TMP_DIR: $BASE_TMP_DIR"
 1638     cat /${TMP_DIR}/newfiles.tmp | egrep -v '^[-0-9][0-9]*[[:space:]]*(unlink|access)' | cut -f 3 | egrep -v "^(/dev|$BASE_TMP_DIR|/tmp)" | sort -u > /${TMP_DIR}/newfiles
 1639 
 1640     # symlinks are next
 1641     cat /${TMP_DIR}/newfiles.tmp | egrep -v '^[-0-9][0-9]*[[:space:]]*(unlink|access)' | cut -f 4 | egrep -v "^(/dev|$BASE_TMP_DIR|/tmp)" | grep -v "#success" | sort -u  >> /${TMP_DIR}/newfiles
 1642         # Create another list of modified files that exclude all files the
 1643         # install script wanted to create but did not, e.g because they already
 1644         # existed.
 1645         egrep "#success$" /${TMP_DIR}/newfiles.tmp | cut -f 3 | sort -u \
 1646             >/${TMP_DIR}/modified
 1647         egrep "#success$" /${TMP_DIR}/newfiles.tmp | cut -f 4 \
 1648             | egrep -v "#success" | sort -u >> /${TMP_DIR}/modified
 1649 
 1650     # OK, now we clean it up a bit
 1651     mv /${TMP_DIR}/newfiles.tmp /${TMP_DIR}/newfiles.installwatch
 1652     sort -u <  /${TMP_DIR}/newfiles | uniq  | while read file; do
 1653        if [ -e "${TRANSLROOT}${file}" ]; then
 1654           echo $file >> /${TMP_DIR}/newfiles.tmp
 1655        else
 1656           FILE_SYM=`file "${TRANSLROOT}${file}" | grep 'symbolic link'`
 1657           [ "${FILE_SYM}" != "" ] && echo $file >> /${TMP_DIR}/newfiles.tmp
 1658        fi
 1659     done
 1660 
 1661     cp /${TMP_DIR}/newfiles.tmp /${TMP_DIR}/newfiles
 1662 
 1663     # Don't include anything under the directories specified with "--exclude"
 1664 
 1665     [ $DEBUG -gt 0 ] && echo "debug: EXCLUDE=$EXCLUDE"
 1666 
 1667     for exclude in `echo $EXCLUDE | awk '{ split ($0, files,","); for(i=1; files[i] != ""; i++) print files[i];}'`; do
 1668        if [ -d $exclude ]; then  # If it's a directory, ignore everything below it
 1669           egrep -v "^$exclude" < /${TMP_DIR}/newfiles > /${TMP_DIR}/newfiles.tmp
 1670        else
 1671           if [ -f $exclude ]; then  # If it's a file, ignore just this one
 1672          egrep -v "^$exclude$" < /${TMP_DIR}/newfiles > /${TMP_DIR}/newfiles.tmp
 1673           fi
 1674        fi
 1675        cp /${TMP_DIR}/newfiles.tmp /${TMP_DIR}/newfiles
 1676     done
 1677 
 1678     # Find files created under /home
 1679     grep '^/home' ${TMP_DIR}/newfiles > /${TMP_DIR}/unwanted
 1680     if [ $? -eq 0 ]; then
 1681        echo
 1682        echog "Some of the files created by the installation are inside the home directory: /home"
 1683        echo
 1684        echog "You probably don't want them to be included in the package."
 1685        echogn "Do you want me to list them? "
 1686        if yorn "n"; then
 1687            $PAGER ${TMP_DIR}/unwanted
 1688            fi
 1689        echogn "Should I exclude them from the package? (Saying yes is a good idea) "
 1690        if yorn "n"; then
 1691            sed -i -e '/^\/home/d' ${TMP_DIR}/newfiles
 1692            fi
 1693     fi
 1694 
 1695     ## Find any files created in `pwd`. We probably don't want them here
 1696 
 1697     grep "^`pwd`" ${TMP_DIR}/newfiles > /${TMP_DIR}/unwanted 
 1698     if [ $? = 0 ]; then 
 1699        echo
 1700        echog "Some of the files created by the installation are inside the build\ndirectory: %s" "`pwd`"
 1701        echo
 1702        echogn "You probably don't want them to be included in the package,\nespecially if they are inside your home directory.\nDo you want me to list them? "
 1703        if  yorn "n"; then
 1704           $PAGER ${TMP_DIR}/unwanted
 1705        fi
 1706        echogn "Should I exclude them from the package? (Saying yes is a good idea) "
 1707        if  yorn ; then
 1708           grep -v "`pwd`" ${TMP_DIR}/newfiles > /${TMP_DIR}/newfiles.tmp
 1709           mv /${TMP_DIR}/newfiles.tmp /${TMP_DIR}/newfiles
 1710        fi
 1711     fi
 1712 
 1713     # If requested with "--inspect" we run an editor on the newfiles list
 1714     if [ $CK_INSPECT -gt 0 ]; then
 1715        echo
 1716        echog "You requested to review the list of files that will be\nincluded in this package.\n\nNow you'll have the chance to review and optionally modify it."
 1717        echo
 1718        echog "Press ENTER to continue."
 1719        read junk
 1720        $VISUAL ${TMP_DIR}/newfiles
 1721 
 1722        # Check if new files were added by the user
 1723        cat /${TMP_DIR}/newfiles | while read file; do 
 1724           if ! [ -e "${TRANSLROOT}${file}" ]; then
 1725           copy_dir_hierarchy --deref-parents "${file}" "/" "${BUILD_DIR}" >> /${TMP_DIR}/updated-by-user.log 2>&1
 1726           fi
 1727        done
 1728 
 1729     fi
 1730 
 1731 
 1732     # Copy the files to the temporary directory
 1733     #
 1734 
 1735     echo
 1736     echogn "Copying files to the temporary directory..."
 1737 
 1738     cd /
 1739 
 1740     ( cat /${TMP_DIR}/newfiles | while read i; do 
 1741           if [ ! -d "${TRANSLROOT}${i}" -o -L "${TRANSLROOT}${i}" ]; then
 1742           echo ".${i}"
 1743        fi
 1744     done ) > /${TMP_DIR}/newfiles-tar
 1745 
 1746         # Here it gets tricky: we need to copy all new files to our build dir,
 1747         # keeping permissions as they are for parents directories as well as for
 1748         # the files themselves. If the parents or the file are symlinks, we
 1749         # dereference them only if they were not modified by the installation
 1750         # script. 
 1751         NEWFILES="${TMP_DIR}/modified"
 1752         LOGFILE="/${TMP_DIR}/checkinstall.log"
 1753 
 1754     cat /${TMP_DIR}/newfiles-tar | while read file; do
 1755             parents=`list_parents ${file} | sed s/^\.//`
 1756             for p in $parents; do
 1757             # We have to remove the ./ at the beginning
 1758         truep=`echo ${p} | sed s/^\.//`
 1759                 # Parent has been modified: do _not_ dereference
 1760         grep "${truep}$" "${NEWFILES}" &>/dev/null
 1761         if [ $? -eq 0 ]; then
 1762                     $TAR --no-recursion -C "${TRANSLROOT}" -cpf - $p \
 1763             | $TAR -f - -xvpC "${BUILD_DIR}" >> $LOGFILE 2>&1
 1764         else
 1765                     # Parent wasn't touched by the install script: dereference
 1766                     $TAR --no-recursion -C "${TRANSLROOT}" -cphf - $p \
 1767             | $TAR -f - -xvpC "${BUILD_DIR}"  >> $LOGFILE 2>&1
 1768         fi
 1769             done
 1770             truefile=`echo ${file} | sed 's/^\.//'`
 1771             # No recursion here: if $file is a directory, then the files created
 1772             # in it will follow.
 1773             grep "${truefile}$" "${NEWFILES}" &>/dev/null
 1774             if [ $? -eq 0 ]; then
 1775         $TAR --no-recursion -C "${TRANSLROOT}" -cpf - "$file" \
 1776                     | $TAR -f - -xvpC "${BUILD_DIR}" >> $LOGFILE 2>&1
 1777             else 
 1778         $TAR --no-recursion -C "${TRANSLROOT}" -cphf - "$file" \
 1779                     | $TAR -f - -xvpC "${BUILD_DIR}" >> $LOGFILE 2>&1
 1780             fi
 1781     done
 1782 
 1783     okfail
 1784 
 1785     cd /
 1786 
 1787 
 1788     # Reset all files' owner/group to root.root, and all dirs' perms to 755
 1789     #
 1790     # We do this if asked with "--reset-uids" in the command line, like the
 1791     # similar option in Slackware's makepkg.
 1792 
 1793     if [ $RESET_UIDS -gt 0 ]; then
 1794        find "$BUILD_DIR" -exec chown root.root {} \;
 1795        find "$BUILD_DIR" -type d -exec chmod 755 {} \;
 1796     fi
 1797 
 1798     ##############################################################################
 1799                     # Strip ELF binaries # 
 1800                     ######################
 1801 
 1802 
 1803     #
 1804     # Note: The code in this section was taken from the brp-strip script included 
 1805     # in rpm-4.0.2, which is distributed under the GNU GPL. The copyright
 1806     # for this code belongs to its owner. See the file COPYING for details.
 1807     #
 1808 
 1809     if [ $STRIP_ELF -eq 1 ]; then
 1810        echo
 1811        if [ $STRIP_SO_ELF -eq 1 ]; then
 1812            echogn "Stripping ELF binaries and libraries..."
 1813        else
 1814            echogn "Stripping ELF binaries..."
 1815        fi
 1816        for f in `find ${BUILD_DIR} -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \)` ; do
 1817 
 1818            if [ $STRIP_SO_ELF -eq "0" -a "`file $f | grep -v ' shared object,'`" = "" ]; then
 1819            #if this is a *.so* file and we don't have to strip it, then filter 'em
 1820            continue
 1821            fi
 1822            if [ "`file $f | sed -n -e 's/^\(.*\):[  ]*ELF.*, not stripped/\1/p'`" = "" ]; then
 1823            continue
 1824            fi
 1825            strip -p $f || :
 1826        done
 1827        okfail
 1828     fi
 1829                      ###################
 1830                      # End of stripping #
 1831     ##############################################################################
 1832 
 1833 
 1834     ##############################################################################
 1835                     # Compress man pages #
 1836                     ######################
 1837 
 1838 #
 1839 # Note: The code in this section is based on the brp-compress script
 1840 # included in rpm-4.0.2, which is distributed under the GNU GPL. The
 1841 # copyright for this code belongs to its owner. See the file COPYING for
 1842 # details.
 1843 #
 1844 
 1845 if [ $COMPRESS_MAN -eq 1 ]; then
 1846  echo
 1847  echogn "Compressing man pages..."
 1848  cd $BUILD_DIR
 1849  
 1850  # Compress man pages
 1851  COMPRESS="gzip -9"
 1852  COMPRESS_EXT=.gz
 1853  
 1854  for d in ./usr/local/man/man* ./usr/local/man/*/man* ./usr/local/info \
 1855     ./usr/local/share/man/man* ./usr/local/share/man/*/man* \
 1856     ./usr/local/share/info \
 1857     ./usr/local/kerberos/man \
 1858     ./usr/local/share/doc/*/man/man* ./usr/local/lib/*/man/man* \
 1859     ././usr/man/man* ./usr/man/*/man* ./usr/info \
 1860     ./usr/share/man/man* ./usr/share/man/*/man* ./usr/share/info \
 1861     ./usr/kerberos/man ./usr/X11R6/man/man* ./usr/lib/perl5/man/man* \
 1862     ./usr/share/doc/*/man/man* ./usr/lib/*/man/man*
 1863  do
 1864      [ -d $d ] || continue
 1865      for f in `find $d -type f`
 1866      do
 1867         [ -f "$f" ] || continue
 1868     [ "`basename $f`" = "dir" ] && continue
 1869 
 1870          # decompress manpage by "cat"ing it, this allows decompression of
 1871          # hardlinked manpages and allows gunzip of a compressed page which is
 1872          # actually called "man.1" and not "man.1.gz", something it won't do
 1873          # when operating directly on file.
 1874          # this overcomes installs that create (un)compressed pages with names
 1875          # that don't correspond with the compression.
 1876          # this is done to a temporary file so we can detect hardlinks to
 1877          # original file.
 1878        b=`echo $f | sed -e 's/\.Z$//;s/\.gz$//;s/\.bz2$//'`
 1879          cp -p $f $b.tmp # setup up permissions on our new file
 1880          cat $f | gunzip -c 2>/dev/null >$b.tmp || {
 1881            cat $f | bunzip2 -c 2>/dev/null >$b.tmp || {
 1882              cat $f >$b.tmp
 1883            }
 1884          }
 1885  
 1886        $COMPRESS $b.tmp
 1887          # find any hard links to the old manpage and link to the new one..
 1888          inode=`ls -i $f | awk '{ print $1 }'`
 1889          others=`find $d -type f -inum $inode`
 1890        if [ -n "$others" ]; then
 1891          for afile in $others ; do
 1892            [ "$afile" = "$f" ] && continue
 1893              rm -f ${TRANSLROOT}/${afile} ${afile}
 1894              afile=`echo $afile | sed -e 's/\.Z$//;s/\.gz$//;s/\.bz2$//'`
 1895            ln $b.tmp$COMPRESS_EXT $afile$COMPRESS_EXT
 1896          done
 1897          fi
 1898          rm -f ${TRANSLROOT}/${f} ${f}
 1899          mv $b.tmp$COMPRESS_EXT $b$COMPRESS_EXT
 1900     done
 1901  
 1902      for f in `find $d -type l`
 1903      do
 1904     l=`ls -l $f | awk '{ print $11 }' | sed -e 's/\.gz$//' -e 's/\.bz2$//' -e 's/\.Z$//'`
 1905     rm -f ${TRANSLROOT}/${f}
 1906     b=`echo $f | sed -e 's/\.gz$//' -e 's/\.bz2$//' -e 's/\.Z$//'`
 1907     ln -sf $l$COMPRESS_EXT $b$COMPRESS_EXT
 1908      done
 1909  done
 1910  okfail
 1911 fi
 1912 
 1913                        ################################
 1914                        # End of man pages compressing #
 1915 ##############################################################################
 1916 
 1917 
 1918 # Now we get the TRUE list of files from the directory listing (kind of)
 1919 # of the BUILD_DIR. This is the true one simply because THESE are the files
 1920 # that will actually get packaged.
 1921 
 1922 
 1923 echo
 1924 echogn "Building file list..."
 1925 rm ${TMP_DIR}/newfiles
 1926 cd $BUILD_DIR
 1927 $TAR -cpf -  . | $TAR -f - -t 2>&1 | sed -e 's#^\./#/#' | egrep -v "^/$" > ${TMP_DIR}/newfiles
 1928 okfail
 1929 
 1930 
 1931 # Do we have a postinstall script?
 1932 PINST_EXISTS=0
 1933 [ -f ${DIRECTORIO_FUENTE}/postinstall-pak ] && PINST_EXISTS=1
 1934 
 1935 ##############################################################################
 1936                          # Identify shared libraries # 
 1937                          #############################
 1938 
 1939 if [ $ADD_SO -eq 1 ]; then
 1940 
 1941 # Here we identify the shared libraries locations so we can add them
 1942 # to /etc/ld.so.conf file if they're not already there. This will be done
 1943 # in the postinstall script.
 1944 
 1945 cat ${TMP_DIR}/newfiles | while read libfile; do
 1946   FILETYPE=`file $libfile` 
 1947   if echo /$FILETYPE | grep -e ".*ELF.*hared.*bject" &> /dev/null; then
 1948      echo `dirname $libfile` >> ${TMP_DIR}/libdirs
 1949   fi
 1950 done
 1951 
 1952 # Did we find any libdirs?
 1953 if [ -f ${TMP_DIR}/libdirs ]; then
 1954 
 1955  echo
 1956  echog "Shared libraries found. Adding them to the postinstall script."
 1957  # If we have a pre-existing postinstall-pak we save it
 1958 
 1959  if [ $PINST_EXISTS -gt 0 ]; then
 1960     mv ${DIRECTORIO_FUENTE}/postinstall-pak ${DIRECTORIO_FUENTE}/postinstall-pak.tmp 
 1961     PINST_EXISTS=1
 1962  fi
 1963  
 1964  if ! [ $PINST_EXISTS -gt 0 ]; then
 1965     cat << EOF > ${DIRECTORIO_FUENTE}/postinstall-pak
 1966 #!/bin/sh
 1967 #
 1968 # postinstall script, created by checkinstall-${CHECKINSTALL_VERSION}
 1969 #
 1970 EOF
 1971  fi
 1972 
 1973  echo "echo" >>  ${DIRECTORIO_FUENTE}/postinstall-pak
 1974 
 1975  cat ${TMP_DIR}/libdirs | while read libdir; do
 1976    (
 1977     echo "if ! egrep \"^/${libdir} *$\" /etc/ld.so.conf &> /dev/null; then"
 1978     echo "   echo \"Adding \"/$libdir\" to /etc/ld.so.conf\"" 
 1979     echo "   echo /$libdir >> /etc/ld.so.conf"
 1980     echo fi
 1981    ) >> ${DIRECTORIO_FUENTE}/postinstall-pak
 1982  done
 1983 
 1984  echo ldconfig >> ${DIRECTORIO_FUENTE}/postinstall-pak
 1985 
 1986  # If we had an existing postinstall-pak, append it to the new one
 1987  
 1988  if [ -f ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ]; then
 1989     cat ${DIRECTORIO_FUENTE}/postinstall-pak.tmp >> ${DIRECTORIO_FUENTE}/postinstall-pak
 1990  fi
 1991 
 1992 fi  # End of did we find any libdirs?
 1993 
 1994 fi
 1995 
 1996                        ####################################
 1997                        # End of Identify shared libraries # 
 1998 ##############################################################################
 1999 
 2000 ##############################################################################
 2001                           # Identify kernel modules #
 2002               ###########################
 2003 
 2004 # Find out if we installed a kernel module, and if so run depmod in the postinst
 2005 # and delete the files depmod touches (they conflict with other packages)
 2006 # These files are modules.* inside the kernel modules directory.
 2007 
 2008 DEPFILES=$(cat ${TMP_DIR}/newfiles | grep -E 'modules\.(dep|pcimap|usbmap|ccwmap|ieee1394map|isapnpmap|inputmap|ofmap|seriomap|alias|symbols)' )
 2009 if [ ! -z "$DEPFILES" ] ; then
 2010     echo
 2011     echog "Kernel modules found. Calling depmod in the postinstall script"
 2012     # Delete references to the depmod generated files
 2013     sed -r -i -e '\,modules\.(dep|pcimap|usbmap|ccwmap|ieee1394map|isapnpmap|inputmap|ofmap|seriomap|alias|symbols),d' ${TMP_DIR}/newfiles
 2014     # And the files themselves
 2015     for file in $DEPFILES ; do
 2016         rm ${BUILD_DIR}/$file
 2017     done
 2018     # Find out the kernel version.
 2019     # Ugly hack, but works in Debian and should on many other systems.
 2020     # The file must be /any/dir/<version>/modules.*
 2021     KVER=$(echo $DEPFILES | awk '{print $1}' | sed -e 's|/modules\..*||' | xargs basename )
 2022     # Add depmod to the postinst
 2023     # This will be redundant if we already have a postinstall script.
 2024     # Nevertheless, it is harmless.
 2025     echo "#!/bin/sh" >> ${DIRECTORIO_FUENTE}/postinstall-pak
 2026     echo "#" >> ${DIRECTORIO_FUENTE}/postinstall-pak
 2027     echo "# postinstall script, created by checkinstall-${CHECKINSTALL_VERSION}" >> ${DIRECTORIO_FUENTE}/postinstall-pak
 2028     echo "#" >> ${DIRECTORIO_FUENTE}/postinstall-pak
 2029     echo "depmod $KVER" >> ${DIRECTORIO_FUENTE}/postinstall-pak
 2030 fi
 2031 
 2032                         ##################################
 2033                 # End of Identify kernel modules #
 2034 ##############################################################################
 2035 
 2036 cd $DIRECTORIO_FUENTE
 2037 
 2038 FAILED=0
 2039 
 2040 case $INSTYPE in
 2041 
 2042 ##############################################################################
 2043                     # Create Slackware compatible tarball #
 2044                     #######################################
 2045 
 2046 
 2047 s|S)  
 2048 
 2049 
 2050 # The new Slackware naming scheme
 2051 SLACK_PKG_BASENAME="${PKG_BASENAME}-${ARCHITECTURE}-${RELEASE}"
 2052 
 2053 FAILED=0
 2054 
 2055 # If we're not installing the package then there is no problem if 
 2056 # installpkg is not in our execution path
 2057 
 2058 if [ $INSTALL -gt 0 ]; then
 2059    # Verify that we have the "installpkg" command in our path 
 2060 
 2061    INSTALLPKG_PATH=`which installpkg 2> /dev/null`
 2062 
 2063    if ! [ -x "$INSTALLPKG_PATH" ]; then
 2064       echo
 2065       echog "*** The \"installpkg\" program is not in your PATH!"
 2066       echo
 2067       echog "*** Slackware package creation aborted"
 2068       FAILED=1
 2069    fi
 2070 fi
 2071 
 2072 if ! [ $FAILED -gt 0 ]; then
 2073 
 2074 # Create the Slackware installation script
 2075 
 2076 echo
 2077 echogn "Preparing Slackware install directory..."
 2078 mkdir -p ${BUILD_DIR}/install
 2079 touch ${BUILD_DIR}/install/doinst.sh
 2080 okfail
 2081 
 2082 echo
 2083 echogn "Writing package description..."
 2084 
 2085 # If we're building for Slackware 8.1+, then we use the new description
 2086 # file format
 2087 
 2088 if [ $NEW_SLACK -gt 0 ]; then
 2089 
 2090 cat << EOF > ${BUILD_DIR}/install/slack-desc
 2091 # HOW TO EDIT THIS FILE:
 2092 # The "handy ruler" below makes it easier to edit a package description.  Line
 2093 # up the first '|' above the ':' following the base package name, and the '|' on
 2094 # the right side marks the last column you can put a character in. You must make
 2095 # exactly 11 lines for the formatting to be correct.  It's also customary to
 2096 # leave one space after the ':'.
 2097 
 2098 EOF
 2099 
 2100 # Calculate the spaces before the "handy-ruler"
 2101 HR_SPACES=`echo $NAME | wc -c| awk '{ for (i=1;substr ($0,i,1) ~ /[[:blank:]]/ ;i++); print substr ($0,i);}'`
 2102 
 2103 
 2104 awk -v S=$HR_SPACES 'BEGIN {ORS=""; for (i=1; i < S; i++) print " ";}' >> ${BUILD_DIR}/install/slack-desc
 2105 
 2106 echo "|-----handy-ruler------------------------------------------------------|" >> ${BUILD_DIR}/install/slack-desc
 2107 
 2108 
 2109 # Add the prefixed description
 2110  cat description-pak | while read line; do
 2111     echo "$NAME: $line" >> ${BUILD_DIR}/install/slack-desc
 2112  done
 2113 
 2114 okfail
 2115 
 2116 # End of NEW_SLACK block
 2117 
 2118 else 
 2119 
 2120 #
 2121 # Generate the description-installing doinst.sh
 2122 #
 2123 
 2124 if [ $AUTODOINST -eq 1 ]; then
 2125    echo "PACKAGE DESCRIPTION:" > ${BUILD_DIR}/install/description
 2126    cat description-pak | while read line; do
 2127       echo $line >> ${BUILD_DIR}/install/description
 2128    done
 2129    okfail 
 2130 
 2131    echo
 2132    echogn "Writing Slackware install script..."
 2133    cat << EOF >> ${BUILD_DIR}/install/doinst.sh
 2134 # 
 2135 # doinst.sh, auto-generated by checkinstall-${CHECKINSTALL_VERSION}
 2136 #
 2137 
 2138 echo 
 2139 cat /install/description
 2140 
 2141 sed '/PACKAGE LOCATION/r /install/description' < "/var/log/packages/$SLACK_PKG_BASENAME" > description.tmp
 2142 mv description.tmp "/var/log/packages/${SLACK_PKG_BASENAME}"
 2143 rm /install/description
 2144 
 2145 EOF
 2146    okfail
 2147 fi
 2148 
 2149 fi # End of description creation
 2150 
 2151 # If we have a Slackware install script already, add it to this one
 2152 # and force an interactive slackware install script
 2153 for file in postinstall-pak install-pak; do
 2154    if [ -f $file ]; then
 2155       INSTALL_PAK=${file}
 2156    fi
 2157 done
 2158 if [ -f "$INSTALL_PAK" ]; then 
 2159    echo
 2160    # We want to say this only if we actually had a preexisting postinstall-pak
 2161    if [ $PINST_EXISTS -gt 0 ]; then
 2162       echogn "Appending your script to the main install script..."
 2163       cat $INSTALL_PAK >> ${BUILD_DIR}/install/doinst.sh
 2164       okfail
 2165       echo
 2166    else
 2167       cat $INSTALL_PAK >> ${BUILD_DIR}/install/doinst.sh
 2168    fi
 2169    SHOW_SLACK_INSTALL=1
 2170 fi
 2171 
 2172 
 2173 echo
 2174 echogn "Creating package ${SLACK_PKG_BASENAME}..."
 2175 
 2176 cd $BUILD_DIR
 2177 chmod 755 $BUILD_DIR
 2178 
 2179 # Make the "TAR" variable available to MAKEPKG
 2180 export TAR
 2181 
 2182 if [ $SHOW_MAKEPKG -gt 0 ]; then
 2183    $MAKEPKG $MAKEPKG_FLAGS "${SLACK_PKG_BASENAME}.tgz"
 2184    okfail
 2185 else
 2186    $MAKEPKG $MAKEPKG_FLAGS "${SLACK_PKG_BASENAME}.tgz" &> /dev/null
 2187    okfail
 2188 fi
 2189 
 2190 mv "${SLACK_PKG_BASENAME}.tgz" "$DIRECTORIO_FUENTE"
 2191 
 2192 #
 2193 # If requested, we install the package to register it in Slackware's
 2194 # installed packages list so we can list it's contents with pkgtool 
 2195 # or remove it with removepkg
 2196 #
 2197 
 2198 if [ "$INSTALL" = "1" ]; then
 2199 
 2200    # Go back to where we started
 2201    cd "$DIRECTORIO_FUENTE"
 2202    
 2203    echo
 2204    
 2205    if [ $SHOW_SLACK_INSTALL -eq 0 ]; then
 2206       echogn "Installing package..."
 2207       installpkg "${SLACK_PKG_BASENAME}.tgz" &> ${TMP_DIR}/slackinstall.log
 2208       okfail
 2209       [ $? -gt 0 ] && FAILED=1
 2210    
 2211    else
 2212    echog "========================= Installation results ==========================="
 2213       echo
 2214       installpkg "${SLACK_PKG_BASENAME}.tgz" 
 2215       if [ $? -gt 0 ]; then
 2216          FAILED=1
 2217       else
 2218          echo
 2219       echog "======================== Installation successful =========================="
 2220       fi
 2221    fi
 2222    
 2223    if [ $FAILED -eq 1 ]; then
 2224       echo
 2225       echog "*** Failed to install the package"
 2226       echo
 2227       if [ $SHOW_SLACK_INSTALL -eq 0 ]; then
 2228          echogn "Do you want to see the log file? "
 2229          if yorn ; then
 2230             $PAGER ${TMP_DIR}/slackinstall.log
 2231             cleanup
 2232             exit 1
 2233          fi
 2234       fi
 2235    fi
 2236 
 2237 else
 2238         echo
 2239         echog "NOTE: The package will not be installed."
 2240 fi
 2241  
 2242 
 2243 PKG_LOCATION="${DIRECTORIO_FUENTE}/${SLACK_PKG_BASENAME}.tgz"
 2244 INSTALLSTRING="installpkg ${SLACK_PKG_BASENAME}.tgz"
 2245 REMOVESTRING="removepkg ${SLACK_PKG_BASENAME}"
 2246 
 2247 fi
 2248 ;;
 2249 
 2250 
 2251                        #################################
 2252                        # End Slackware package section #
 2253 ##############################################################################
 2254 
 2255 
 2256 ##############################################################################
 2257                           # RPM package installation #
 2258                           ############################
 2259 
 2260 
 2261 r|R)
 2262 
 2263 
 2264 FAILED=0
 2265 
 2266 # Verify that we have the rpm command in our path
 2267 
 2268 RPM_PATH=`which rpm 2> /dev/null`
 2269 
 2270 if ! [ -x "$RPM_PATH" ]; then
 2271    echo
 2272    echog "*** The \"rpm\" program is not in your PATH!"
 2273    echo
 2274    echog "*** RPM package creation aborted"
 2275    FAILED=1
 2276 fi
 2277    
 2278 if ! [ $FAILED -gt 0 ]; then
 2279 
 2280 # Identify the rpm version
 2281 
 2282 RPM_VERSION=`rpm --version | awk '{ print $3 }'`
 2283 RPM_MAJOR_VERSION=`echo $RPM_VERSION | cut -f1 -d"."`
 2284 RPM_MINOR_VERSION=`echo $RPM_VERSION | cut -f2 -d"."`
 2285 RPM_PATCH_LEVEL=`echo $RPM_VERSION | cut -f3 -d"."`
 2286 
 2287 if [ "$RPM_PATCH_LEVEL" = "" ]; then 
 2288    RPM_PATCH_LEVEL=0
 2289 fi
 2290 
 2291 
 2292 if [ $DEBUG -gt 0 ]; then
 2293    echo "debug: RPM_VERSION=${RPM_VERSION}"
 2294    echo "debug: RPM_MAJOR_VERSION=$RPM_MAJOR_VERSION"
 2295    echo "debug: RPM_MINOR_VERSION=$RPM_MINOR_VERSION"
 2296    echo "debug: RPM_PATCH_LEVEL=$RPM_PATCH_LEVEL"
 2297    echo "debug: RPM_IU=$RPM_IU"
 2298 fi
 2299 
 2300 # AFAIK, the only rpm versions that accept
 2301 # "--target=arch" instead of "--target arch"
 2302 # are 3.x < version < 4.0.3
 2303 
 2304 if [ $RPM_MAJOR_VERSION -eq 4 -a $RPM_PATCH_LEVEL -lt 3 ]; then
 2305    RPM_TARGET_FLAG="--target="
 2306 else
 2307    RPM_TARGET_FLAG="--target "
 2308 fi
 2309 
 2310 # rpmbuild seems to exist only in RPM 4
 2311 
 2312 if [ $RPM_MAJOR_VERSION -eq 4 ]; then
 2313    RPMBUILD="rpmbuild"
 2314 else
 2315    RPMBUILD="rpm"
 2316 fi
 2317 
 2318 if [ "$RPMBUILD" = "rpmbuild" -a ! -x "`which rpmbuild 2> /dev/null`" ]; then
 2319    echo
 2320    echo "*** The \"rpmbuild\" program is not in your PATH!"
 2321    echo
 2322    echo "*** RPM package creation aborted"
 2323    FAILED=1
 2324 fi
 2325    
 2326 if ! [ $FAILED -gt 0 ]; then
 2327 
 2328 
 2329 # Find out the RPM source directory path
 2330 
 2331 if ! [ "$RPMSOURCEDIR" ]; then
 2332    if [ $RPM_MAJOR_VERSION -eq 3 -a $RPM_PATCH_LEVEL -ge 3 -o $RPM_MAJOR_VERSION -gt 3 ]; then
 2333       RPMSOURCEDIR="`rpm --eval=%_topdir`"
 2334    else
 2335       RPMSOURCEDIR="NOT-FOUND"
 2336       for directory in packages OpenLinux redhat RedHat rpm RPM "" ; do
 2337          [ -d /usr/src/${directory}/SOURCES ] && RPMSOURCEDIR="/usr/src/${directory}"
 2338       done
 2339    fi
 2340 fi
 2341 
 2342 [ $DEBUG -gt 0 ] && echo "debug: RPMSOURCEDIR=$RPMSOURCEDIR"
 2343 
 2344 
 2345 while ! [ -d "$RPMSOURCEDIR/SOURCES" ]; do
 2346    echo
 2347    echogn "%s has no SOURCES directory. Please write the path to\nthe RPM source directory tree: " "$RPMSOURCEDIR"
 2348    read RPMSOURCEDIR
 2349    ! [ "$RPMSOURCEDIR" ] && RPMSOURCEDIR="NOT-FOUND"
 2350 done
 2351 
 2352    
 2353 # We'll write a basic spec file
 2354 
 2355 if ! [ -f "$SPEC_PATH" ]; then
 2356 
 2357 # If the buildroot path has spaces then we'll use the BUILD_DIR instead.
 2358 # rpm can't have a buildroot path with spaces in it (Bug?)
 2359 #
 2360 # This is obviously a hack, I hope we can do it the right way when rpm is
 2361 # fixed.
 2362 
 2363 if ( echo $DIRECTORIO_FUENTE | grep " " &> /dev/null ); then
 2364    BROOTPATH="${DIRECTORIO_FUENTE}/buildroot"
 2365 else
 2366    BROOTPATH=$BUILD_DIR
 2367 fi
 2368 
 2369 # Here comes the .spec file:
 2370 
 2371    cat > "$SPEC_PATH" << EOF
 2372 Summary:   $SUMMARY
 2373 Name:      $NAME
 2374 Version:   $VERSION
 2375 Release:   $RELEASE
 2376 License: $LICENSE
 2377 Packager:  checkinstall-$CHECKINSTALL_VERSION
 2378 Group:     $PKG_GROUP          
 2379 BuildRoot: $BROOTPATH
 2380 Provides:  $PROVIDES
 2381 Requires:  $REQUIRES,/bin/sh
 2382 
 2383 %description
 2384 EOF
 2385    cat description-pak >> "$SPEC_PATH"
 2386 
 2387 
 2388 # Use the preinstall-pak script if we have it
 2389 if [ -f preinstall-pak ]; then
 2390    echo  >> "$SPEC_PATH" 
 2391    echo '%pre' >> "$SPEC_PATH" 
 2392    cat preinstall-pak  >> "$SPEC_PATH"
 2393 fi
 2394 
 2395 # Use the postinstall-pak script if we have it
 2396 if [ -f postinstall-pak ]; then
 2397    echo >> "$SPEC_PATH" 
 2398    echo '%post' >> "$SPEC_PATH" 
 2399    cat postinstall-pak  >> "$SPEC_PATH"
 2400 fi
 2401 
 2402 # Use the preremove-pak script if we have it
 2403 if [ -f preremove-pak ]; then
 2404    echo >> "$SPEC_PATH" 
 2405    echo '%preun' >> "$SPEC_PATH" 
 2406    cat preremove-pak  >> "$SPEC_PATH"
 2407 fi
 2408 
 2409 # Use the postremove-pak script if we have it
 2410 if [ -f postremove-pak ]; then
 2411    echo >> "$SPEC_PATH" 
 2412    echo '%postun' >> "$SPEC_PATH" 
 2413    cat postremove-pak  >> "$SPEC_PATH"
 2414 fi
 2415 
 2416    cat >> "$SPEC_PATH" << EOF
 2417 
 2418 %files
 2419 EOF
 2420 
 2421 # Prepare directories to be included in the .spec file
 2422 mv ${TMP_DIR}/newfiles ${TMP_DIR}/newfiles.tmp
 2423 cat ${TMP_DIR}/newfiles.tmp | while read line; do
 2424    [ -d "${BUILD_DIR}/${line}" -o -L "${BUILD_DIR}/${line}" ] && echo -n "%dir " >> ${TMP_DIR}/newfiles
 2425    echo "\"/${line}\"" >> ${TMP_DIR}/newfiles
 2426 done
 2427 
 2428 # Append the file list to the .spec file
 2429 cat ${TMP_DIR}/newfiles >> "$SPEC_PATH" 
 2430 fi
 2431 
 2432 
 2433 # If requested with --review-spec, we run an editor on the .spec file
 2434 if [ $REVIEW_SPEC -gt 0 ]; then
 2435    echo
 2436    echog "You requested to review the .spec file for this package.\nNow you\'ll have the chance to review and optionally modify this file."
 2437    echo
 2438    echog "Press ENTER to continue."
 2439    read junk
 2440    $VISUAL "$SPEC_PATH" 
 2441 fi
 2442 
 2443 BUILDROOT=`egrep '^[Bb]uild[Rr]oot' < "$SPEC_PATH" | cut -f2 -d:| sed 's/^ *//g'| sed 's/ *$//g'` # The sed commands remove leading/trailing whitespaces
 2444 
 2445 # We make sure that we have a valid RELEASE number
 2446 
 2447 ! [ "$RELEASE" ] && RELEASE=`egrep '^Release:' < "$SPEC_PATH"|cut -f2 -d: | awk '{ for (i=1;substr ($0,i,1) ~ /[[:blank:]]/ ;i++); print substr ($0,i); }'`
 2448 
 2449 [ $DEBUG -gt 0 ] && echo "debug: BUILDROOT=$BUILDROOT"
 2450 
 2451 ! [ -d "$BUILDROOT" ] &&  ln -s "$BUILD_DIR" "$BUILDROOT"
 2452 
 2453 # We make sure that the architecture directory exists
 2454 
 2455 ! [ -d "${RPMSOURCEDIR}/RPMS/${ARCHITECTURE}" ] && mkdir -p "${RPMSOURCEDIR}/RPMS/${ARCHITECTURE}"
 2456 
 2457 
 2458 mkdir "${TMP_DIR}/$PKG_BASENAME"
 2459 cd $TMP_DIR
 2460 $TAR -cz -f "${RPMSOURCEDIR}/SOURCES/${PKG_BASENAME}.tgz" "$PKG_BASENAME"
 2461 rm -rf "${TMP_DIR}/$PKG_BASENAME"
 2462 cd "$DIRECTORIO_FUENTE"
 2463 
 2464 echo
 2465 echogn "Building RPM package..."
 2466 $RPMBUILD -bb ${RPM_TARGET_FLAG}${ARCHITECTURE} "$SPEC_PATH" &> ${TMP_DIR}/rpmbuild.log
 2467 okfail
 2468 
 2469 if [ $? -gt 0 ]; then
 2470    echo
 2471    echog "*** Failed to build the package"
 2472    echo
 2473    echogn "Do you want to see the log file? "
 2474    if yorn ; then
 2475       $PAGER ${TMP_DIR}/rpmbuild.log
 2476    fi
 2477    FAILED=1
 2478 fi
 2479  
 2480 RPMPKG="${RPMSOURCEDIR}/RPMS/${ARCHITECTURE}/${PKG_BASENAME}-${RELEASE}.${ARCHITECTURE}.rpm"
 2481 
 2482 # Check for the old RPMFLAGS
 2483 if [ "$RPMFLAGS" ]; then
 2484    echo
 2485    echog "Warning: the use of RPMFLAGS is deprecated.\nWarning: You should now use RPM_FLAGS,\nWarning: please update your checkinstallrc file."
 2486 fi
 2487 
 2488 if ! [ $FAILED -gt 0 ]; then 
 2489    if [ "$INSTALL" = "1" ]; then
 2490 
 2491       echo
 2492       echogn "Installing RPM package..."
 2493       rpm -$RPM_IU $RPM_FLAGS "${RPMPKG}" &>  ${TMP_DIR}/rpminstall.log
 2494       okfail
 2495       if [ $? -gt 0 ]; then
 2496          echo
 2497          echog "*** Failed to install the package"
 2498          echo
 2499          echogn "Do you want to see the log file? "
 2500          if yorn ; then
 2501             $PAGER ${TMP_DIR}/rpminstall.log
 2502          fi
 2503          FAILED=1
 2504       fi
 2505    else
 2506       echo
 2507       echog "NOTE: The package will not be installed"
 2508    fi
 2509 fi
 2510    
 2511 if ! [ $FAILED -gt 0 ]; then
 2512    PKG_LOCATION="$RPMPKG"
 2513    INSTALLSTRING="rpm -i `basename "$RPMPKG"`"
 2514    REMOVESTRING="rpm -e ${PKG_BASENAME}-${RELEASE}"
 2515 fi
 2516    
 2517    
 2518 fi  # End of the "no rpmbuild in the path" if
 2519 fi  # End of the "no rpm in the path" if
 2520 
 2521 ;;
 2522 
 2523                        #################################
 2524                        #    End RPM package section    #
 2525 ##############################################################################
 2526 
 2527 
 2528 
 2529 ##############################################################################
 2530                         # Debian  package installation #
 2531                         ################################
 2532 
 2533 
 2534 d|D)
 2535 
 2536 # As we said before:
 2537 PKG_BASENAME=$NAME
 2538 # maybe PKG_BASENAME should be defined locally for all the install
 2539 # types, and not only on debian...
 2540 
 2541 FAILED=0
 2542 
 2543 
 2544 # Verify that we have the dpkg command in our path
 2545 
 2546 DPKG_PATH=`which dpkg 2> /dev/null`
 2547 
 2548 if ! [ -x "$DPKG_PATH" ]; then
 2549    echo
 2550    echog "*** The \"dpkg\" program is not in your PATH!"
 2551    echo
 2552    echog "*** Debian package creation aborted"
 2553    FAILED=1
 2554 fi
 2555    
 2556 if ! [ $FAILED -gt 0 ]; then
 2557 
 2558 cd "$DIRECTORIO_FUENTE"
 2559 
 2560 # We'll write a basic Debian control file
 2561 
 2562 
 2563 mkdir $BUILD_DIR/DEBIAN
 2564 
 2565 cat << EOF >> $BUILD_DIR/DEBIAN/control
 2566 Package: $PKG_BASENAME
 2567 Priority: extra
 2568 Section: $PKG_GROUP
 2569 Installed-Size: `du -s $BUILD_DIR | awk '{print $1}'`
 2570 Maintainer: $MAINTAINER
 2571 Architecture: $ARCHITECTURE
 2572 Version: ${VERSION}-${RELEASE}
 2573 Depends: $REQUIRES
 2574 Provides: $PROVIDES
 2575 Conflicts: $CONFLICTS
 2576 Replaces: $REPLACES
 2577 Description: $SUMMARY
 2578 EOF
 2579 
 2580 # Add the description
 2581 cat "$DIRECTORIO_FUENTE/description-pak"| egrep -v "$SUMMARY|^[     ]*$" | while read line; do
 2582    echo " "$line >> $BUILD_DIR/DEBIAN/control
 2583 done
 2584 
 2585 
 2586 # Use the preinstall-pak script if we have it
 2587 if [ -f preinstall-pak ]; then
 2588    cat preinstall-pak > $BUILD_DIR/DEBIAN/preinst
 2589    chmod 755 $BUILD_DIR/DEBIAN/preinst
 2590 fi
 2591 
 2592 # Use the postinstall-pak script if we have it
 2593 if [ -f postinstall-pak ]; then
 2594    cat postinstall-pak > $BUILD_DIR/DEBIAN/postinst
 2595    chmod 755 $BUILD_DIR/DEBIAN/postinst
 2596 fi
 2597 
 2598 # Use the preremove-pak script if we have it
 2599 if [ -f preremove-pak ]; then
 2600    cat preremove-pak > $BUILD_DIR/DEBIAN/prerm
 2601    chmod 755 $BUILD_DIR/DEBIAN/prerm
 2602 fi
 2603 
 2604 # Use the postremove-pak script if we have it
 2605 if [ -f postremove-pak ]; then
 2606    cat postremove-pak > $BUILD_DIR/DEBIAN/postrm
 2607    chmod 755 $BUILD_DIR/DEBIAN/postrm
 2608 fi
 2609 
 2610 # Tag files in /etc to be conffiles
 2611 find $BUILD_DIR/etc 2> /dev/null | sed -e "s,$BUILD_DIR,," | \
 2612     grep -v '^/etc$' > $BUILD_DIR/DEBIAN/conffiles
 2613 
 2614 # The package will be saved here (ignores <epoch>: prefix):
 2615 DEBPKG="${DIRECTORIO_FUENTE}/${NAME}_`echo ${VERSION} | sed -e 's/^[0123456789]*://'`-${RELEASE}_${ARCHITECTURE}.deb"
 2616 # This one is for 2.2 "Potato" (or older) style packages
 2617 #DEBPKG="${DIRECTORIO_FUENTE}/${NAME}_${VERSION}-${RELEASE}.deb"
 2618 
 2619 if [ $DEBUG -gt 0 ]; then
 2620   echo
 2621   echo debug: PKG_BASENAME=${PKG_BASENAME}
 2622   echo debug: BUILD_DIR=${BUILD_DIR}
 2623   echo debug: DEBPKG=${DEBPKG}
 2624   echo debug: dpkg command:
 2625   echo "   \"dpkg-deb -b $BUILD_DIR $DEBPKG &> ${TMP_DIR}/dpkgbuild.log\""
 2626 fi
 2627 
 2628 # If requested with --review-control, we run an editor on the control file
 2629 if [ $REVIEW_CONTROL -gt 0 ]; then
 2630    echo
 2631    echog "You requested to review the control file for this package.\nNow you'll have the chance to review and optionally modify this file."
 2632    echo
 2633    echog "Press ENTER to continue."
 2634    read junk
 2635    $VISUAL ${BUILD_DIR}/DEBIAN/control
 2636 fi
 2637 
 2638 echo
 2639 echogn "Building Debian package..."
 2640 dpkg-deb -b $BUILD_DIR "$DEBPKG" &> ${TMP_DIR}/dpkgbuild.log
 2641 okfail
 2642       
 2643 if [ $? -gt 0 ]; then
 2644    echo
 2645    echog "*** Failed to build the package"
 2646    echo
 2647    echogn "Do you want to see the log file? "
 2648    if yorn ; then
 2649       $PAGER ${TMP_DIR}/dpkgbuild.log
 2650    fi
 2651    FAILED=1
 2652 fi
 2653 
 2654 
 2655 if ! [ $FAILED -gt 0 ]; then
 2656    if [ "$INSTALL" = "1" ]; then
 2657 
 2658       echo
 2659       echogn "Installing Debian package..." 
 2660       dpkg -i $DPKG_FLAGS "$DEBPKG" &>  ${TMP_DIR}/dpkginstall.log
 2661       okfail
 2662       if [ $? -gt 0 ]; then
 2663          echo
 2664          echog "*** Failed to install the package"
 2665          echo
 2666          echogn "Do you want to see the log file? "
 2667          if yorn ; then
 2668             $PAGER ${TMP_DIR}/dpkginstall.log
 2669          fi
 2670          FAILED=1
 2671       fi
 2672    else
 2673       echo
 2674       echog "NOTE: The package will not be installed"
 2675    fi
 2676 fi
 2677  
 2678 if ! [ $FAILED -gt 0 ]; then
 2679    PKG_LOCATION="$DEBPKG"
 2680    INSTALLSTRING="dpkg -i `basename "$DEBPKG"`"
 2681    REMOVESTRING="dpkg -r ${PKG_BASENAME}"
 2682 fi
 2683 
 2684 
 2685 fi
 2686 
 2687 ;;
 2688 
 2689 
 2690                        ################################
 2691                        #  End Debian package section  #
 2692 ##############################################################################
 2693 
 2694 
 2695 esac
 2696 
 2697 # If we have a package repository set, move the package there
 2698 
 2699 if ! [ $FAILED -gt 0 ]; then
 2700 
 2701    if [ "$PAK_DIR" ]; then
 2702       if ! [ -d "$PAK_DIR" ]; then
 2703          echo
 2704          echogn "The package storage directory [ %s ]\ndoesn\'t exist. Do you want to create it?" "$PAK_DIR"
 2705          if yorn ; then
 2706             echo
 2707             echogn "Creating package storage directory..."
 2708             mkdir -p "$PAK_DIR" &> ${TMP_DIR}/mkpakdir.log
 2709             okfail 
 2710             if [ $? -gt 0 ]; then
 2711                echo 
 2712                echog "*** Unable to create %s" "$PAK_DIR"
 2713                echo "*** `cat ${TMP_DIR}/mkpakdir.log`"
 2714                echo
 2715             fi
 2716          fi
 2717       fi
 2718       if [ -d "$PAK_DIR" ]; then 
 2719          echo
 2720          echogn "Transferring package to %s..." "$PAK_DIR"
 2721          mv "$PKG_LOCATION" "${PAK_DIR}" &> $TMP_DIR/transfer.log
 2722          okfail
 2723          if [ $? -gt 0 ]; then
 2724             echo
 2725             echogn "*** Transfer failed:"
 2726             cat $TMP_DIR/transfer.log
 2727             echo
 2728          else
 2729             # Update the package location
 2730             PKG_LOCATION="${PAK_DIR}/`basename "$PKG_LOCATION"`"
 2731          fi
 2732       else 
 2733          echo
 2734          echog "There\'s no package storage directory, the package\nwill be stored at the default location."
 2735       fi
 2736    fi
 2737 fi
 2738 
 2739 #
 2740 # Remove trash from TMP_DIR
 2741 #
 2742 
 2743 echo 
 2744 echogn "Erasing temporary files..."
 2745 
 2746 # Preserve the Debian control file if debug is on
 2747 if [ $DEBUG -gt 0 ]; then
 2748    if [ -d ${BUILD_DIR}/DEBIAN ]; then
 2749        mv ${BUILD_DIR}/DEBIAN $TMP_DIR
 2750    fi
 2751 fi
 2752 
 2753 [ $DEBUG -lt 2 ] && rm -rf ${BUILD_DIR}
 2754 rm -f checkinstall-debug*
 2755 rm -f "$BUILDROOT"
 2756 rm -f "${RPMSOURCEDIR}/SOURCES/${PKG_BASENAME}.tgz"
 2757 okfail
 2758 
 2759 # Delete doc-pak directory
 2760 if [ $DEL_DOCPAK -gt 0 ]; then
 2761    echo
 2762    echogn "Deleting doc-pak directory..."
 2763    rm -rf doc-pak
 2764    okfail
 2765 fi
 2766 
 2767 # Preserve the spec file if debugging is on
 2768 [ $DEBUG -gt 0 ] && [ -f "$SPEC_PATH" ] && cp "$SPEC_PATH" $TMP_DIR
 2769 
 2770 # Delete spec file
 2771  [ $DEL_SPEC -gt 0 ] && rm -f "$SPEC_PATH"
 2772 
 2773 # Delete the package description file
 2774  [ $DEL_DESC -gt 0 ] && rm -f description-pak
 2775 
 2776 
 2777 # If we had a pre-existing postinstall-pak, we keep it as it was.
 2778 
 2779 # If PINST_EXISTS=0 and there is a postinstall-pak file, then
 2780 # it's the one we created and has to be deleted 
 2781 if [ $PINST_EXISTS -eq 0 ]; then  
 2782    rm -f ${DIRECTORIO_FUENTE}/postinstall-pak
 2783 fi
 2784 
 2785 if [ -f ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ]; then
 2786    mv ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ${DIRECTORIO_FUENTE}/postinstall-pak
 2787 fi
 2788 
 2789 
 2790 # If we have a backup, pack it up
 2791 
 2792 rm -rf ${TMP_DIR}/BACKUP/no-backup &> /dev/null
 2793 ls ${TMP_DIR}/BACKUP/* &> /dev/null
 2794 if [ $? -eq 0 ]; then
 2795    cd ${TMP_DIR}/BACKUP
 2796    echo
 2797    echogn "Writing backup package..."
 2798    # We do this for the same reason as in restore_backup
 2799    FILES=$(ls -A)
 2800    $TAR -cpf - $FILES | gzip -9 > "${DIRECTORIO_FUENTE}/backup-`date +%m%d%Y%H%M`-pre-${PKG_BASENAME}.tgz"
 2801     okfail
 2802 
 2803    okfail
 2804 fi
 2805 
 2806 
 2807 if [ $DEBUG -eq 0 ]; then
 2808    echo
 2809    echogn "Deleting temp dir..."
 2810    rm -rf ${TMP_DIR}
 2811    okfail
 2812    echo
 2813 else
 2814    echo
 2815    echogn "Building debug information package..."
 2816    cd ${TMP_DIR}
 2817    echo `uname -a` > sysinfo
 2818    echo `rpm --version` >> sysinfo
 2819    $TAR -cpzvf "${DIRECTORIO_FUENTE}/checkinstall-debug.$$.tgz" * &> /dev/null
 2820    okfail
 2821 fi
 2822 
 2823 
 2824 if ! [ $FAILED -gt 0 ]; then
 2825 
 2826    if [ "${INSTALL}" = "1" ]; then
 2827 
 2828       echo
 2829       echo '**********************************************************************'
 2830       echo
 2831       echog " Done. The new package has been installed and saved to\n\n %s\n\n You can remove it from your system anytime using: \n\n      %s" "$PKG_LOCATION"  "$REMOVESTRING"
 2832       echo
 2833       echo '**********************************************************************'
 2834       echo
 2835 
 2836    else
 2837 
 2838       echo
 2839       echo '**********************************************************************'
 2840       echo
 2841       echog " Done. The new package has been saved to\n\n %s\n You can install it in your system anytime using: \n\n      %s" "$PKG_LOCATION" "$INSTALLSTRING"
 2842       echo
 2843       echo '**********************************************************************'
 2844       echo
 2845 
 2846    fi
 2847       
 2848 fi
 2849 
 2850 
 2851 
 2852