sync: use `build --status`
[aurutils.git] / examples / sync-devel
blob1d9f227f199d262c6bb840fb83d7a784b910c264
1 #!/bin/bash
2 set -e
3 argv0=sync-devel
4 XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
6 # For the purposes of this example, we assume AURDEST contains both AUR and
7 # non-AUR git repositories (e.g. from github or archweb), with corresponding
8 # packages in the local repository.
9 AURDEST=${AURDEST:-$XDG_CACHE_HOME/aurutils/sync}
10 AURVCS=".*-(cvs|svn|git|hg|bzr|darcs)$"
12 # Pattern the defines VCS packages. The AUR has no formal definition of a VCS
13 # package - here we include the most common version control systems.
14 filter_vcs() {
15 awk -v "mask=$AURVCS" '$1 ~ mask {print $1}' "$@"
18 # Scratch space for intermediary results.
19 mkdir -pm 0700 "${TMPDIR:-/tmp}/aurutils-$UID"
20 tmp=$(mktemp -d --tmpdir "aurutils-$UID/$argv0.XXXXXXXX")
21 trap 'rm -rf "$tmp"' EXIT
23 # Retrieve a list of the local repository contents. The repository
24 # can be specified with the usual aur-repo arguments.
25 aur repo --list "$@" | tee "$tmp"/db | filter_vcs - >"$tmp"/vcs
27 # Only AUR repositories can be cloned anew, as the source of non-AUR packages
28 # is unknown beforehand. Their existence is checked with `git-ls-remote` (`-e`)
29 # Running makepkg locally on a PKGBUILD with pkgver() results in local changes,
30 # so these are removed with `--discard`. New upstream commits are then merged
31 # with `git-merge` or `git-rebase` (`--sync=auto`). The final PKGBUILD is shown
32 # in `aur-view` later on.
33 cd "$AURDEST"
34 aur fetch -e --discard --sync=auto --results="$tmp"/fetch_results - <"$tmp"/vcs
36 # Make sure empty repositories are not considered for inspection.
37 targets=()
38 while IFS=: read -r mode rev_old rev path; do
39 path=${path#file://} name=${path##*/}
41 case $mode in
42 clone|merge|fetch|rebase|reset)
43 [[ $rev != "0" ]] && targets+=("$name") ;;
44 esac
45 done <"$tmp"/fetch_results
47 # Inspect new AUR (downstream) commits with aur-view(1). This is done
48 # before running aur-srcver, which runs makepkg and sources the
49 # PKGBUILD.
50 aur view "${targets[@]}"
52 # Update `epoch:pkgver-pkgrel` for each target with `aur-srcver`.
53 # This runs `makepkg`, cloning upstream to the latest revision. The
54 # output is then compared with the contents of the local repository.
55 cat "$tmp"/db | aur vercmp -p <(aur srcver "${targets[@]}") | \
56 awk '{print $1}' >"$tmp"/ood
58 # Build the packages. Arguments are shared between aur-repo and
59 # aur-build to specify the local repository.
60 if [[ -s $tmp/ood ]]; then
61 aur build "$@" -a "$tmp"/ood --syncdeps --rmdeps --noconfirm
62 else
63 printf >&2 '%s: all packages up-to-date\n' "$argv0"