summarylogtreecommitdiffstats
path: root/check-updates.sh
blob: a5d087212e2cf525cfc42b3b6b3e02b916b8196e (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
#!/usr/bin/env bash

set -euo pipefail

readonly PKGBUILD_FILE="${1:-PKGBUILD}"
readonly UPDATE_YML_URL="https://software.lenzaos.com/app-chats/latest-linux.yml"

if [[ ! -f "${PKGBUILD_FILE}" ]]; then
  echo "error: file not found: ${PKGBUILD_FILE}" >&2
  exit 1
fi

current_version="$(awk -F= '/^pkgver=/{print $2; exit}' "${PKGBUILD_FILE}")"
if [[ -z "${current_version}" ]]; then
  echo "error: failed to read pkgver from ${PKGBUILD_FILE}" >&2
  exit 1
fi

if ! latest_yml="$(curl -fsSL "${UPDATE_YML_URL}")"; then
  echo "error: failed to fetch ${UPDATE_YML_URL}" >&2
  exit 2
fi

latest_version="$(
  printf '%s\n' "${latest_yml}" \
    | awk -F': ' '/^version:/{print $2; exit}' \
    | tr -d '\r'
)"

if [[ -z "${latest_version}" ]]; then
  echo "error: failed to read version from ${UPDATE_YML_URL}" >&2
  exit 1
fi

if [[ "${current_version}" == "${latest_version}" ]]; then
  echo "up-to-date: ${current_version}"
  exit 0
fi

echo "update available: ${current_version} -> ${latest_version}"
exit 10