LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
  Search this Thread
Old 07-31-2006, 03:42 AM   #16
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235

Ok the script's now fixed. Please optimize the script if you can.

Code:
#!/bin/bash

# freshpick.sh (c) 2006 konsolebox
# chooses the newest versions of packages from a list
# version: 1.1
# license: GPL

DEBUG=

debug() { [ "$DEBUG" ] && echo "$@"; }
error() { echo "error: $@"; exit; }

usege() {
	echo "usage: freshpick.sh list"
	exit
}

compareversions() {
	for ((p=1; p<=10; p++)); do
		a=$(echo "$1" | cut -f "$p" -d '.')
		b=$(echo "$2" | cut -f "$p" -d '.')
		debug "comparing $a to $b"

		if [ -z "$a" ] && [ -z "$b" ]; then
			debug "compareversions exit no 1"
			return 1
		elif [ -z "$b" ]; then
			debug "compareversions exit no 2"
			return 1
		elif [ -z "$a" ]; then
			debug "compareversions exit no 3"
			return 0
		fi

		if [[ b -gt a ]]; then
			debug "compareversions exit no 4"
			return 0
		elif [[ b -lt a ]]; then
			debug "compareversions exit no 5"
			return 1
		fi

		# a still equals to b so continue
	done

	error "versions $a and $b too long"
}

finalize() {
	# you an modify this function if you like
	echo "$@"
}

#### start ####

FILENAME="$1"
if [ -z "$FILENAME" ]; then
	usege
elif [ ! -e "$FILENAME" ]; then
	error "$FILENAME" not found
fi

# process the first line

fn=$(cat "${FILENAME}" | sort | sed -n 1p)
CURRENTPACKAGE="${fn/-*}"
NEWESTVERSION="$(echo "$fn" | sed s/".*\-\([0-9.]\+[0-9]\).*"/"\1"/)"	# better than 'grep -o ..'
CURRENTSUFFIX="$(echo "$fn" | sed s/".*${NEWESTVERSION}."//)"
debug [ "$CURRENTPACKAGE" "$NEWESTVERSION" ]

# main loop

for fn in $(cat "${FILENAME}" | sort | sed -n 1\!p); do
	NEWPACKAGE="${fn/-*}"
	NEWVERSION="$(echo "$fn" | sed s/".*\-\([0-9.]\+[0-9]\).*"/"\1"/)"
	debug [ "$NEWPACKAGE" "$NEWVERSION" ]
	if [ "${NEWPACKAGE}" != "${CURRENTPACKAGE}" ]; then
		finalize "${CURRENTPACKAGE}-${NEWESTVERSION}.${CURRENTSUFFIX}"
		CURRENTPACKAGE="${NEWPACKAGE}"
		NEWESTVERSION="${NEWVERSION}"
		CURRENTSUFFIX="$(echo "$fn" | sed s/".*${NEWVERSION}."//)"
	else
		compareversions "${NEWESTVERSION}" "${NEWVERSION}" && \
			NEWESTVERSION="${NEWVERSION}"
	fi
done

finalize "${CURRENTPACKAGE}-${NEWESTVERSION}.${CURRENTSUFFIX}"
Regards,
konsolebox
 
Old 07-31-2006, 02:30 PM   #17
jong357
Senior Member
 
Registered: May 2003
Location: Columbus, OH
Distribution: DIYSlackware
Posts: 1,914

Original Poster
Rep: Reputation: 52
yep, that does the trick as far as I can tell. Thanks!
 
Old 07-31-2006, 07:58 PM   #18
jong357
Senior Member
 
Registered: May 2003
Location: Columbus, OH
Distribution: DIYSlackware
Posts: 1,914

Original Poster
Rep: Reputation: 52
Quote:
Originally Posted by spirit receiver
Read a line from buildorder.txt and grep pkglst.txt for the result.
DOH!!! Man... Don't know whats wrong with me lately. You said it in english, that's why...

while read line
do
grep "^$line" pkglst.txt
done <buildorder.txt

Thanks again guys for your help. I have the mechanics completely done now.
 
Old 08-01-2006, 04:38 AM   #19
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
And by 'feed the "while read <&3" loop with the lines of buildorder.txt' I meant to replace
Code:
exec 3< <( sed  -n 's/-[[:digit:].]\+tar\.bz2$//p' $DATAFILE | sort | uniq )
with
Code:
exec 3< buildorder.txt
as this is 'fed' into the loop's read command. Sorry for the confusion.
 
Old 08-01-2006, 02:55 PM   #20
jong357
Senior Member
 
Registered: May 2003
Location: Columbus, OH
Distribution: DIYSlackware
Posts: 1,914

