LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware - Installation (http://www.linuxquestions.org/questions/slackware-installation-40/)
-   -   Create packages from installed X11R7.3 (or any generic set of bins) (http://www.linuxquestions.org/questions/slackware-installation-40/create-packages-from-installed-x11r7-3-or-any-generic-set-of-bins-615723/)

andrems 01-23-2008 09:23 AM

Create packages from installed X11R7.3 (or any generic set of bins)
 
Hello there

I had some trouble with and old IDE HD and had to re-install Slackware 12. It was nice that I had stored packages that I built (beryl and deps, PyQT, pycairo etc etc) in a different place. The thing is, Slack 12 comes with X11R6 and I followed this to upgrade. Worked as is following post #1, but now I'm back to X11R6 :(

Does this script updates the installed packages list? (that one accessed by pkgtool, can't rememeber it's folder location)


Is there a way (besides searching for every single file and reorganizing them so makepkg can recognize) to "repackage" to a single .tgz archive so I can store and back-up in the future?
EDIT:
Found in the Slackbook
removepkg -copy packagename


The only question is if the build-from-tarballs.sh script updates /var/log/packages


Thanks

gnashley 02-03-2008 01:00 PM

Here you go:
Code:

#!/bin/bash
#
# The purpose of this script is to recreate a Slackware package
# from your disk. Basicly the opposite of installpkg, where
# installpkg will install software on your system. This script
# will recreate the Slackware package that was installed, if you
# misplaced the original package, but still have it installed.
#
# This software is released and licensed under the GPL v2, for
# further documentation look at http://www.gnu.org/copyleft/gpl.html
#
# Author: James Caffrey <jamescaffrey@gmail>
# Version: 1.4.0
#
#
# Some variables
VER=1.4.0
CWD=`pwd`
PKGDB="/var/log/packages"
PKGDBS="/var/log/scripts"

# Exit Status
# 0 Clean
# 1 Did not pass sanity checks
# 2 Errors
# 3 Package not found

# Sanity checks
if [ "`whoami`" != "root" ]; then
  echo
  echo "ERROR: You must be root!"
  echo
  exit 1
fi
if [ ! -e "/sbin/makepkg" ]; then
  echo
  echo "ERROR: You seem to be missing /sbin/makepkg you"
  echo "      should get it from a Slackware mirror."
  echo
  exit 1
fi
if [ ! -d "$PKGDB" -o -d "PKGDBS" ]; then
  echo
  echo "ERROR: You are missing one or both of the following"
  echo "      directories: /var/log/packages /var/log/scripts"
  echo "      Please install pkgtools from a Slackware mirror"
  echo
  exit 1
fi

# Functions
usage() {
  cat << EOF
`basename $0` $VER
A tool to rebuild a Slackware package from hard disk. This can
be used to rebuild the package, when you have lost it, but it is
still installed on your system.

Options:
        -h|--help                Shows this help message
        -v|--version                Displays version information

Usage:
        `basename $0` [options] <package_name> ...
EOF
}

count_args() {
  args=$#
}

show_list() {
while true
do
  echo
  echo "More than one package was found with the name $PKGNAME"
  echo "so here is a list of packages that match your description"
  echo "Please choose one:"
  #give a list
  find $PKGDB -type f -name "*$PKGNAME*" -exec basename {} \; | sort
  echo
  echo -n "Enter package name here: "
  read PKGNAME
  #make sure we have the full package
  #name so we can break it down later
  count_args `find $PKGDB -type f -name "*$PKGNAME*" -exec basename {} \;`
  if [ "$args" = "1" ]; then
        #we got it
        PKGNAME=`find $PKGDB -type f -name "*$PKGNAME*" -exec basename {} \;`
        return
  fi
  if [ "$args" = "0" ]; then
        echo
        echo "Your package name $PKGNAME could not be found"
        echo
        exit 2
  fi
done
}

# Just one more sanity check :)
if [ $# = 0 ]; then
  usage
  exit 0
fi

# Parse args
while [ ! -z $1 ]; do
CLEANUP=1
if [ "$1" = "-h" -o "$1" = "--help" ]; then
  usage
  exit 0
elif [ "$1" = "-v" -o "$1" = "--version" ]; then
  echo "`basename $0` $VER"
  exit 0
else
  PKGNAME=$1
fi

#having troubles with this :(
#CLEANUP=1
#while [ "$1" ]; do
#  case "$1" in
#        '-h|--help')                usage; exit 0 ;;
#        '-v|--version')        echo "`basename $0` $VER"; exit 0;;
#        '-n|--no-cleanup')        CLEANUP="0";;
#        '-t|--tmp')                TMP="$OPTARG"
#                                shift 2;;
#        *)                        PKGNAME="`basename $1 .tgz`";;
#  esac
#done

# Setup a tmp directory
TMP=${TMP:-/var/tmp/`basename $0`}
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi

# Get full package name
count_args `find $PKGDB -type f -name "*$PKGNAME*" -exec basename {} \;`
#count_args sets the args variable
case "$args" in
  0)
        echo
        echo "Your package $PKGNAME could not be found"
        echo
        exit 3;;
  1)
        PKGNAME=`find $PKGDB -type f -name "*$PKGNAME*" -exec basename {} \;`
        ;; #we should be good
  *)
        show_list
        ;;
esac

