Browse Source

add examples directory

To make updating and copying of sample scripts more convenient, place
them in an `examples` directory. For now this contains the
`aur-sync-devel` script from aurvcs.7. The subdirectory contains a
`README.md` with a basic overview of the included scripts.

This is superficially similar to the previous `contrib` directory, but
emphasizes the use as examples, instead of "unsupported" third-party
scripts.
pull/960/head
Alad Wenter 5 months ago
parent
commit
2086b2130a
  1. 19
      examples/README.md
  2. 56
      examples/aur-sync-devel
  3. 2
      makepkg/PKGBUILD
  4. 107
      man7/aurvcs.7

19
examples/README.md

@ -0,0 +1,19 @@
This directory contains simple examples which combine `aur(1)` programs. They
typically have fixed options and are documented line-by-line.
## aur-vcs-devel
The aim of this script is to take all VCS (version control) packages in a local
repository, update the corresponding source files to the latest upstream
revision, and build them if there are any changes. This is done because VCS
packages typically have `pkgver` set to the upstream revision at the time of
AUR package submission.
The sample script performs two updates:
1. Retrieve new AUR revisions with `aur-fetch(1)` and inspect them with `aur-view(1)`
2. Retrieve new upstream revisions with `aur-srcver(1)`
In the second step, `makepkg -o` is run on each `PKGBUILD`, updating `pkgver`.
The full version (`epoch:pkgver-pkgrel`) is then compared to the contents of
the local repository with `aur-vercmp(1)`. If there is an update, the package
is built with `aur-build(1)`.

56
examples/aur-sync-devel

