0

So what I'm intending to do here is to determine the latest stable version of TuxOnIce from http://tuxonice.net/downloads/all/ (currently tuxonice-for-linux-3.8.0-2013-02-24.patch.bz2).

What complicates things is that there's no "current" link, so we gotta follow the versioning, which is something like (these don't exist):

tuxonice-for-linux-3.8.0-2013-4-2.patch.bz2
tuxonice-for-linux-3.8-4-2013-4-16.patch.bz2
tuxonice-for-linux-3.8-11-2013-5-23.patch.bz2

The problem is they're gonna be in this order:

tuxonice-for-linux-3.8-11-2013-5-23.patch.bz2
tuxonice-for-linux-3.8-4-2013-4-16.patch.bz2
tuxonice-for-linux-3.8.0-2013-4-2.patch.bz2

My current implemetation (which is garbage) is this. I thought about using the dates but couldn't figure out how to do that either (/tmp/tuxonice is the index file):

_major=3.8 # Auto-generated
_TOI=$(grep ${_major}-1[0-9] /tmp/tuxonice | cut -d '"' -f2 | tail -1)
[ ! $_TOI ] && _TOI=$(grep ${_major}- /tmp/tuxonice | cut -d '"' -f2 | tail -1)
[ ! $_TOI ] && _TOI=$(grep ${_major}.0-2 /tmp/tuxonice | cut -d '"' -f2 | tail -1)

Thanks.

Det
  • 3,640
  • 5
  • 20
  • 27

2 Answers2

1

Use the webserver's feature to sort the index page by modification date in reverse order, grab the page using lynx -dump, get the first line matching the filename you are interested in and print the respective column. This gives you the absolute URL to the file, from there you can tweak the command to give you the exact output you want (filename, just the version string, ...).

$ lynx -dump 'http://tuxonice.net/downloads/all/?C=M&O=D'|awk '/^[[:space:]]*[[:digit:]]+\..+\/tuxonice-for-linux/ { print $2; exit }'
http://tuxonice.net/downloads/all/tuxonice-for-linux-3.8.0-2013-02-24.patch.bz2

Still not super-robust and will obviously break if the modification dates are not as expected, and you probably also want to tweak the regex a bit to be more specific.

Adrian Frühwirth
  • 42,970
  • 10
  • 60
  • 71
  • Had no idea you could sort the index by dates. So as long as there won't be any other releases for the same kernel a simple `grep ${_major} /tmp/tuxonice | cut -d '"' -f2 | head -1` would suffice (preceded by `curl -s "http://tuxonice.net/downloads/all/?C=M&O=D" -o /tmp/tuxonice`). – Det Apr 06 '13 at 16:17
  • 1
    Exactly! If you are curious, check [Apache's documentation of mod_autoindex](http://httpd.apache.org/docs/2.2/mod/mod_autoindex.html#query) for the possible sort and format arguments of the (Apache) index. Obviously this will only work as long as they stick to a webserver that supports sorting by URL parameter (not many do). – Adrian Frühwirth Apr 06 '13 at 17:30
  • Of course, `grep -m1` is even better than `| head -1`. Just thought of it now. – Det Sep 06 '13 at 08:50
0

This isn't a real answer, but I thought this "one-liner"[1] was pretty cool:

HTML=$(wget -qO- http://tuxonice.net/downloads/all/ | grep tuxonice); TIMESTAMP=$(echo "$HTML" | sed 's/.*\([0-9]\{2\}-[A-Za-z]\{3\}-[0-9]\{4\} [0-9]\{2\}:[0-9]\{2\}\).*/\1/' | while read line; do echo $(date --date "$line" +%s) $line; done | sort | tail -n 1 | cut -d' ' -f2-3); LINK=$(echo "$HTML" | grep "$TIMESTAMP" | sed 's/.*href=\"\(.*\)\".*/\1/'); echo "http://tuxonice.net/downloads/all/${LINK}"

Prints:

http://tuxonice.net/downloads/all/tuxonice-for-linux-3.8.0-2013-02-24.patch.bz2

This approach is really just a joke though. Obviously, there are better ways to do this, perhaps using a scripting language that supports XML parsing.

At the very least, maybe this will give you some insight on how you can use the date/time values of the files to select the "newest". But I'd caution using this (because upload dates may not coincide with version numbers), and suggest that your version number idea was probably a better idea, if you can somehow handle all of the various naming and version numbering schemes it looks like they've used.

[1] It's not a real one liner

jedwards
  • 29,432
  • 3
  • 65
  • 92