summarylogtreecommitdiffstats
path: root/checkupdate.sh
blob: cdb6254a5c09342c612b4f6d54b161968c64a7ef (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
#!/bin/bash

# To get changes made somewhere else
git pull

maxVersionDifference=20

scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$scriptdir"

#if [[ -f STOP_AUTOMATIC_UPDATE ]]; then
#  >&2 echo "Automatic updates are disabled via STOP_AUTOMATIC_UPDATE."
#  exit 1
#fi

upstreamVersion="$(curl -s "https://josm.openstreetmap.de/latest")"

if [[ ! $upstreamVersion =~ ^[0-9]{5}$ ]]; then
  >&2 echo "Invalid upstream version $upstreamVersion."
  exit 1
fi

pkgbuildVersion="$(grep -Po '(?<=pkgver=)\d+' PKGBUILD)"

if [[ ! $pkgbuildVersion =~ ^[0-9]{5}$ ]]; then
  >&2 echo "Invalid PKGBUILD version $pkgbuildVersion."
  exit 1
fi

#if [[ $((upstreamVersion - pkgbuildVersion)) -gt $maxVersionDifference ]]; then
#  >&2 echo "Update would exceed maxVersionDifference of $maxVersionDifference ($pkgbuildVersion->$upstreamVersion). Disabling further automatic updates."
#  touch STOP_AUTOMATIC_UPDATE
#  exit 1
#fi

if [[ $upstreamVersion -gt $pkgbuildVersion ]]; then
  echo "Found new upstream version $upstreamVersion (was $pkgbuildVersion)."

  sed -r -i -e 's/(pkgver=)[0-9]+/\1'$upstreamVersion'/' PKGBUILD
  sed -r -i -e 's/(pkgrel=)[0-9]+/\11/' PKGBUILD

  sed -r -i -e 's/(pkgver = )[0-9]+/\1'$upstreamVersion'/' .SRCINFO
  sed -r -i -e 's/(pkgrel = )[0-9]+/\11/' .SRCINFO
  sed -r -i -e 's/(josm=)[0-9]+/\1'$upstreamVersion'/' .SRCINFO
  sed -r -i -e 's/(snapshot-)[0-9]+/\1'$upstreamVersion'/g' .SRCINFO
  sed -r -i -e 's/(trunk#revision=)[0-9]+/\1'$upstreamVersion'/' .SRCINFO

  git commit --no-signoff PKGBUILD .SRCINFO -m "Automatic update ($pkgbuildVersion->$upstreamVersion)"
  git push
else
  echo "No new upstream version found (upstream $upstreamVersion, PKGBUILD $pkgbuildVersion)."
fi