Last active
October 28, 2023 09:56
-
-
Save getchoo/7a4dbda9a52c856c082e270bc9bda6db to your computer and use it in GitHub Desktop.
a small posix sh script for updating PKGBUILDs automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| ## SPDX-License-Identifier: MIT | |
| ## a small posix sh script for updating PKGBUILDs | |
| ## this uses files named `update.sh` in the same directory as a PKGBUILD | |
| ## they can be configured like this: | |
| ## | |
| ## ``` | |
| ## name="foo" | |
| ## link='https://api.github.com/repos/bar/foo/releases/latest' | |
| ## jq_exp='.tag_name' | |
| ## regex='v/' # this will be run with `sed` to get the `pkgver`. in this case it only removes the 'v' prefix | |
| ## `` | |
| ## | |
| ## requires: gh, jq | |
| # shellcheck disable=SC2154,SC1091,SC2094 | |
| set -e | |
| origdir="$PWD" | |
| pkgdir="$HOME/pkgbuilds/" # directory with subfolders containing PKGBUILDS | |
| catch_err() { | |
| echo "$1: failed to $2" | |
| } | |
| # temp file to write new pkgbuilds to | |
| tmp="$(mktemp PKGBUILD-XXXXX)" | |
| trap 'rm -f "$tmp"' EXIT | |
| for dir in "$pkgdir"/*/; do | |
| if [ ! -f "$dir"/update.sh ]; then | |
| continue | |
| fi | |
| . "$dir"/update.sh | |
| echo "updating $name..." | |
| latest_ver="$(gh api "$link" | jq "$jq_exp" | tr -d '"' | sed "s/$regex/" )" | |
| cur_ver="$(grep '^pkgver=' "$dir"/PKGBUILD | sed 's/pkgver=//')" | |
| [ "$latest_ver" = "$cur_ver" ] && continue | |
| echo "updating $name: $cur_ver -> $latest_ver" | |
| # not all systems have `sed -i` ;) | |
| sed "s/^pkgver=.*/pkgver=$latest_ver/" "$dir"/PKGBUILD > "$tmp" | |
| sed 's/^pkgrel=.*/pkgrel=1/' "$tmp" > "$dir"/PKGBUILD | |
| cd "$dir" || catch_err "$0" "cd into $dir" | |
| updpkgsums | |
| makepkg -sCcr | |
| # use this if you have aurutils for more reliable builds | |
| # aur chroot -B -N | |
| makepkg --printsrcinfo > .SRCINFO | |
| cd "$origdir" || catch_err "$0" "cd into $origdir...what did you do" | |
| unset name link jq_exp regex | |
| done | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment