2 # run as: `sudo sync-asroot ...`
3 [[ -v AUR_DEBUG
]] && set -o xtrace
4 SUDO_HOME
=$
(eval echo "~$SUDO_USER")
5 XDG_CACHE_HOME
=${XDG_CACHE_HOME:-$SUDO_HOME/.cache}
6 AURDEST
=${AURDEST:-$XDG_CACHE_HOME/aurutils/sync}
10 build_args
=(-LR --chroot) sync_args
=() keep_going
=1
12 # colors (for build summary)
13 source /usr
/share
/makepkg
/util
/message.sh
15 if [[ ! -v NO_COLOR
]] && [[ ! -v AUR_DEBUG
]]; then
16 [[ -t 2 ]] && colorize
21 while getopts :U
:d
:k
:fSuN OPT
; do
23 d
) build_args
+=(-d "$OPTARG"); sync_args
+=(-d "$OPTARG") ;;
24 f
) build_args
+=(-f "$OPTARG") ;;
25 S
) build_args
+=(-S) ;;
26 U
) build_user
=$OPTARG ;;
27 k
) keep_going
=$OPTARG ;;
29 N
) sync_args
+=(--no-ver) ;;
34 # 1. define unprivileged commands ------------------------------------------------->
35 build_user
=${build_user:-${SUDO_USER:-$USER}}
36 build_args
+=(-U "$build_user")
38 build_env
=(AUR_MAKEPKG
="runuser -u $build_user -- makepkg"
39 AUR_GPG
="runuser -u $build_user -- gpg"
40 AUR_REPO_ADD
="runuser -u $build_user -- repo-add"
41 AUR_BUILD_PKGLIST
="runuser -u $build_user -- aur build--pkglist")
43 # 2. retrieve sources ------------------------------------------------------------->
44 ninja_dir
=$
(runuser
-u "$build_user" -- mktemp
-d) ||
exit
45 trap 'rm -rf "$ninja_dir"' EXIT
47 runuser
-u "$build_user" -- \
48 env AURDEST
="$AURDEST" aur sync
"${sync_args[@]}" "$@" --columns --save "$ninja_dir"/graph ||
exit 1
50 # 3. build queue ------------------------------------------------------------------>
51 if [[ -s $ninja_dir/graph
]]; then
52 runuser
-u "$build_user" -- aur sync--ninja
"$AURDEST" <"$ninja_dir"/graph
>"$ninja_dir"/build.ninja
-- \
53 env AUR_ASROOT
=1 "${build_env[@]}" aur build
"${build_args[@]}"
55 env NINJA_STATUS
='[%s/%t] ' ninja
-C "$ninja_dir" -k "$keep_going"
57 # The following is taken from aur-sync, but we want the build results always.
59 # Print all targets in dependency order
60 NINJA_STATUS
='[%s/%t] ' ninja
-nC /var
/empty
-f "$ninja_dir"/build.ninja | \
61 # [\w@\.\-\+]: valid characters for pkgname
62 # alternative: [^\s]+ from rule `env -C ... > pkgbase.stamp`
63 pcregrep
-o1 -o3 '(\[\d+/\d+\] )(.+?)([\w@\.\-\+]+)(\.stamp)' |
while read -r status pkg
65 if [[ -f $ninja_dir/$pkg.stamp
]]; then
66 printf "${BOLD}${BLUE}%s${ALL_OFF} %s\t${BOLD}${GREEN}[OK]${ALL_OFF}\n" "$status" "$pkg"
68 printf "${BOLD}${BLUE}%s${ALL_OFF} %s\t${BOLD}${RED}[FAIL]${ALL_OFF}\n" "$status" "$pkg"