#!/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 # 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] ... 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