#!/bin/sh # Small script for updating the sha256 sums in PKGBUILD files. # Useful for AUR maintainers. # Automatically replaces sha256sums* with updated versions from # makepkg -g. Previous PKGBUILD is always backed up. # Requires kakoune (pacman -S kakoune) # Author: Daniel Fichtinger # License: GPLv3 # check if user gave path to a PKGBUILD, # or a directory that contains it. if [ "$#" -eq 0 ]; then input="$PWD" else input="$1" fi if [ -d "$input" ]; then input="$input/PKGBUILD" fi if [ "$(basename "$input")" != "PKGBUILD" ] || [ ! -f "$input" ]; then echo "PKGBUILD not found!" exit 1 fi pwd="$(dirname "$input")" # use kak -f to perform the replacement # select first and last line with sha256sums # select union of those selections # replace selection with output of makepkg -g kak_filter='gg/sha256sumsxZggxu|makepkg -g' # run the filter and write to temp file tempfile="$(mktemp)" env -C "$pwd" kak -f "$kak_filter" <"$input" >"$tempfile" # user confirmation ${PAGER:-less} "$tempfile" printf 'Do you want to proceed? [y/N]: ' read -r answer case "$answer" in [Yy]*) echo "Replacing..." # back up previous mv "$input" "${input}.bak" mv "$tempfile" "$input" ;; *) echo "Aborted." rm "$tempfile" exit 1 ;; esac