Download PKGBUILD file conveniently to create a package with it

Every now and then I need a PKGBUILD file to create a package for Arch Linux, for example to install it on multiple computers in a LAN.

Let’s take as a random example. For example, one can click on “View PKGBUILD” at mentioned link and then save the displayed content in a PKGBUILD file locally. Alternatively, one can also run git clone –depth 1 This automatically saves the desired file but you have to know the exact link. I don’t like either solution very much.

Today I came across the tool pbget. With this one only needs to know the name of the package to be created. Thus, the command pbget –aur ttf-iosevka-term is sufficient to download the desired PKGBUILD file. It is necessary to use –aur in this case, because ttf-iosevka-term is only available in the AUR and pbget only searches the official package sources by default.

The command should create the directory ttf-iosevka-term and store the PKBUILD file in it. If you change to this directory and run makepkg -crs PKGBUILD -noconfirm the package will be created. Or you can run makepkg -cirs PKGBUILD -noconfirm to also install the package.

By the way, pbget can be found in the AUR.

OSBN | Arch

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