# Break down package name
NAME="`echo $PKGNAME | rev | cut -f 4- -d - | rev`"
VERSION="`echo $PKGNAME | rev | cut -f 3 -d - | rev`"
ARCH="`echo $PKGNAME | rev | cut -f 2 -d - | rev`"
BUILD="`echo $PKGNAME | rev | cut -f 1 -d - | rev`"

# Setup work space, and hierarchy
PKGDIR="$TMP/package-$NAME"
if [ ! -d "$PKGDIR" ]; then
  mkdir -p $PKGDIR
fi
mkdir -p $PKGDIR/install

# Copy files
for files in `cat $PKGDB/$PKGNAME | grep -v "$NAME:" | grep -v "PACKAGE" | grep -v "FILE LIST:"`
do
  if [ "$files" = "install/slack-desc" ]; then
      cat $PKGDB/$PKGNAME | grep "$NAME:" > $PKGDIR/install/slack-desc
  elif [ "$files" = "install/doinst.sh" ]; then
      #some packages have the "upgraded" status in
      #their file name, so we have to account for that
      if [ -e "$PKGDBS/$PKGNAME" ]; then
        cat $PKGDBS/$PKGNAME > $PKGDIR/install/doinst.sh
      else
        #when packages do have the "upgraded" status, their
        #file name is usually not equal to PKGNAME most of
        #the time the revision is different. Not perfect I
        #know, but it hasn't failed yet. :)
        find $PKGDBS -name "*$NAME-$VERSION*" -exec cat {} > $PKGDIR/install/doinst.sh \;
      fi
  elif [ -f "/$files" ]; then
      #maybe the .new file still remains
      cp -p "/$files" "$PKGDIR/`dirname $files`"
  elif [ -f "/`dirname $files`/`basename $files .new`" ]; then
      #we have to replace the .new
      cp -p "/`dirname $files`/`basename /$files .new`" "$PKGDIR/`dirname $files`"
      DIR=`pwd`
      cd "$PKGDIR/`dirname $files`"
      OLD=`basename $files .new`
      mv $OLD "$OLD.new"
      cd $DIR
  elif [ -d "/$files" ]; then
      #its a directory
      mkdir -p $PKGDIR/$files
  elif [ "$files" = "install/" ]; then
      #there is no /install directory
      #true
      continue
  else
      echo
      echo "ERROR: $files could not be found"
      echo "      still continuing"
      echo
  fi
done

# Correct permissions
for dir in /{bin,sbin} /usr/{bin,sbin} /usr/local/{bin,sbin} /usr/X11R6/bin ; do
  if [ -d "$PKGDIR$dir" ]; then
        chown -R root.bin $PKGDIR$dir
  fi
done

# Make the package
cd $PKGDIR
/sbin/makepkg -l y -c n $NAME-$VERSION-$ARCH-$BUILD.tgz

# Housekeeping stuff
cp $NAME-$VERSION-$ARCH-$BUILD.tgz $CWD
cd $CWD
if [ "$CLEANUP" -eq "1" ]; then
  rm -rf $PKGDIR
fi
shift
done
exit 0
#########################ChangeLog###############################
#                                                                #
#  20050609 1.4.0                                                #
#        *Added support for passing multiple package                #
#        names                                                        #
#        *Increased list of assorted bin folders to                #
#        include 'local' directories                                #
#                                                                #
#  20050508 1.3.2                                                #
#        *Reimplemented package break down, no loop                #
#        *Having problems with parsing the args, so it                #
#        has been redesigned                                        #
#        *Updated usage() to reflect changes                        #
#        *Bug fix, with correcting permissions of assorted        #
#        bin folders                                                #
#                                                                #
#  20050424 1.3.1                                                #
#        *Modified exit status                                        #
#        *Code cleanup with parsing arguments                        #
#        *Minor code clean, using parameter expansion                #
#        instead of if statement                                #
#                                                                #
#  20050401 1.3                                                #
#        *Optimized package searching by using -name                #
#        with the find command as opposed to piping                #
#        all data through grep                                        #
#                                                                #
#  20050326 1.2                                                #
#        *Cleanup the Copying Files loop to be more                #
#        friendly with .new files.                                #
#        *Allowed package searching for input with                #
#        less than full name ie: foo                                #
#                                                                #
#  20050309 1.1                                                #
#        *Packages with a dash in the "name" now work                #
#                                                                #
#  20050308 1.0                                                #
#        *Initial release                                        #
#                                                                #
#################################################################

# End of buildpkg

Just paste that into an empty text file, save it as 'buildpkg' (or other name), copy into your path (like /usr/local/bin) and then make it executable with chmod 755 /usr/local/bin/buildpkg
I'm passing this along unmodified -don't remeber where I found it but it's part of a collection of useful tools I've found for slackware.

andrems 02-06-2008 09:45 AM

Thanks, gnashley

I don't understand shell scripting, but I read it and it does exactly what I wanted, though the removepkg -copy packagename apparently does the trick (half of it, just the package's base tree).

In fact, I upgraded the X11R7.3 from the slack-current site as I was going trough some pain like this.

Anyway, if anyone has build X11 from that build-from-tarballs.sh, I think it stores the logs and install scripts of installed files in ${DESTDIR}${PREFIX}/var/log, so from there is possible to package X11R7.3.

Didn't tried this, hope it helps someone. :)


All times are GMT -5. The time now is 07:54 PM.