summaryrefslogtreecommitdiff
path: root/watch-versions
blob: 3fd9f1166305c01972168e64f8b4af632511dbcf (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh

if [ "x$1" = 'x-m' ]; then
  machine_readable=true
  shift
else
  machine_readable=false
fi

if [ $# -eq 0 ]; then
  git -C "$(dirname "$0")/../packages" pull --ff-only >/dev/null 2>&1
#  curl -Ss 'https://packages.archlinux32.org/?uses_upstream=Does+Not+Use+Upstream&fuzzy&tsv' 
  curl -Ss 'http://packages.archlinux32.local/?uses_upstream=Does+Not+Use+Upstream&fuzzy&tsv' | \
    {
      read -r headers
      pkgbase_column=$(
        printf '%s\n' "${headers}" | \
          tr '\t' '\n' | \
          grep -nxF 'pkgbase' | \
          cut -d: -f1
      )
      cut -f${pkgbase_column}
    } | \
    sort -u | \
    parallel -j0 "$0"
  exit $?
elif [ $# -gt 1 ]; then
  >&2 echo 'I need zero or one argument.'
  exit 1
fi

pkgbase="$1"
unset pkgver
unset epoch

oldver=$(
  git -C "$(dirname "$0")/../packages" remote | \
    while read -r remote; do
      eval "$(
        git -C "$(dirname "$0")/../packages" archive "${remote}/master" -- 2>/dev/null | \
          tar -Ox --wildcards '*/'"${pkgbase}"'/PKGBUILD' 2>/dev/null | \
          sed -n '
            /^epoch=/p
            /^pkgver=/p
          '
      )"
      printf '%s %s\n' "${epoch-0}" "${pkgver}"
    done | \
    sort -k1n,1 -k2V,2 | \
    tail -n1 | \
    sed '
      s/^0\s\+//
      s/\s\+/:/
    '
)

case "${pkgbase}" in
  'linux-pae')
    url=$(
      curl -LSs 'https://www.kernel.org/pub/linux/kernel' \
        | sed '
          s,^<a href="\(v[0-9]\+\.x/\)">\1</a>.*$,\1,
          t
          d
        ' \
        | sort -Vr \
        | while read -r sub; do
          if curl -ILs "https://www.kernel.org/pub/linux/kernel/${sub}/sha256sums.asc" \
            | grep -qFw 'HTTP/1.1 200 OK'; then
            echo "https://www.kernel.org/pub/linux/kernel/${sub}"
            break
          fi
        done
    )
    regex='<a href="linux-\([0-9.]\+\)\.tar\.sign">'
  ;;
  'pcmciautils')
    url='https://kernel.org/pub/linux/utils/kernel/pcmcia/'
    regex='<a href="pcmciautils-\([0-9.]\+\)\.tar\.sign">'
  ;;
  'archlinux32-keyring'|'archlinux32-keyring-transition')
    url='https://sources.archlinux32.org/sources/'
    regex='<a href="archlinux32-keyring-v\([0-9.]\+\)\.tar\.gz">'
  ;;
  'python-pip-bootstrap')
    url='https://bootstrap.pypa.io/get-pip.py'
    regex=' entire copy of pip (version \([0-9.]\+\))\.'
  ;;
  'python-setuptools-bootstrap')
    url='https://github.com/pypa/setuptools/releases'
    regex='<a href="\/pypa\/setuptools\/releases\/tag\/v\([0-9.]\+\)">'
  ;;
  *'-dummy')
    rem_pkgbase="${pkgbase%-dummy}"
    rem_pkgbase="${rem_pkgbase//+/%2B}"
    url='https://www.archlinux.org/packages/?q='"${rem_pkgbase}"
    range='/^<div id="exact-matches"/,/^<\/div>/'
    regex='<td>\([^-<>]\+\)-[0-9]\+<\/td>'
    regex_b='<td><span class="flagged">\([^-<>]\+\)-[0-9]\+<\/span><\/td>'
  ;;
  *)
    >&2 printf 'Checking the version of package "%s" is not yet implemented!\n' "${pkgbase}"
    exit 1
  ;;
esac

if [ -z "${regex_b}" ]; then
  regex_b="${regex}"
fi

newver=$(
  curl -LSs "${url}" | \
    sed '
      '"${range}"' s/^.*'"${regex}"'.*$/\1/
      t
      '"${range}"' s/^.*'"${regex_b}"'.*$/\1/
      t
      d
    ' | \
    sort -V | \
    tail -n1
)

if [ "${newver}" != "${oldver}" ]; then
  if ${machine_readable}; then
    printf '%s="%s";\n' \
      'pkgbase' "${pkgbase}" \
      'newver' "${newver}" \
      'oldver' "${oldver}"
  else
    printf '%s: %s vs. %s\n' \
      "${pkgbase}" \
      "${newver}" \
      "${oldver}"
  fi
fi