summarylogtreecommitdiffstats
path: root/update_MAC_SDK.zsh
blob: 52084e323ca438a70c8bd11d5dc7c4c88cad78e5 (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 zsh

function get_last_version(){
    local link=https://monkeysaudio.com/versionhistory.html
    local version=$(curl -s $link | awk '/Version [0-9]+\.[0-9]+/{print $3; exit}')
    echo $version
}

function patch_pkgbuild(){
    local version=$1
    sed -i "s/pkgver=.*/pkgver=$version/" PKGBUILD
}

function update_to(){
    local version=$1
    patch_pkgbuild $version
    updpkgsums && makepkg && makepkg --printsrcinfo > .SRCINFO
}

function sync_git(){
    local version=$1
    git commit PKGBUILD .SRCINFO -m "Update SDK to $version"
    git push
}

function try_update(){
    local ver=$1
    local old_ver=$(awk -F= '/pkgver=/{print $2}' PKGBUILD)
    if [[ $ver == $old_ver ]]; then
        echo "Already up-to-date: version $ver"
    else
        update_to $ver && sync_git $ver || patch_pkgbuild $old_ver
    fi
}

function main(){
    local ver=$(get_last_version)
    [[ -n $ver ]] && try_update $ver || { echo "Can't retrieve online version" && return 1 }
}

cd $0:A:h && main $@