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

set -e

### Update PKGBUILD

source PKGBUILD

# Get redirected URL
get_redirected() {
  if command -v curl >/dev/null; then
    curl -Ls -w '%{url_effective}' -o /dev/null "$1"
  elif command -v wget >/dev/null; then
    wget -O /dev/null "$1" 2>&1 | grep "Location: " | head -1 | cut -f2
  else
    echo "Could not find curl or wget"
    return 1
  fi
}

# Get file from URL with redirects
get_file() {
  if command -v curl >/dev/null; then
    curl -Ls "$1"
  elif command -v wget >/dev/null; then
    wget -q -O - "$1"
  else
    echo "Could not find curl or wget"
    return 1
  fi
}

# Get latest upstream version
url=https://github.com/tiann/$_pkg

_upstream_version=$(get_redirected "$url/releases/latest")
_upstream_version=${_upstream_version##*/}

echo $_upstream_version

_upver=${_upstream_version#v}
pkgver=${_upver%-*}
pkgrel=${_upver#*-}
if [ ! "$pkgrel" ] || [ "$pkgrel" = "$_upver" ]; then
  pkgrel=1
fi

# Replace variables in PKGBUILD
sed -i "s/^pkgver=.*/pkgver=${pkgver}/;s/^pkgrel=.*/pkgrel=${pkgrel}/;s/^_ver=.*/_ver=${_upver}/;s/^_upstream_ver=.*/_upstream_ver=${_upstream_version}/" PKGBUILD

# Test the updated PKGBUILD
if ! makepkg -f; then
  echo "Error: makepkg failed with the updated PKGBUILD."
  exit 1
fi

## Update repo

# Generate new .SRCINFO
makepkg --printsrcinfo >.SRCINFO

# Generate commit
git add PKGBUILD .SRCINFO

# Check git signing option
if git config --get commit.gpgSign | grep -q 'true'; then
  commit_flags=('-S')
fi

git commit "${commit_flags[@]}" -m "Bumped version to ${pkgver}-${pkgrel}"

# Push commit
git push origin master