sync: use `build --status`
[aurutils.git] / examples / sync-asroot
blob4585a16eee02788102c14be991d870bf2500bf74
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 # option parsing
13 unset build_user
14 while getopts :U:d:k:fSuN OPT; do
15 case $OPT in
16 d) build_args+=(-d "$OPTARG"); sync_args+=(-d "$OPTARG") ;;
17 f) build_args+=(-f "$OPTARG") ;;
18 S) build_args+=(-S) ;;
19 U) build_user=$OPTARG ;;
20 k) keep_going=$OPTARG ;;
21 u) sync_args+=(-u) ;;
22 N) sync_args+=(--no-ver) ;;
23 esac
24 done
25 shift $(( OPTIND-1 ))
27 # 1. define unprivileged commands ------------------------------------------------->
28 build_user=${build_user:-${SUDO_USER:-$USER}}
29 build_args+=(-U "$build_user")
31 build_env=(AUR_MAKEPKG="runuser -u $build_user -- makepkg"
32 AUR_GPG="runuser -u $build_user -- gpg"
33 AUR_REPO_ADD="runuser -u $build_user -- repo-add"
34 AUR_BUILD_PKGLIST="runuser -u $build_user -- aur build--pkglist")
36 # 2. retrieve sources ------------------------------------------------------------->
37 ninja_dir=$(runuser -u "$build_user" -- mktemp -d) || exit
38 trap 'rm -rf "$ninja_dir"' EXIT
40 runuser -u "$build_user" -- \
41 env AURDEST="$AURDEST" aur sync "${sync_args[@]}" "$@" --columns --save "$ninja_dir"/graph || exit 1
43 # 3. build queue ------------------------------------------------------------------>
44 if [[ -s $ninja_dir/graph ]]; then
45 runuser -u "$build_user" -- aur sync--ninja "$AURDEST" <"$ninja_dir"/graph >"$ninja_dir"/build.ninja -- \
46 env AUR_ASROOT=1 "${build_env[@]}" aur build "${build_args[@]}"
48 env NINJA_STATUS='[%s/%t] ' ninja -C "$ninja_dir" -k "$keep_going"