summarylogtreecommitdiffstats
path: root/update.sh
blob: 743911496b9c4c1eee4e97e151558b1eb543a1b0 (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
#!/usr/bin/env bash
set -euo pipefail

discordUrl="$(curl -o /dev/null -LsI -w '%{url_effective}' 'https://discord.com/api/download?platform=linux&format=tar.gz')"
latestDiscordVersion="$(echo "$discordUrl" | pcregrep -o1 '/([0-9]*\.[0-9]*\.[0-9]*)/')"
currentDiscordVersion="$(pcregrep -o1 '^pkgver=([^+]+)' PKGBUILD)"

latestElectronVersion="$(pacman -qSs electron | pcregrep -o1 '^electron([0-9]{2})' | sort -V | tail -n1)"
currentElectronVersion="$(pcregrep -o1 '^_electron=([0-9]+)' PKGBUILD)"
# TODO: Actually do something with the electron version

if [[ "$currentDiscordVersion" = "$latestDiscordVersion" && "$currentElectronVersion" = "$latestElectronVersion" ]]; then
  echo " [*] discord and electron versions are up to date"
  echo "      discord: ${currentDiscordVersion}"
  echo "      electron: ${currentElectronVersion}"
  exit 0
fi

if [[ "$currentDiscordVersion" != "$latestDiscordVersion" ]]; then
  echo " [*] Updating discord version ${currentDiscordVersion} -> ${latestDiscordVersion}"

  # Update pkgver
  pushd "src/openasar"
  pkgver=$(printf "%s+%s.%s" "$latestDiscordVersion" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)")
  popd
  sed -i "s/^pkgver=.*/pkgver=$pkgver/" PKGBUILD

  # Update checksums
  updpkgsums

  # Update .SRCINFO
  makepkg --printsrcinfo > .SRCINFO

  git add PKGBUILD .SRCINFO
  git commit -m "chore!: update to discord ${latestDiscordVersion}"
fi

if [[ "$currentElectronVersion" != "$latestElectronVersion" ]]; then
  echo " [*] Updating electron version ${currentElectronVersion} -> ${latestElectronVersion}"
  sed -i "s/^_electron=.*/_electron=$latestElectronVersion/" PKGBUILD

  # Update .SRCINFO
  makepkg --printsrcinfo > .SRCINFO

  git add PKGBUILD .SRCINFO
  git commit -m "chore!: update to electron ${latestElectronVersion}"
fi

git push origin master