5 # Targets are taken from a file or the command-line, to avoid
6 # redirecting stdin to aur-view or aur-build.
8 list
=$
(realpath
-- "$1")
10 printf >&2 '%s: %s: file is empty or does not exist\n' "$argv0" "$1"
14 # Create a scratch space. /var/tmp ensures sufficient space for built
15 # packages (not on tmpfs by default)
16 var_tmp
=$
(mktemp
-d --tmpdir="${TMPDIR:-/var/tmp/}")
18 trap 'rm -rf "$tmp" "$var_tmp"' EXIT
# comment this if inspecting the contents
20 # 1. Avoid concurrent use
21 ( flock
-n 200 ||
exit 1
24 # Retrieve repository location
25 { IFS
=: read -r _ db_name
26 IFS
=: read -r _ db_root
27 IFS
=: read -r _ db_path
28 } < <(aur repo
--status "$@")
31 # 2. Retrieve targets and their dependencies from the local repository.
32 aur repo-parse
-p "$db_path" --table |
tee db_table | \
33 cut
-f1,2 |
grep -Fwf "$list" |
tsort >db_deps
35 # 3. Remove entries that are not in the dependency tree.
36 cut
-f1 db_table |
grep -Fxvf db_deps |
sort -u >db_removals
38 files_path
=$
(realpath
"$db_root/$db_name".files
)
40 # Create copy of local repository database
41 cp -Pv "$db_path" "$db_root/$db_name".db
"$var_tmp"
42 cp -Pv "$files_path" "$db_root/$db_name".files
"$var_tmp"
44 # 4. Remove entries that are not in the dependency tree.
46 xargs -a "$tmp"/db_removals
-r repo-remove
"${db_path##*/}"
48 # 5. Add symlinks to built packages.
49 aur repo-parse
-p "$db_path" --attr FileName | \
50 xargs env
-C "$db_root" realpath
-z |
xargs -0r ln -t "$var_tmp" -s --
52 # 6. Point the repository root in pacman.conf to the temporary directory.
53 { printf '[options]\n'
54 pacconf
--raw --options
56 while IFS
= read -r; do
58 printf '[%s]\n' "$REPLY"
60 if [[ $REPLY == "$db_name" ]]; then
61 pacconf
--raw --repo="$REPLY" --verbose Usage SigLevel
62 printf '%s\n' "Server = file://$var_tmp"
64 pacconf
--raw --repo="$REPLY" --verbose Usage SigLevel Server
66 done < <(pacconf
--repo-list)
69 # 7. Run aur-sync(1) with the new pacman configuration.
70 # Adjust options to preference.
71 aur sync
-d "$db_name" --pacman-conf="$tmp"/pacman.conf
-Rrn $
(<"$list")
73 # 8. Synchronize the new repository state to the original location.
74 # Remove --dry-run if the output is as desired.
76 rsync
-avh "$var_tmp"/ "$db_root"/ --delete \
77 --copy-links --exclude={"$db_name".db
,"$db_name".files
} --dry-run
79 # 9. Save list with new dependency tree
80 cp -v "$list" "$list".old
81 aur repo-parse
-p "$db_path" --list | cut
-f1 >"$list"