-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_aur
More file actions
executable file
·270 lines (237 loc) · 6.69 KB
/
update_aur
File metadata and controls
executable file
·270 lines (237 loc) · 6.69 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
#
# Update and install AUR packages.
#
# Dependencies: coreutils, git, pacman, util-linux
set -o nounset -o pipefail
readonly DEFAULT_EXC_FILE="need_manual_intervention"
readonly DEFAULT_EXC_PATTERNS="test_.+,.+_test"
readonly DEFAULT_JOBS=1
readonly DEFAULT_REPO="${HOME}/AUR"
readonly CLR_END="\033[0m" # reset color
readonly CLR_EXC="\033[1;30m" # gray color for exceptions
readonly CLR_UTD="\033[0;32m" # green color for "up-to-date"
readonly L_OPTS="exceptions:,help,jobs:,patterns:,version"
readonly OPTS="e:hj:p:Vv"
readonly CMD="${0##*/}"
readonly USAGE="${CMD} [OPTION]... [REPO]..."
readonly USAGE_ERR_MSG=$(
cat <<END
Usage: ${USAGE}
Try '${CMD} --help' for more information.
END
)
readonly VERSION_INFO=$(
cat <<END
${CMD} (scripts) 1.0.0
This is free and unencumbered software released into the public domain.
For more information, please refer to <https://unlicense.org/>.
END
)
readonly HELP=$(
cat <<END
SYNOPSIS
${USAGE}
DESCRIPTION
Update and install packages in REPOs or ${DEFAULT_REPO}
if REPOs are not specified. The repository must have the following structure:
REPO root
|-- pkg A dir
| |-- pkg AA dir (dependency of pkg A)
| |-- pkg AB dir (dependency of pkg A)
| | |-- pkg ABA dir (dependency of pkg AB)
| | | ...
| | | optional file with exceptions for AB's dirs
| | ...
| | optional file with exceptions for A's dirs
|-- pkg B dir
|-- C dir
| |-- pkg CA dir
| | ...
| | optional file with exceptions for C's dirs
| ...
| optional file with exceptions for root dirs
A pkg differs from a dir in that it contains a PKGBUILD file and a .git dir.
OPTIONS
-e, --exceptions FILE, --exceptions=FILE
rename the exceptions file from '${DEFAULT_EXC_FILE}' to FILE;
files must contain a whitespace-separated list of dir base names
-h, --help
display this help and exit
-j, --jobs N, --jobs=N
make the packages using N jobs instead of ${DEFAULT_JOBS} by default
-p, --patterns PATTERNS, --patterns=PATTERNS
change the comma-separated list of pkg base name regexps
from '${DEFAULT_EXC_PATTERNS}' to PATTERNS
-V, -v, --version
display version and exit
END
)
#######################################
# Check if the directory is a package
# Arguments:
# dir - directory path
#######################################
function is_pkg() {
local -r dir="$1"
[[ -f "${dir}/PKGBUILD" && -d "${dir}/.git" ]]
}
#######################################
# Update the valid non-excluded package
# Globals:
# CLR_END - ANSI escape code for color reset
# CLR_UTD - ANSI escape code for up-to-date pkgs color
# Arguments:
# pkg - package path
# jobs - number of jobs for makepkg
#######################################
function update_pkg() {
local -r pkg="$1"
local -r jobs="$2"
local -r parent_dir="${pkg%/*}"
local dep_string=""
local install_options="--install"
if is_pkg "${parent_dir}"; then
dep_string=" (dependency of the package ${parent_dir})"
install_options+=" --asdeps"
fi
echo "pkg ${pkg}${dep_string}"
cd "${pkg}"
git fetch
if [[ $(git rev-parse HEAD) == $(git rev-parse @{u}) ]]; then
echo -e " ${CLR_UTD}up-to-date${CLR_END}"
else
git pull --autostash --rebase
MAKEFLAGS="-j${jobs}" makepkg "${install_options}" --syncdeps --rmdeps
fi
}
#######################################
# Update each package in the directory
# Globals:
# CLR_END - ANSI escape code for color reset
# CLR_EXC - ANSI escape code for exceptions color
# CLR_UTD - ANSI escape code for up-to-date pkgs color
# Arguments:
# dir - directory path
# exc_filename - filename of the exceptions file
# exc_patterns - excluded patterns
# jobs - number of jobs for makepkg
#######################################
function update_dir() {
local -r dir="$1"
local -r exc_filename="$2"
local -r exc_patterns="$3"
local -r jobs="$4"
local excluded_dirs
{ excluded_dirs=$(<"${dir}/${exc_filename}"); } 2>/dev/null
local subdir
for subdir in "${dir}"/*; do
if ! [[ -d ${subdir} ]]; then
continue
fi
local base="${subdir##*/}"
if [[ ${excluded_dirs} =~ (^|[[:space:]])"${base}"($|[[:space:]]) ]]; then
echo "dir ${subdir}"
echo -e " ${CLR_EXC}excluded by ${dir}/${exc_filename}${CLR_END}"
continue
fi
if is_pkg "${subdir}"; then
for exceptions_pattern in ${exc_patterns//,/ }; do
if grep --line-regexp --quiet "${exceptions_pattern}" <<<"${base}"; then
echo -e " ${CLR_EXC}excluded by '${exceptions_pattern}'${CLR_END}"
continue 2
fi
done
update_dir "${subdir}" "${exc_filename}" "${exc_patterns}" "${jobs}"
update_pkg "${subdir}" "${jobs}"
else
update_dir "${subdir}" "${exc_filename}" "${exc_patterns}" "${jobs}"
fi
done
}
#######################################
# Main function
# Globals:
# CMD - script basename
# DEFAULT_EXC_FILE - default filename of the exceptions file
# DEFAULT_EXC_PATTERNS - default excluded patterns
# DEFAULT_JOBS_NUMBER - default number of jobs for makepkg
# DEFAULT_REPO - default AUR repository path
# HELP - help message
# L_OPTS - long non-positional options (e.g. --help)
# OPTS - short non-positional options (e.g. --h)
# USAGE_ERR_MSG - usage error message
#######################################
function main() {
local opts
opts=$(
getopt \
--options=${OPTS} --longoptions=${L_OPTS} \
--name "${CMD}" \
-- "$@"
)
if (($? != 0)); then
echo "${USAGE_ERR_MSG}"
exit 2
fi
eval set -- "${opts}"
local exc_filename="${DEFAULT_EXC_FILE}"
local exc_patterns="${DEFAULT_EXC_PATTERNS}"
local jobs="${DEFAULT_JOBS}"
local need_help=false
local need_version=false
while true; do
case "$1" in
-e | --exceptions)
exc_filename="$2"
shift 2
;;
-h | --help)
need_help=true
shift
break
;;
-j | --jobs)
jobs="$2"
shift 2
;;
-p | --patterns)
exc_patterns="$2"
shift 2
;;
-V | -v | --version)
need_version=true
shift
break
;;
--)
shift
break
;;
esac
done
if [[ $need_help == true ]]; then
echo "${HELP}"
exit 0
fi
if [[ $need_version == true ]]; then
echo "${VERSION_INFO}"
exit 0
fi
local repo_list
if (($# == 0)); then
repo_list="${DEFAULT_REPO}"
else
while (($# != 0)); do
repo_list+="$1 "
shift
done
fi
local repo
for repo in ${repo_list}; do
local repo_dir
repo_dir=$(realpath --no-symlinks "${repo}")
update_dir "${repo_dir}" "${exc_filename}" "${exc_patterns}" "${jobs}"
done
}
main "$@"