LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 06-30-2006, 12:42 PM   #1
dunric
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 411

Rep: Reputation: 39
Lightbulb Slackpkg extensions


In Slackware extra packages there is a handy updating tool called slackpkg.
I'm using it on my desktop boxes but I've missed some features so I coded them myself.
  • clean-cache - remove all downloaded package files not installed on system. It helps to keep minimal size of download cache after upgrades and uninstalls.
  • clean-repocache - similar to clean-cache but only removes package files not contained in updated repository list. It doesn't uninstalls packages like clean-system does. It helps to keep mirror of selected and actual packages for long runs. Handy for network sharing.
  • list - Simply display all available package names with their status (installed/uninstalled/installed but there is an update). I wonder why such basic feature is missing.
  • display help for non-root user - just an annoyance fix to display help screen for normal users also. They are able to use some non-intrusive commands like list, info and search.

For anybody interested in bellow's the patch to original files of version 2.05 (Slackware current)
Updates:
fixed missing concatenating space in PKGLIST in list function
updated for slackpkg 2.09 from Slackware 11RC4

Code:
--- usr/sbin/slackpkg.orig	2006-09-05 16:31:55.000000000 +0200
+++ usr/sbin/slackpkg	2006-09-05 16:32:16.000000000 +0200
@@ -175,6 +175,49 @@
 		showlist "$REMOVEPKG" $CMD
 		remove_pkg
 	;;
+	"clean-cache")
+		# removes all non-installed files from slackpkg cache
+		echo -e "Looking for files to remove. Please, wait...\n"
+		for PKGFILE in ${TEMP}/*.tgz; do
+			PKGFILE=${PKGFILE##*/}
+			if [ ! -f /var/log/packages/${PKGFILE%.tgz} ]; then
+				FILE="$FILE $PKGFILE"
+			fi
+		done
+		if [ -n "$FILE" ]; then
+			showlist "$FILE" remove 
+			for i in $SHOWLIST; do
+				echo -e "\nPackage: $i"
+				rm -f ${TEMP}/${i}
+				rm -f ${TEMP}/${i}.asc
+				echo -e "\tremoved."
+			done
+		else
+			echo -e "No redundant files for clean-cache found\n"
+		fi
+		POSTINST=OFF
+	;;
+	"clean-repocache")
+		# removes all outdated files from slackpkg repository cache
+		echo -e "Looking for files to remove. Please, wait...\n"
+		for PKGFILE in ${TEMP}/*.tgz; do
+			PKGFILE=${PKGFILE##*/}
+			if ! fgrep -q ${PKGFILE} ${CONF}/pkglist; then
+				FILE="$FILE $PKGFILE"
+			fi
+		done
+		if [ -n "$FILE" ]; then
+			for i in $SHOWLIST; do
+				echo -e "\nPackage: $i"
+				rm -f ${TEMP}/${i}
+				rm -f ${TEMP}/${i}.asc
+				echo -e "\tremoved."
+			done
+		else
+			echo -e "No outdated files for clean-repocache found\n"
+		fi
+		POSTINST=OFF
+	;;
 	"clean-system")
 		makelist $PATTERN
 		if [ -n "$REMOVEPKG" ]; then
@@ -248,6 +291,43 @@
 		
 		blacklist_pkg
 	;;
