summarylogtreecommitdiffstats
path: root/aurupdate
blob: 9f412fb6f59041c9b37b2e944c216c1ef6d518b3 (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
#!/usr/bin/env bash

function getconfig {
    git config -f ~/.avr --get "$1"
}

function load {
    tmpdir=$(mktemp -d)
    pkgdir="${1}"

    source "${pkgdir}/PKGBUILD"
    latest=$(_latest)

    if [ "${latest//v}" != "$(echo -e "${latest//v}\n$pkgver" | sort -V | head -n1)" ]; then
        prefix="${_pkgname:-${pkgname}}"
        export "${prefix^^}_VERSION=${latest//v}"
        source "${pkgdir}/PKGBUILD.tpl"

        sha256="\nsha256sums=(\n"
        for uri in ${source[@]}; do
            srcname="${uri%%::*}"
            if [ ! -z ${srcname} ]; then
                srcname=$(basename ${uri})
            fi
            srcuri="${uri##*::}"
            curl -s -L -o $tmpdir/$srcname $srcuri
            sha256+="    $(sha256sum $tmpdir/$srcname | cut -d' ' -f1)\n"
        done
        sha256+=")\n"

        envsubst "\$${prefix^^}_VERSION" < "${pkgdir}/PKGBUILD.tpl" > "${pkgdir}/PKGBUILD"

        printf "${sha256}" >> "${pkgdir}/PKGBUILD"

        cd "$pkgdir"
        makepkg --printsrcinfo > .SRCINFO
        cd ..

        git add "${pkgdir}/PKGBUILD" "${pkgdir}/.SRCINFO"
        git ci -m "bumping $pkgname to version $latest"
        aurpublish "$pkgdir"
        git push origin main
    fi
}

cd $(getconfig update.localRepositoryLocation)
git pull origin main

for result in $(find . -mindepth 2 -maxdepth 2 -type f -name ".autoupdate"); do
    package=$(echo $result | cut -d'/' -f 2)
    if [ -f "${package}/PKGBUILD" ]; then
        ( load "${package}" )
    fi
done