@ -0,0 +1,56 @@
#!/bin/bash
set -e
argv0=sync-devel
XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
AURDEST=${AURDEST:-$XDG_CACHE_HOME/aurutils/sync}
AURVCS=${AURVCS:-.*-(cvs|svn|git|hg|bzr|darcs)$}
filter_vcs() {
awk -v "mask=$AURVCS" '$1 ~ mask {print $1}' "$@"
}
# Scratch space for intermediary results.
tmp=$(mktemp -d --tmpdir "aurutils-$UID/$argv0.XXXXXXXX")
trap 'rm -rf "$tmp"' EXIT
# Retrieve a list of the local repository contents. The repository
# can be specified with the usual aur-repo arguments.
aur repo --list "$@" | tee "$tmp"/db | filter_vcs - >"$tmp"/vcs
# Pull any new AUR revisions (e.g. dependency updates) for VCS packages.
cd "$AURDEST"
aur fetch - --results="$tmp"/fetch_results <"$tmp"/vcs
# Only run aur-view on non-empty git repositories.
targets=()
while IFS=: read -r mode rev_old rev path; do
path=${path#file://} name=${path##*/}
case $mode in
clone|fetch|rebase|reset)
if [[ $rev != "HEAD" ]] && [[ $rev != "0" ]]; then
targets+=("$name")
fi ;;
esac
done < "$tmp"/fetch_results
# Inspect packages with aur-view(1). This is done before running
# aur-srcver, which runs makepkg and sources the PKGBUILD.
if (( ! ${#targets[@]} )); then
exit
fi
aur view "${targets[@]}"
# Find VCS packages that are outdated according to aur-srcver.
# This checks out the latest revision for existing source directories,
# assuming the PKGBUILD has been viewed priorly.
cat "$tmp"/db | aur vercmp -p <(aur srcver "${targets[@]}") | \
awk '{print $1}' >"$tmp"/ood
# Build the packages. Arguments are shared between aur-repo and
# aur-build to specify the repository.
if [[ -s $tmp/ood ]]; then
aur build "$@" -a "$tmp"/ood --syncdeps --rmdeps --noconfirm
else
printf >&2 '%s: all packages up-to-date\n' "$argv0"
fi

2
makepkg/PKGBUILD

@ -1,6 +1,6 @@
# Maintainer: Alad Wenter <https://github.com/AladW>
pkgname=aurutils-git
pkgver=6.4.r0.gce1015d
pkgver=8.1.1.r1.gb2d35fc
pkgrel=1
pkgdesc='helper tools for the arch user repository'
url='https://github.com/AladW/aurutils'

107
man7/aurvcs.7

@ -1,107 +0,0 @@
.TH AURVCS 7 2022-03-02 AURUTILS
.SH NAME
aurvcs \- workflows for VCS packages
.
.SH DESCRIPTION
Workflows for building and managing VCS packages.
.
.SH aur\-sync\-devel
Takes the contents of a local repository
.RB ( "aur\-repo \-\-list" )
and matches them against a common pattern for VCS packages
.RB ( "grep \-E $AURVCS" ).
It then looks in the
.BR aur\-sync (1)
cache
.RB ( "find $AURDEST" )
for relevant directories.
.PP
Any existing
.BR PKGBUILD (5)
files in these directories are executed, with upstream sources updated
to their latest revision.
.RB ( aur\-srcver
using
.BR "makepkg \-o" ).
.PP
Any option arguments are forwarded to
.BR aur\-repo (1).
.
.SS Program source
.EX
#!/bin/bash
set \-e
argv0=sync\-devel
XDG_CACHE_HOME=${XDG_CACHE_HOME:\-$HOME/.cache}
AURDEST=${AURDEST:\-$XDG_CACHE_HOME/aurutils/sync}
AURVCS=${AURVCS:\-.*\-(cvs|svn|git|hg|bzr|darcs)$}
filter_vcs() {
awk \-v "mask=$AURVCS" '$1 ~ mask {print $1}' "$@"
}
# Scratch space for intermediary results.
tmp=$(mktemp \-d \-\-tmpdir "aurutils-$UID/$argv0.XXXXXXXX")
trap 'rm \-rf "$tmp"' EXIT
# Retrieve a list of the local repository contents. The repository
# can be specified with the usual aur-repo arguments.
aur repo \-\-list "$@" | tee "$tmp"/db | filter_vcs \- >"$tmp"/vcs
# Pull any new AUR revisions (e.g. dependency updates) for VCS packages.
cd "$AURDEST"
aur fetch \- \-\-results="$tmp"/fetch_results <"$tmp"/vcs
# Only run aur\-view on non-empty git repositories
targets=()
while IFS=: read -r mode rev_old rev path; do
path=${path#file://} name=${path##*/}
case $mode in
clone|fetch|rebase|reset)
if [[ $rev != "HEAD" ]] && [[ $rev != "0" ]]; then
targets+=("$(basename \-\- "$path")")
fi ;;
esac
done < "$tmp"/fetch_results
# Inspect packages with aur\-view(1). This is done before running
# aur-srcver, which runs makepkg and sources the PKGBUILD.
if (( ! ${#targets[@]} )); then
exit
fi
aur view "${targets[@]}"
# Find VCS packages that are outdated according to aur-srcver.
# This checks out the latest revision for existing source directories,
# assuming the PKGBUILD has been viewed priorly.
aur vercmp \-p <(aur srcver "${targets[@]}") <"$tmp"/db | awk '{print $1}' >"$tmp"/ood
# Build the packages. Arguments are shared between aur\-repo and
# aur\-build to specify the repository.
if [[ \-s $tmp/ood ]]; then
aur build "$@" \-a "$tmp"/ood \-\-syncdeps \-\-rmdeps \-\-noconfirm
else
printf >&2 '%s: all packages up\-to\-date\\n' "$argv0"
fi
.EE
.
.SS Notes
In the penultimate line, the resulting package versions
.RB ( "get_latest_revision" )
are compared against the local repository
.RB ( "aur repo \-\-list" ).
If the package version is newer, it is built with
.BR aur\-build (1).
.PP
Version-control packages typically have
.B pkgver
set to the upstream revision at the time of package submission, making
the AUR-advertised version older than the latest version.
.
.SH AUTHORS
.MT https://github.com/AladW
Alad Wenter
.ME
.
.\" vim: set textwidth=72:
Loading…
Cancel
Save