+	"list")
+		# List all package names
+		echo -e "List of available packages:\n"
+
+		for fn in `ls -1 /var/log/packages/`;do
+			fn=${fn##*/}
+			fn=${fn%.tgz}
+			INSTPKG="$INSTPKG $fn"
+		done
+
+		PKGLIST=""
+		for pkgprio in ${FIRST} ${SECOND} ${THIRD} ${FOURTH}; do
+			PKGLIST=${PKGLIST:+$PKGLIST }`grep "^./${pkgprio}/" ${CONF}/pkglist`
+		done
+		for PKGNAME in ${PKGLIST}; do
+			PKGNAME=${PKGNAME##*/}
+			PKGNAME=${PKGNAME%.tgz}
+			PKGNAME_RE='/('`expr ${PKGNAME} : '\(.*\)-.*-.*-.*$'`'-[^-]*-[^-]*-[^-]*).tgz'
+			if [[ ${INSTPKG} =~ ${PKGNAME} ]]; then
+				if [[ ${PKGLIST} =~ ${PKGNAME_RE} ]]; then
+					[ ${BASH_REMATCH[1]} == ${PKGNAME} ] && \
+						STATUS=" installed " || \
+						STATUS="  upgrade  "
+				else
+					# should never get here
+					STATUS="uninstalled"
+				fi
+			else
+				STATUS="uninstalled"
+			fi
+			echo -n "[$STATUS] "
+			[ "$STATUS" == "  upgrade  " ] && echo "$PKGNAME --> ${BASH_REMATCH[1]}" \
+			|| echo "$PKGNAME"
+		done
+
+		POSTINST=OFF
+	;;
 	"search")
 		# Search filelist.gz for possible matches
 		for i in $FIRST $SECOND $THIRD $FOURTH ; do
--- usr/libexec/slackpkg/core-functions.sh.orig	2006-09-05 16:31:46.000000000 +0200
+++ usr/libexec/slackpkg/core-functions.sh	2006-09-05 16:34:18.000000000 +0200
@@ -103,13 +103,16 @@
 
 	if [ "$#" = "1" ] && [ "$CMD" != "update" ] && \
 		[ "$CMD" != "upgrade-all" ] && [ "$CMD" != "install-new" ] && \
-		[ "$CMD" != "blacklist" ] && [ "$CMD" != "clean-system" ]; then
+		[ "$CMD" != "blacklist" ] && [ "$CMD" != "clean-system" ] && \
+		[ "$CMD" != "clean-cache" ] && [ "$CMD" != "clean-repocache" ] && \
+		[ "$CMD" != "list" ] ; then
 		usage
 	fi
 	
 	# Checking if the user have the permissions to install/upgrade/update
 	#                                                                    
-	if [ "`id -u`" != "0" ] && [ "$CMD" != "search" ] && [ "$CMD" != "info" ]; then
+	if [ "`id -u`" != "0" ] && [ "$1" != "search" ] && [ "$1" != "info" ] \
+		&& [ "$1" != "list" ] && [ -n "$1" ]; then
 		echo -e "\n\
 Only root can install, upgrade or remove packages.\n\
 Please, log as root or call your system administrator.\n"
@@ -203,6 +206,11 @@
 \tslackpkg reinstall package\tsame as install, but for packages 
 \t\t\t\t\talready installed
 \tslackpkg remove package\t\tremove installed packages
+\tslackpkg clean-cache\t\tremove all non-installed package files
+\t\t\t\t\tfrom cache to save disk space
+\tslackpkg clean-repocache\tremove all outdated package files
+\t\t\t\t\tfrom cache to save disk space
+\t\t\t\t\tand keep repository clean
 \tslackpkg clean-system\t\tremove all packages which are not 
 \t\t\t\t\tpresent in slackware distribution.
 \t\t\t\t\tGood to keep the house in order
@@ -220,6 +228,7 @@
 \tslackpkg download\t\tJust download (do not install) a package
 \tslackpkg info package\t\tShow package information 
 \t\t\t\t\t(works with only ONE package)
+\tslackpkg list\t\t\tList all available packages
 \tslackpkg search file\t\tSearch for a specific file in the
 \t\t\t\t\tentire package collection
 \nYou can see more information about slackpkg usage and some examples
@@ -510,8 +519,8 @@
 	getfile ChangeLog.txt $TMPDIR/ChangeLog.txt
 	if diff --brief $CONF/ChangeLog.txt $TMPDIR/ChangeLog.txt ; then
 		echo -e "\
-\n\t\tNo changes in ChangeLog.txt between your last update and now.\n\
-\t\tDo you really want to download all other files (y/N)? \c"
+\nNo changes in ChangeLog.txt between your last update and now.\n\
+Do you really want to download all other files (y/N)? \c"
 		read ANSWER
 		if [ "$ANSWER" != "Y" ] && [ "$ANSWER" != "y" ]; then
 			cleanup

Last edited by dunric; 09-05-2006 at 09:41 AM.
 
Old 07-01-2006, 11:59 AM   #2
cathectic
Member
 
Registered: Sep 2004
Location: UK, Europe
Distribution: Slackware64
Posts: 761

Rep: Reputation: 34
Have you considered posting this to the slackpkg authors?

http://slackpkg.sourceforge.net/ (see the bottom of the page for the authors addresses)
 
Old 07-01-2006, 01:57 PM   #3
dunric
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 411

Original Poster
Rep: Reputation: 39
I've already sent patch for 1.x version to Piter Punk. He thanked me for it but due to conservative way of slackpkg developement he didn't intend to include it in nearest releases.
Also I don't know if anybody else will find these new features useful and if this little simple code will work in other environments (I guess it will).
If I have to give an example how it's useful to me, I would mention an automation of distributed upgrades. There is a dedicated machine sharing through NFS downloaded packages repository (/var/cache/packages by default) to other computers in LAN. In night cron jobs first every computer updates to dedicated machine list of their currently installed packages, then this machine will browse all this lists and download with slackpkg new packages for every machine once. Then it'll run slackpkg clean-repocache to remove obsolete packages. Later all computers will run upgradepkg on shared repository to become up-to-date. This way it doesn't matter if updating 1 or 1000 computers.
The main difference to rsync solution is significant save of network bandwidth and disk space - you download and keep required packages only. It's even more noticeable when updating from current branch.
It may sound difficult but it's really very simple in use (up to 3 rows shell scripts for each case).

Last edited by dunric; 07-01-2006 at 02:03 PM.
 
Old 07-01-2006, 06:18 PM   #4
theoffset
Member
 
Registered: Aug 2005
Location: Guadalajara, Jal, Mexico
Distribution: Slackware Linux
Posts: 211

Rep: Reputation: 30
The "list" feature is definitly a must have. I can't believe how Piter Punk didn't think of that before. (I used to use "slackpkg search ." to list all the packages)

I just tested your patch and it works wonders. Thank you, man!
 
Old 07-02-2006, 02:37 AM   #5
dunric
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 411

Original Poster
Rep: Reputation: 39
You are welcome
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
slackpkg problems dive Slackware 3 11-16-2005 04:08 PM
Warning! Slackpkg walkingbeard Slackware 6 09-18-2005 09:17 PM
slackpkg question ralvy Slackware 2 11-19-2004 04:48 PM
Slackpkg vs. Swaret. mdarby Slackware 3 11-18-2004 10:10 PM
slackpkg upgrade _mu_ Slackware 9 01-29-2004 08:28 PM


All times are GMT -5. The time now is 10:37 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration