[opensuse] bash gurus - Best way to get latest version from $(ls -t fglrx*.rpm) ?
Listmates, Every time a new fglrx driver comes out, I end up dorking with my script for automating the install from the ATi binary to try and improve it. Tonight is no different. The task: "I may have several versions of the fglrx rpm in the directory where the script is running or in /usr/src/packages/RPMS/.. and I want the script to automatically select the latest one to install. Such as (names for testing purposes only): -rw-r--r-- 1 david dcr 21355823 2008-08-22 21:08 fglrx64_7_1_0_SUSE110-8.522-1.x86_64.rpm -rw-r--r-- 1 david dcr 0 2008-08-22 23:47 fglrx64_7_1_0_SUSE110-8.523-1.x86_65.rpm -rw-r--r-- 1 david dcr 0 2008-08-22 23:47 fglrx64_7_1_0_SUSE110-8.524-1.x86_66.rpm Specifically what I need help solving is "what is the best way to select the newest fglrx rpm from the present directory to install?" I can do it 3 different ways, but all rely on file creation time (ls -t) and seem horribly inefficient. Using the version number would seem to be a better way. So far I have: (1) Grab the first filename from $(ls -t fglrx*.rpm) with a for loop: mcount=1 for i in $(ls -t fglrx*.rpm); do if [ "$mcount" -eq "1" ]; then FGLRX_RPM="$i" echo -e "\n\t\tSelecting: $FGLRX_RPM\n" let "mcount+=1" fi done This seems like a giant waste of a loop. (2) Grab it using sed to delete everything after the first whitespace: FGLRX_RPM=$(echo $(ls -t fglrx*.rpm) | sed -e 's/\s.*//' -e 's/\s*$//') This is a cludge and I want to eliminate the pipe and the sed call (3) Dump the dir list into an array and grab the first element: RPM_ARRAY=( $(ls -t fglrx*.rpm) ) FGLRX_RPM=${RPM_ARRAY[0]} This is better, but it still seems clumsy. There has to be a better way to do this. How can I pull the version information from the filename itself and take the highest version regardless of the file time information? I can't figure out how to parse the version fields in the filename after I have the directory list of fglrx files without adding more sed calls and more loop. I'd pull the version info like this: fglrx64_7_1_0_SUSE110-8.522-1.x86_64.rpm ^^^^^ out of what is returned by $(ls -t fglrx*.rpm) and use that to select the file? Is it a reasonable approach or will it be more inefficient? What says the brain trust? -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Saturday 23 August 2008 08:07:15 David C. Rankin wrote:
There has to be a better way to do this. How can I pull the version information from the filename itself and take the highest version regardless of the file time information? I can't figure out how to parse the version fields in the filename after I have the directory list of fglrx files without adding more sed calls and more loop. I'd pull the version info like this:
fglrx64_7_1_0_SUSE110-8.522-1.x86_64.rpm ^^^^^ out of what is returned by $(ls -t fglrx*.rpm) and use that to select the file? Is it a reasonable approach or will it be more inefficient? What says the brain trust?
Do answer your question, how about ls fglrx*|tail -1 since ls does its own sorting. However, we have zypper, and then you could do something like zypper sa -t plaindir /path/to/rpms repoalias and then zypper would always keep track of what the latest available version is, so when you do zypper in fglrx64_7_1_0 it would get the correct version Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 22 August 2008 23:07, David C. Rankin wrote:
Listmates,
Every time a new fglrx driver comes out, I end up dorking with my script for automating the install from the ATi binary to try and improve it. Tonight is no different.
The task: "I may have several versions of the fglrx rpm in the directory where the script is running or in /usr/src/packages/RPMS/.. and I want the script to automatically select the latest one to install. Such as (names for testing purposes only):
-rw-r--r-- 1 david dcr 21355823 2008-08-22 21:08 fglrx64_7_1_0_SUSE110-8.522-1.x86_64.rpm -rw-r--r-- 1 david dcr 0 2008-08-22 23:47 fglrx64_7_1_0_SUSE110-8.523-1.x86_65.rpm -rw-r--r-- 1 david dcr 0 2008-08-22 23:47 fglrx64_7_1_0_SUSE110-8.524-1.x86_66.rpm
Specifically what I need help solving is "what is the best way to select the newest fglrx rpm from the present directory to install?" I can do it 3 different ways, but all rely on file creation time (ls -t) and seem horribly inefficient. Using the version number would seem to be a better way. So far I have:
In addition to the usual and default glob pattern matching, there is full regular expression matching in BASH. Look in the manual page for a double left bracket, '[['. If you search in "less" (used automatically usually when you run "man"), you'll need to escape them both when used as search patters: "\[\[". Next, you should (in general) be aware of the variable expansion syntax that can apply substitutions to the value while expanding the variable: ${varName#leftStripMinimalPattern} ${varName##leftStripMaximalPattern} ${varName%rightStripMinimalPattern} ${varName%rightStripMaximalPattern} ${varName/replacePattern/firstMatchReplacement} ${varName/replacePattern//allMatchesReplacement} Again, check the manual page for the details. This is enough to detect and dissect the names you want. The "rpm" command can present arbitrary and detailed information about an RPM driven by a format argument of your specification. This is the definitive information about the RPM, of course, so it would be the best thing on which to base a selection. Lastly, when you're dealing with real date strings, they can be decoded by the "date" command and rendered into a linear "seconds since the epoch" date encoding, which allows easy comparison.
...
What says the brain trust?
I don't trust my brain, why would you?
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Saturday 23 August 2008 07:15, Randall R Schulz wrote:
...
Next, you should (in general) be aware of the variable expansion syntax that can apply substitutions to the value while expanding the variable:
${varName#leftStripMinimalPattern} ${varName##leftStripMaximalPattern} ${varName%rightStripMinimalPattern}
Oops. This:
${varName%rightStripMaximalPattern}
Should be this: ${varName%%rightStripMaximalPattern}
...
RRS -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
----- Original Message -----
From: "Randall R Schulz"
On Saturday 23 August 2008 07:15, Randall R Schulz wrote:
...
Next, you should (in general) be aware of the variable expansion syntax that can apply substitutions to the value while expanding the variable:
${varName#leftStripMinimalPattern} ${varName##leftStripMaximalPattern} ${varName%rightStripMinimalPattern}
Oops.
This:
${varName%rightStripMaximalPattern}
Should be this: ${varName%%rightStripMaximalPattern}
The all-matches sed-alike was off too:
${varName/replacePattern//allMatchesReplacement}
rather: ${variable//search/replace} all matches -- Brian K. White brian@aljex.com http://www.myspace.com/KEYofR +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (4)
-
Anders Johansson
-
Brian K. White
-
David C. Rankin
-
Randall R Schulz