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