#!/bin/bash ############################################################################### # amypkg v1.4 A Slackware Package Management Tool # Copyright (C) 2004 Rob Page # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################### #http_proxy=wwwcache.aber.ac.uk:8080 #ftp_proxy=wwwcache.aber.ac.uk:8080 BASEDIR=/var/db/amypkg/ AMYDIR=${BASEDIR}slackware/ AMYDIREXTRA=${BASEDIR}extra/ MIRROR=ftp://ftp.heanet.ie/mirrors/ftp.slackware.com/pub/slackware/slackware-current/slackware/ MIRROREXTRA=http://mirror.etf.bg.ac.yu/linuxpackages/Slackware-10.0/ VERSION=1.4 AMYPKGURL=http://heanet.dl.sourceforge.net/sourceforge/amypkg/amypkg TESTMD5= TESTMD5=TRUE # Comment this line out to disable MD5 testing.. This is not recommended. FORCE= COMMAND= amypkg_upgrade() { if [ -e /usr/sbin/amypkg ] then mv /usr/sbin/amypkg ${BASEDIR}./amypkg-${VERSION} fi wget ${AMYPKGURL} -O /usr/local/sbin/amypkg && chmod u+rwx /usr/sbin/amypkg && echo Upgrade Sucessful.. amypkg ${VERSION} stored at ${BASEDIR}amypkg-${VERSION} } amypkg_getfile() { if [ ! -e CHECKSUMS.md5 ] then wget ${MIRROR}./CHECKSUMS.md5 fi if [ ! -e $1 ] then wget ${MIRROR}./$1 -O $1 else if [ $FORCE ] then wget ${MIRROR}./$1 -O $1 fi fi if [ ${TESTMD5} ] && [ ! "$2" = --NOMD5 ] then if grep -q "`md5sum ${1}`" CHECKSUMS.md5 then echo $1... MD5sum OK else if [ "$2" ] then shift echo MD5sum failed, trying alternate package $1 amypkg_getfile $@ else echo $1 MD5sum FAILED! && echo "Found: `md5sum $1`" && echo "Expected: `grep $1 CHECKSUMS.md5`" && if [ $FORCE ] then echo "Please run 'amypkg --force update' if this does not" echo "resolve the problem, then please report this as a bug" else echo "Please remove manually or rerun with --force" fi exit -1 fi fi fi } amypkg_optimise() { echo -n Optimising Files... && cp MANIFEST.bz2 manifest.bz2 bunzip2 manifest.bz2 && echo -n half wayish... && sed -e 's/^...-.*$//g' \ -e 's/^d.*$//g' \ -e 's/^[^|].\{50\}//g' \ -e 's/^+.*$//g' \ -e 's/^||$//g' \ -e '/^$/d' manifest > optimanifest && rm manifest && echo Done Optimising Files } amypkg_update() { echo Checking Core Files amypkg_getfile ./PACKAGES.TXT --NOMD5 amypkg_getfile ./FILELIST.TXT ./FILE_LIST if [ -e FILE_LIST ] then cp FILE_LIST FILELIST.TXT fi amypkg_getfile ./MANIFEST.bz2 echo Downloads Completed Successfully amypkg_optimise echo Update Done } amypkg_filedeps() { echo Scanning Files until [ ! -s tmp/files.tmp ] do FILE=`tail -n1 tmp/files.tmp` ldd /${FILE} | \ grep not\ found | \ sed -e 's/^[ \t]*//' -e 's/ => not found*$//' >> tmp/missing.tmp head -n-1 tmp/files.tmp > tmp/files2.tmp mv tmp/files2.tmp tmp/files.tmp done sort tmp/missing.tmp > tmp/missing2.tmp uniq tmp/missing2.tmp > tmp/missing.tmp cp tmp/missing.tmp missing.tmp echo Getting List of Packages to Install until [ ! -s tmp/missing.tmp ] do MISSING=`tail -n1 tmp/missing.tmp` echo -n Scanning for ${MISSING}... MISSINGPKG=`tac optimanifest | \ sed -n '/'${MISSING}'/,$p' | \ sed -n '/^||.*$/p' | \ head -n1 | \ sed -e 's/|| Package: .\/.*\///'` FOUNDPKG=`sed -n '/PACKAGE NAME: '${MISSINGPKG}'/,$p' PACKAGES.TXT | \ sed -n '/^[^\(PACKAGE\)]/,$p' | \ head -n1 | \ sed -e 's/:.*$//'` if [ ${FOUNDPKG} ] then echo Found! Installing ${FOUNDPKG} amypkg_install ${FOUNDPKG} else echo echo Could not find library: $MISSING echo You could try rerunning this command with -x to search the extra packages echo Also, the package may exist but just not have been included in the Manifest echo For instance if the missing library is called: libsigc-2.0.so.0 try: echo 'amyedit install -x libsigc' exit -1; fi head -n-1 tmp/missing.tmp > tmp/missing2.tmp mv tmp/missing2.tmp tmp/missing.tmp done } amypkg_pkgdeps() { echo Checking Dependencies until [ ! -s tmp/packages.tmp ] do PACKAGE=`tail -n1 tmp/packages.tmp | \ sed -e 's:/[^/]*/:/:' -e 's:/:\\\\/:g'` sed -n '/|| Package: '${PACKAGE}'/,$p' optimanifest | \ sed -n '1,/^||/p' | \ sed -e '/^||/d' >> tmp/files.tmp head -n-1 tmp/packages.tmp > tmp/packages2.tmp mv tmp/packages2.tmp tmp/packages.tmp if [ `cat tmp/files.tmp` ] then amypkg_filedeps fi done } amypkg_install() { until [ -z "$1" ] do case "$1" in (-*) ;; (*) grep "PACKAGE NAME: $1" PACKAGES.TXT | sed -e 's/PACKAGE NAME: *//' > tmp/pkgstxt.tmp case "`wc -l tmp/pkgstxt.tmp | cut -f1 -d\ `" in ('0') echo No matching packages in PACKAGES.TXT! checking FILELIST.TXT grep '/'$1'[^/]*\.tgz' FILELIST.TXT | sed -e 's!^.* \./!./!' > tmp/pkgstxt.tmp case "`wc -l tmp/pkgstxt.tmp | cut -f1 -d\ `" in ('0') echo No Matching Packages Found for command: install $1 exit -1 ;; ('1') LOCATION=`sed -e 's!/[^/]*\.tgz$!!' tmp/pkgstxt.tmp` FILE=`sed -e 's!^.*/!!g' tmp/pkgstxt.tmp` echo echo Ready to install package: \'$FILE\' echo to abort hit Ctrl-C, otherwise press Enter to proceed. read ;; ('*') MAXNUM=`wc -l tmp/pkgstxt.tmp | cut -f1 -d\ ` QUITLOOP= while [ $NUM -lt '1' ] && [ $NUM -gt $MAXNUM ] do echo echo More than one matching package! Please choose which you wish to install cat -n tmp/pkgstxt.tmp echo Please enter number 1-$MAXNUM followed by Enter echo Press Ctrl-C to Abort read NUM done FILE=`cat -n tmp/pkgstxt.tmp | grep $NUM'.*PACKAGE NAME:' | sed -e 's/^.*PACKAGE NAME: *//'` LOCATION=`grep -A4 $FILE PACKAGES.TXT | grep PACKAGE\ LOCATION | sed -e 's/^.*PACKAGE LOCATION: *//'` esac ;; ('1') FILE=`sed -e 's!^.*/!!g' tmp/pkgstxt.tmp` LOCATION=`grep $FILE'$' FILELIST.TXT | sed -e 's!^.*\./!\./!' | sed -e 's!/'$FILE'$!!'` echo echo Ready to install package: \'$FILE\' echo to abort hit Ctrl-C, otherwise press Enter to proceed. read ;; (*) MAXNUM=`wc -l tmp/pkgstxt.tmp | cut -f1 -d\ ` QUITLOOP= while [ ! $QUITLOOP ] do echo echo More than one matching package! Please choose which you wish to install cat -n tmp/pkgstxt.tmp echo Please enter number 1-$MAXNUM followed by Enter echo Press Ctrl-C to Abort read NUM if [ $NUM -ge '1' ] then if [ $NUM -le $MAXNUM ] then QUITLOOP=TRUE fi fi done FILE=`cat -n tmp/pkgstxt.tmp | grep $NUM'.*PACKAGE NAME:' | sed -e 's/^.*PACKAGE NAME: *//'` LOCATION=`grep -A4 $FILE PACKAGES.TXT | grep PACKAGE\ LOCATION | sed -e 's/^.*PACKAGE LOCATION: *//'` ;; esac mkdir -p ${LOCATION} amypkg_getfile ${LOCATION}/${FILE} installpkg ${LOCATION}/${FILE} echo ${LOCATION}/${FILE} >> tmp/packages.tmp esac shift done echo "Install Done" } amypkg_disclaimer() { echo "amypkg version ${VERSION}, Copyright (C) 2004 Rob Page" echo "amypkg comes with ABSOLUTELY NO WARRANTY;" echo "This is free software, and you are welcome to redistribute it" echo "under certain conditions. Type 'amypkg license' for details" } amypkg_usage() { echo "Usage: amypkg [options] [command] [parameters]" echo " amypkg version" echo "Valid Commands:" echo " update : Update core files" echo " install : Install packages in parameters" echo " upgrade : Upgrade amypkg to latest version" echo " finddeps : Find the dependencies for the given executable" echo " usage : Display this usage information" echo "Valid options:" echo " --force, -f : force all downloads" echo " -x : use the Extra Packages" } function amypkg_setopts { until [ -z "$1" ] do case "$1" in ('--force'|'-f' ) FORCE=TRUE ;; ('--useextra'|'-x') MIRROR=${MIRROREXTRA} AMYDIR=${AMYDIREXTRA} ;; ('-'*) echo Invalid Option: $1 exit -1 ;; esac shift done } amypkg_disclaimer if [ `whoami` != "root" ] then echo You must be root to run AmyPkg exit -1 fi amypkg_setopts $@ until [ $COMMAND ] do case $1 in ('') echo "No Command Entered" amypkg_usage exit -1 ;; ('-'*) ;; (*) COMMAND=$1 ;; esac shift done rm -rf ${AMYDIR}tmp/*.tmp mkdir -p ${AMYDIR} mkdir -p ${AMYDIR}tmp mkdir -p ${AMYDIR}pkg case "$COMMAND" in ('update') cd $AMYDIR amypkg_update ;; ('install') if [ -n "$1" ] then echo Switching to $AMYDIR cd $AMYDIR amypkg_install $* amypkg_pkgdeps else echo "But what do you want me to install?" fi ;; ('upgrade') amypkg_upgrade ;; ('finddeps') until [ -z "$1" ] do case "$1" in -*) ;; *) echo `pwd`/$1 >> ${AMYDIR}tmp/files.tmp ;; esac shift done echo $AMYDIR cd $AMYDIR amypkg_filedeps ;; ('license') cd $AMYDIR amypkg_getfile ./COPYING && less COPYING ;; ('usage') amypkg_usage exit 0 ;; (*) echo Invalid Argument: $COMMAND amypkg_usage exit -1 ;; esac