summary refs log tree commit diff
path: root/pkgs/common-updater/scripts/list-archive-two-level-versions
blob: ae29d533fc3be7faf3ea93d90aaeb11e804d05a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash

# lists all available versions listed for a package in a site (http)

archive="$1"  # archive url
pname="$2"  # package name
file="$3"  # file for writing debugging information

while (( $# > 0 )); do
    flag="$1"
    shift 1
    case "$flag" in
        --url=*)
            archive="${flag#*=}"
            ;;
        --pname=*)
            pname="${flag#*=}"
            ;;
        --file=*)
            version="${flag#*=}"
            ;;
        *)
            echo "$0: unknown option ‘${flag}’"
            exit 1
            ;;
    esac
done

if [ -z "$archive" ]; then
    echo "$scriptName: Missing archive url"
    exit 1
fi

# print a debugging message
if [ -n "$file" ]; then
    echo "# Listing versions for '$pname' at $archive" >> $file
fi

# list all major-minor versions from archive
tags1=$(curl -sS "$archive/")
tags1=$(echo "$tags1" | sed -rne 's,^<a href="([0-9]+\.[0-9]+)/">.*,\1,p')

# print available versions
for tag in $tags1; do
    tags2=$(curl -sS "$archive/$tag/")
    tags2=$(echo "$tags2" | sed -rne "s,^<a href=\"$pname-([0-9.]+)\\.[^0-9].*\">.*,\\1,p")
    echo "$tags2"
done