build: error on partially built package group
[aurutils.git] / examples / sync-asroot
blobc86bf6047b418000dda882ef468f47a7ff08d91e
1 #!/bin/bash
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}
7 argv0=sync-asroot
9 # default options
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
19 # option parsing
20 unset build_user
21 while getopts :U:d:k:fSuN OPT; do
22 case $OPT in
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 ;;
28 u) sync_args+=(-u) ;;
29 N) sync_args+=(--no-ver) ;;
30 esac
31 done
32 shift $(( OPTIND-1 ))
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"
67 else
68 printf "${BOLD}${BLUE}%s${ALL_OFF} %s\t${BOLD}${RED}[FAIL]${ALL_OFF}\n" "$status" "$pkg"
70 done | column -t