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

# BEGIN functions for version comparison
verlte() {
    [  "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}

verlt() {
    [ "$1" = "$2" ] && return 1 || verlte $1 $2
}
# END functions


wget -O teamcity.json "https://data.services.jetbrains.com/products/releases?code=TC&latest=true&type=release&downloads=linux"
downloadLink=`jq -r '.TC[0].downloads.linux.link' < teamcity.json`
checksumLink=`jq -r '.TC[0].downloads.linux.checksumLink' < teamcity.json`
pkgver=`jq -r '.TC[0].version' < teamcity.json`
oldpkgver=`grep -oP '(?<=pkgver = ).*' .SRCINFO`

verlt $oldpkgver $pkgver
if [ $? -eq 0 ]; then
    wget $downloadLink
    wget $checksumLink

    checksumFile=$(sed -r 's|.*/(.*\.tar\.gz\.sha256)|\1|' <<< $checksumLink)
    downloadFile=$(sed -r 's|.*/(.*\.tar\.gz)|\1|' <<< $downloadLink)

    sha256sum --status -c "$checksumFile"
    if [ $? -eq 0 ]; then
        checksum=`sha256sum "TeamCity-$pkgver.tar.gz" | cut -d " " -f1`
        sed -ri "s/pkgver=.*/pkgver=$pkgver/" ./PKGBUILD
        sed -ri "s/sha256sums=\('.*'/sha256sums=\('$checksum'/" ./PKGBUILD
        sed -ri "s|source=\(.*|source=\('$downloadLink'|" ./PKGBUILD
        makepkg --printsrcinfo > .SRCINFO
        rm $checksumFile
        rm $downloadFile
        printf "Built updated TeamCity package.\n\nOld version: %s\nNew version: %s" "$oldpkgver" "$pkgver"
    else
        echo "An error occured"
    fi
fi