Automatically update the Pkgbuild file and install it

Under Arch I have installed a few packages whose updates are sometimes offered with a time delay. For example, because the respective package maintainer does not have the necessary time or because he wants to wait for the first minor release. Hugo is often such a package.

Therefore I often install the current version myself. For this I created the directory ~/pkgbuilds/hugo/ and stored the PKGBUILD file in this directory to install the package. In the case of Hugo, this currently looks like this.

pkgdesc="Fast and Flexible Static Site Generator in Go"
makedepends=('go' 'git')
optdepends=('python-pygments: syntax-highlight code snippets'
            'python-docutils: reStructuredText support')

build() {
  cd "${srcdir}"/${pkgname}-${pkgver}
  export CGO_CFLAGS="${CFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  go build -tags extended

  ./hugo gen man
  ./hugo completion bash > ${pkgname}.bash-completion
  ./hugo completion fish > ${pkgname}.fish
  ./hugo completion zsh > ${pkgname}.zsh

package() {
  cd "${srcdir}"/${pkgname}-${pkgver}
  install -Dm755 "${pkgname}" "${pkgdir}"/usr/bin/${pkgname}
  install -Dm644 LICENSE "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE

  install -Dm644 "${srcdir}"/${pkgname}-${pkgver}/man/*.1  -t "${pkgdir}"/usr/share/man/man1/
  install -Dm644 ${pkgname}.bash-completion "${pkgdir}"/usr/share/bash-completion/completions/${pkgname}
  install -Dm644 ${pkgname}.fish "${pkgdir}"/usr/share/fish/vendor_completions.d/${pkgname}.fish
  install -Dm644 ${pkgname}.zsh "${pkgdir}"/usr/share/zsh/site-functions/_${pkgname}

If a new version was published I enter the new version in the PKGBUILD file at the line pkgver=. Then I execute the commands updpkgsums PKGBUILD, makepkg -cirs PKGBUILD -noconfirm and rm – .tar. in the directory where the file is located.

The first command downloads the archive file containing the source code, creates the checksum of the file, and adds it to the PKGBUILD file. The second command uses the instructions in the PKGBUILD file to build and install the package. The last command deletes both the archive file with the source code and the created package.

Because I am already quite skilled at this, this doesn’t take a minute. However, I still want to automate the process. Therefore I have created a function for myself.

updpkgbuild () {
	sed -E "s#(pkgver=).*#\1$new_ver#" -i PKGBUILD
	updpkgsums PKGBUILD
	makepkg -cirs PKGBUILD --noconfirm
	rm -- *.tar.*

With this I only need to run for example updpkgbuild 0.102.0 in the directory of the PKGBUILD file and version 0.102.0 of the package will be installed automatically. Of course, the whole process only works if only the version as well as the checksum needs to be updated. But this is mostly the case.

I created this function for the zsh. Whether this also works in other shells like bash or fish, I can’t say.

OSBN | Linux

These articles could also be interesting:
I reserve the right not to activate comments. The activation of comments can also take several days.