summarylogtreecommitdiffstats
path: root/update.sh
blob: a692d8bd6682d8c34eb076e39499db3b8ce5ccf1 (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
#!/bin/bash
set -e
set -o pipefail

HASH=b2sum
HASH_NAME=b2sums

source PKGBUILD
PKGNAME=$_name
RELEASES=$(curl -sL https://pypi.org/pypi/$PKGNAME/json | jq .releases)

LAST=$(jq -r <<<$RELEASES '
[ keys[]
    | select(contains("beta") == false)
    | select(contains("rc") == false)
    | select(contains("a") == false)
    | select(contains("b") == false)
    | select(contains("c") == false)
    | select(contains("d") == false)
    | [split(".")[] | tonumber] ]
  | sort[-1]
  | join(".")
')

if [ "$pkgver" == "$LAST" ]; then
    echo "Already up to date" >&2
    exit 0
fi

LICENSE_URL="https://raw.githubusercontent.com/pola-rs/polars/py-$LAST/LICENSE"
LICENSE_BODY=$(curl -sL $LICENSE_URL)
LICENSE_SUM=$($HASH - <<<$LICENSE_BODY | cut -d' ' -f1)

DOWNLOAD_URL=$(jq -r <<<$RELEASES --arg last $LAST '
    .[$last][]
        | select(.packagetype == "bdist_wheel")
        | select(.filename | contains("linux"))
        | select(.filename | contains("x86_64"))
        .url
')

SUM=$(curl -sL $DOWNLOAD_URL | $HASH - | cut -d' ' -f1)
FILENAME=$(basename $DOWNLOAD_URL)

sed -i 's,source=.*$,source=("'${DOWNLOAD_URL}'" "'$LICENSE_URL'"),' PKGBUILD
sed -i 's/noextract=.*$/noextract=("'$FILENAME'")/' PKGBUILD
sed -i 's/.*sums=.*$/'$HASH_NAME'=("'$SUM'" "'$LICENSE_SUM'")/' PKGBUILD
sed -i 's/pkgver=.*/pkgver='$LAST'/' PKGBUILD
sed -i 's/pkgrel=.*/pkgrel=1/' PKGBUILD

# Make sure it builds fine
makepkg -f

git add PKGBUILD
git commit -m "Update to $LAST"
git push