Original Poster
Rep: Reputation: 52
I'm sorta tiring of this thread as are you guys, but I thought I'd let you know spirit reciever, your script really mutilates this list, whereas Konsolbox's script processes it correctly... There are 9 missing packages with dupicates of others via your output...
Code:
libAppleWM-1.0.0.tar.bz2
libFS-1.0.0.tar.bz2
libICE-1.0.0.tar.bz2
libICE-1.0.1.tar.bz2
libSM-1.0.0.tar.bz2
libSM-1.0.1.tar.bz2
libWindowsWM-1.0.0.tar.bz2
libX11-1.0.0.tar.bz2
libX11-1.0.1.tar.bz2
libX11-1.0.2.tar.bz2
libX11-1.0.3.tar.bz2
libXScrnSaver-1.0.1.tar.bz2
libXScrnSaver-1.1.0.tar.bz2
libXTrap-1.0.0.tar.bz2
libXau-1.0.0.tar.bz2
libXau-1.0.1.tar.bz2
libXau-1.0.2.tar.bz2
libXaw-1.0.1.tar.bz2
libXaw-1.0.2.tar.bz2
libXcomposite-0.2.2.2.tar.bz2
libXcomposite-0.3.tar.bz2
libXcursor-1.1.5.2.tar.bz2
libXcursor-1.1.6.tar.bz2
libXcursor-1.1.7.tar.bz2
libXdamage-1.0.2.2.tar.bz2
libXdamage-1.0.3.tar.bz2
libXdmcp-1.0.0.tar.bz2
libXdmcp-1.0.1.tar.bz2
libXevie-1.0.0.tar.bz2
libXevie-1.0.1.tar.bz2
libXext-1.0.0.tar.bz2
libXext-1.0.1.tar.bz2
libXfixes-3.0.1.2.tar.bz2
libXfixes-4.0.1.tar.bz2
libXfixes-4.0.tar.bz2
libXfont-1.0.0.tar.bz2
libXfont-1.1.0.tar.bz2
libXfont-1.2.0.tar.bz2
libXfontcache-1.0.1.tar.bz2
libXfontcache-1.0.2.tar.bz2
libXft-2.1.8.2.tar.bz2
libXft-2.1.9.tar.bz2
libXft-2.1.10.tar.bz2
libXi-1.0.0.tar.bz2
libXi-1.0.1.tar.bz2
libXinerama-1.0.1.tar.bz2
libXmu-1.0.0.tar.bz2
libXmu-1.0.1.tar.bz2
libXmu-1.0.2.tar.bz2
libXp-1.0.0.tar.bz2
libXpm-3.5.4.2.tar.bz2
libXpm-3.5.5.tar.bz2
libXprintAppUtil-1.0.1.tar.bz2
libXprintUtil-1.0.1.tar.bz2
libXrandr-1.1.0.2.tar.bz2
libXrandr-1.1.1.tar.bz2
libXrender-0.9.0.2.tar.bz2
libXrender-0.9.1.tar.bz2
libXres-1.0.0.tar.bz2
libXres-1.0.1.tar.bz2
libXt-1.0.0.tar.bz2
libXt-1.0.1.tar.bz2
libXt-1.0.2.tar.bz2
libXtst-1.0.1.tar.bz2
libXv-1.0.1.tar.bz2
libXvMC-1.0.1.tar.bz2
libXvMC-1.0.2.tar.bz2
libXxf86dga-1.0.0.tar.bz2
libXxf86dga-1.0.1.tar.bz2
libXxf86misc-1.0.0.tar.bz2
libXxf86misc-1.0.1.tar.bz2
libXxf86vm-1.0.0.tar.bz2
libXxf86vm-1.0.1.tar.bz2
libdmx-1.0.1.tar.bz2
libdmx-1.0.2.tar.bz2
libfontenc-1.0.1.tar.bz2
libfontenc-1.0.2.tar.bz2
liblbxutil-1.0.0.tar.bz2
liblbxutil-1.0.1.tar.bz2
liboldX-1.0.1.tar.bz2
libxkbfile-1.0.1.tar.bz2
libxkbfile-1.0.2.tar.bz2
libxkbfile-1.0.3.tar.bz2
libxkbui-1.0.1.tar.bz2
libxkbui-1.0.2.tar.bz2
xtrans-1.0.0.tar.bz2
xtrans-1.0.1.tar.bz2
Everyone starting to see why I want to autoresolve $VERSION and fetching? That's only one list out of 8.... Were talking hundreds of packages. Pretty annoying having to figure out what needs updating after the next Xorg release... They do use 7.0 as a static base and then 7.{1-x} will be updates only but that's still gonna take time...
 
Old 08-01-2006, 03:46 PM   #21
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
You're right, I was too sloppy with some pattern matching there, which caused problems if a package name started with another package name, as in libXpm. The next to last line should be replaced with
Code:
grep "^$REPLY-[[:digit:].]\+tar\.bz2$" $DATAFILE | grab_latest
Edit: But I couldn't find 9 missing packages, there were libXp-1.0.0.tar.bz2 and libXv-1.0.1.tar.bz2 missing, with the corrsponding duplicates of libXpm-3.5.5.tar.bz2 and libXvMC-1.0.2.tar.bz2.

Last edited by spirit receiver; 08-01-2006 at 04:12 PM.
 
Old 08-01-2006, 04:19 PM   #22
jong357
Senior Member
 
Registered: May 2003
Location: Columbus, OH
Distribution: DIYSlackware
Posts: 1,914

Original Poster
Rep: Reputation: 52
you know, My reorder grep function is playing havoc with me as well . It's throwing packages that should be up top down towards the bottom and possibly listing them twice. I'm getting irritated..

Is it really worth it I ask? I've already spent alot time on this, not quiting now... If there's one thing I hate, it's wasted time..

Thanks for the fix on your script.

EDIT: Yea, I think I had 4 libXpm-3.5.5 and some other crap. My reorder is defenately going awry..

Last edited by jong357; 08-01-2006 at 04:28 PM.
 
Old 08-01-2006, 10:46 PM   #23
jong357
Senior Member
 
Registered: May 2003
Location: Columbus, OH
Distribution: DIYSlackware
Posts: 1,914

Original Poster
Rep: Reputation: 52
Quote:
Originally Posted by spirit receiver
And by 'feed the "while read <&3" loop with the lines of buildorder.txt' I meant to replace
Code:
exec 3< <( sed  -n 's/-[[:digit:].]\+tar\.bz2$//p' $DATAFILE | sort | uniq )
with
Code:
exec 3< buildorder.txt
as this is 'fed' into the loop's read command. Sorry for the confusion.
That does work great. Thanks for all the time you've spent helping me... I really do appreciate it. Really...
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 01:34 AM
About sed orgazmo Programming 10 05-19-2005 10:21 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-04-2005 12:00 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:08 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration