1

I'm trying to put a "function" inside of a script to install the latest version of "TeamSpeak3" Client and make all configurations.

My problem is I don't know how to make a function to test the version number part, "number.number.number.number". The numbers range from 0 to 99.

For example, I'm given a variable that has the value within a URL:

URL=http://dl.4players.de/ts/releases/$version/TeamSpeak3-Client-linux_$arch-$version.run

Here the variable, $Version, the latest is 3.0.16. The current latest URL is:

http://dl.4players.de/ts/releases/3.0.16/TeamSpeak3-Client-linux_x86-3.0.16.run

But in the future when I use the script, I want it to determine automatically the latest version, checking the numbers within the URL.

For "archs" I have this code:

# Determining the system arch
arch=$(uname -m)
case "$arch" in
x86)    arch="x86"  ;;
i?86)   arch="x86"  ;;
amd64)  arch="amd64"    ;;
x86_64) arch="x86_64"   ;;
* ) echo "Your Arch '$arch' -> Its not supported."  ;;
esac

Maybe an array or something like that? Can someone help me with this idea?

4 Answers 4

2

This is why you shouldn't use pure shell scripting. Instead, is better to use something that is meant for the task, like uscan (which is a perl script), instead of doing it yourself:

$ uscan --watchfile teamspeak --package TeamSpeak3 --no-download --verbose --upstream-version 3.0.16
-- In test, processing watchfile line:
   http://dl.4players.de/ts/releases/([\d\.]+)/TeamSpeak3-Client-linux_amd64-([\d\.]+).run
-- Found the following matching hrefs:
     TeamSpeak3-Client-linux_amd64-3.0.16.run (3.0.16)
Newest version on remote site is 3.0.16, local version is 3.0.16
 => Package is up to date

the content of the teamspeak file is:

version=2
http://dl.4players.de/ts/releases/([\d\.]+)/TeamSpeak3-Client-linux_amd64-([\d\.]+).run

In the example above, I am manually setting the version of the latest version, if you want to, you can replace the version from TeamSpeak if they support the --version parameter, ie.:

$ uscan --watchfile teamspeak --package TeamSpeak3 --no-download --verbose --upstream-version $(teamspeak --version)

it should output a numeric value. It also possible to automagically download the latest run file, just remove the --no-download option. This has the advantage that it's very, very flexible, you don't need to modify anything when a new version goes out, nor worry about it breaking.

The only real limitation for your use case is that uscan doesn't support setting architectures, but such limitation is trivially overcome if you just create another file, say teamspeak-i386, and tweak the url like this:

version=2
http://dl.4players.de/ts/releases/([\d\.]+)/TeamSpeak3-Client-linux_x86-([\d\.]+).run
2
1

I'm not sure what it is you're asking exactly. Assuming you mean you want to find the latest version listed in http://dl.4players.de/ts/releases/, you can do this:

curl -s http://dl.4players.de/ts/releases/ | \
  grep -Po '(?<=href=")[0-9]+(\.[0-9]+){2,3}(?=/")' | \
  sort -Vr | head -1

Example output:

3.0.16

Explanation:

  • Note that the directory listing HTML follows a fairly regular pattern:

    <tr><td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td><td><a href="3.0.0/">3.0.0/</a></td><td align="right">10-Aug-2011 16:57  </td><td align="right">  - </td><td>&nbsp;</td></tr>
    <tr><td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td><td><a href="3.0.1/">3.0.1/</a></td><td align="right">17-Nov-2011 08:43  </td><td align="right">  - </td><td>&nbsp;</td></tr>
    

    All the version folder links are created with href="X.Y.Z[.A]/", A, X, Y and Z all being numbers.

  • So we can grep for this pattern: (?<=href=")[0-9]+(\.[0-9]+){2,3}(?=/"). I have used Perl regexes (-P) for lookaheads and lookbehinds (so that the string is surrounded by href=" and /", but these two aren't part of the actual match). The regex [0-9]+(\.[0-9]+){2,3} means:

    1. One or more digits: [0-9]+, followed by,
    2. A group consisting of a period and one or more digits ((\.[0-9]+)), repeated two or three times ({2,3}).
  • Then we do version sort and get the top result.


Ordinarily, one should not use Regular expressions to parse HTML. However, I think on occasion an exception can be made.

0

I'd take the URLs and parse the version number from it:

$ echo 'http://dl.4players.de/ts/releases/3.0.16/TeamSpeak3-Client-linux_x86-3.0.16.run' \
    | awk -F'_x86-' '{print $2}' | sed 's/.run//'
3.0.16

With the version parsed out you can then use sort to determine which version is newer. Specifically with sort, using its -V switch, which newer versions have.

$ echo -e '3.0.16\n4.0.2\n1.2.3\n5.6.7\n3.0.17' | sort -V | tail -1
5.6.7

This is just a rough approach, but should show you how you can easily achieve what you're looking for.

NOTE: My sort version.

$ sort --version
sort (GNU coreutils) 8.21
0

well with curl i can solve the Quake2 Lastest Version

Q2VA=$(curl -s http://deponie.yamagi.org/quake2/ | grep -Po "quake2-[0-9].[0-9][0-9].tar.xz" | sort -Vr | head -1)

But right now i am trying with LibreOffice, using the follow command :

curl -s http://www.libreoffice.org/download/download/ | grep -Po "[0-9].[0-9].[0-9]" | sort -Vr

Output :

93276
90701
89681
72663
50227
43905
42382
42382
26302
25220
20474
18000
14907
14764
14001
13964
13903
13902
13898
13890
13884
12887
12774
07992
700,9
100,3
6/5.4
6/5.3
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.4.0
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.5
5.3.4
5.3.4
5.2.7
5.2.7
2.6.2
1.1.0
0,400
0,300
0A500
0A500

How i can indicate just the first vale type "Number.Number.Number" for store in a variable ? in this case 5.4.0 the first, in the row 29, but if i use some like sed, this can change in the future, is not secure ever the row 29 ever had the lastest version.

Desire Output:

5.4.0

Someone can give some idea to solve it ?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .