-
Notifications
You must be signed in to change notification settings - Fork 0
/
aurum.in
215 lines (184 loc) · 6.15 KB
/
aurum.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
[[ -v AUR_DEBUG ]] && set -o xtrace
XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
readonly argv0=aurum
readonly version='AURUM_VERSION'
readonly lib_dir=${AURUM_EXEC_PATH:-'AURUM_LIB_DIR'}
# append utilities to PATH (propagates to external commands like ninja)
if [[ "$PATH" != "$lib_dir:"* ]]; then
readonly PATH=$lib_dir:$PATH
fi
# default arguments
build_args=(-R)
fetch_args=()
sync_args=(--format=log)
# default options
fetch_only=0
info_only=0
search_only=0
view_only=0
upgrades=0
use_mirror=1
use_ninja=0 # TODO: enable ninja by default when implemented
use_default_fm=0
use_dialog=1
usage() {
echo "usage: $argv0 [-d ARG] [-ufCe] [--] ARGS..."
exit 2
}
# option parsing
source /usr/share/makepkg/util/parseopts.sh || exit
opt_short='C:k:ufFeMnisSw'
opt_long=('repo:' 'upgrades' 'force' 'continue' 'no-mirror' 'no-check'
'no-confirm' 'no-ninja' 'no-provides' 'keep-going:' 'chdir:' 'ignore:'
'search' 'info' 'fetch' 'merge' 'rebase' 'reset' 'ff' 'fm' 'no-dialog')
if ! parseopts "$opt_short" "${opt_long[@]}" -- "$@"; then
usage
fi
set -- "${OPTRET[@]}"
# TODO: --init, --margs, -R/--remove (aur-remove), --gc (aur-gc), -D/--vcsupgrade,
# --rebuild (sync-rebuild), --no-ver, --discard, --foreign, --upgrades, --print
unset repo_args sync_args build_dir
while true; do
case $1 in
-i|--info)
info_only=1 ;;
-s|--search)
search_only=1 ;;
-F|--fetch)
fetch_only=1 ;;
# XXX: long option (pacman -w/--downloadonly)
-w)
view_only=1 ;;
-C|--chdir)
shift; build_dir=$1 ;;
--repo)
shift; repo_args+=(-d "$1") ;;
--merge)
fetch_args+=("$1") ;;
--rebase|--reset|--ff)
fetch_args+=("$1"); sync_args+=("$1") ;;
-f|--force)
build_args+=(-f); sync_args+=(-f --no-ver-argv) ;;
-n|--no-confirm)
build_args+=(-n) ;;
--no-check)
build_args+=(--no-check); sync_args+=(--no-check) ;;
# XXX: replace with -X, --runtx (pkgbuilder)
-e|--continue)
sync_args+=(--continue) ;;
-u|--upgrades)
upgrades=1; sync_args+=(-u) ;;
--ignore)
shift; sync_args+=(--ignore "$1") ;;
--no-provides)
sync_args+=(--no-provides) ;;
--no-mirror)
use_mirror=0 ;;
--no-ninja)
use_ninja=0 ;;
--no-dialog)
use_dialog=0 ;;
--fm)
use_default_fm=1 ;;
--) shift; break ;;
esac
shift
done
if ! (( $# + upgrades )); then
usage
fi
# use separate source directories for --mirror by default
if (( use_mirror )); then
export AURDEST=${AURDEST:-$XDG_CACHE_HOME/aurutils/sync-mirror}
export AUR_FETCH_USE_MIRROR=1
else
export AURDEST=${AURDEST:-$XDG_CACHE_HOME/aurutils/sync}
export AUR_FETCH_USE_MIRROR=0
fi
if (( use_default_fm )); then
unset AUR_PAGER
else
export AUR_PAGER=${AUR_PAGER:-aurum-view-delta}
fi
if [[ -v build_dir ]] && cd -- "$build_dir"; then
# command-line directory takes precedence over AURDEST/--mirror
# XXX: if build_dir is unset, cd -- "$AURDEST" is not run
export AURDEST=$build_dir
elif [[ -v build_dir ]]; then
exit 1
fi
# exclusive modes
if (( search_only )); then
aur search "$@"
exit $?
elif (( info_only )); then
aur search --info "$@"
exit $?
elif (( fetch_only )) && (( ! upgrades )); then
aur fetch --recurse "${fetch_args[@]}" "$@"
exit $?
fi
# set up scratch space
tmp=$(mktemp -d --tmpdir "aurum-$UID.XXXXXXXX")
if [[ ! -v AUR_DEBUG ]]; then
trap 'rm -rf "$tmp"' EXIT
fi
# retrieve local repository information
{ IFS=: read -r _ db_name
IFS=: read -r _ db_root
IFS=: read -r _ _
} < <(aur repo "${repo_args[@]}" --status)
wait "$!" || exit
# retrieve sources for upgrades (-Fu)
if (( fetch_only )) && (( upgrades )); then
aur repo -d "$db_name" -u | aur fetch "${fetch_args[@]}" /dev/stdin
exit $?
fi
# retrieve and inspect sources in AURDEST
# XXX: --no-build contains absolute paths, --columns only package names
env -u AUR_CONFIRM_PAGER aur sync --no-build "${sync_args[@]}" "$@" \
--database "$db_name" --root "$db_root" \
--exclude ':!*.SRCINFO' --exclude ':!*.gitignore' --prefix >"$tmp"/queue || exit
if [[ ! -s $tmp/queue ]]; then
exit 0 # nothing to do (aur-sync -u with no available upgrades)
elif (( view_only )); then
cat >&2 "$tmp"/queue
exit 0
# print summary and confirmation for build queue
# if AUR_CONFIRM_PAGER=0 is set in the environment, respect it
elif (( ! use_default_fm )) && (( ${AUR_CONFIRM_PAGER:-1} )) && (( use_dialog )); then
dialog_text=$(printf '%s\n' 'Continue with build process?' \
'─────────────────────────────────' \
"$(xargs -a "$tmp"/queue basename -a)")
if ! dialog --title 'aurum' --yesno "$dialog_text" 10 40; then
clear; printf >&2 '%s: build process aborted by user\n' "$argv0"
exit 1
fi
clear # remove dialog background
# if --no-dialog is supplied, use a regular `read` prompt
elif (( ! use_default_fm )) && (( ${AUR_CONFIRM_PAGER:-1} )); then
read -rp $'Press Return to continue or Ctrl+d to abort\n' || exit
fi
# build packages in dependency order
# XXX: ninja support copied from aur-sync, move to seperate helper/util
build_args+=(-d "$db_name" -r "$db_root" -U "$USER")
if (( use_ninja )); then
printf >&2 '%s: function not implemented\n' "$argv0"
exit 38
# mkdir -p -- "$XDG_STATE_HOME"/$argv0
# ninja_dir=$XDG_STATE_HOME/$argv0/ninja-$USER-$$
# mkdir -- "$ninja_dir"
# # generate build.ninja
# cd -- "$ninja_dir"
# # XXX: build.ninja does not run outside `aurum` (AURUM_LIB_DIR set in PATH)
# aur sync--ninja "$AURDEST" <"$tmp" >build.ninja -- build-asroot "${build_args[@]}"
# TODO: ninja -k ...
else
# XXX: dependency order is recomputed
#tsort "$tmp"/graph >"$tmp"/queue
aurum-build-asroot "${build_args[@]}" -a "$tmp"/queue || exit
fi