commit | author | age
|
00a98f
|
1 |
#!/bin/bash |
C |
2 |
|
|
3 |
function newest_matching_file |
|
4 |
{ |
|
5 |
# Use ${1-} instead of $1 in case 'nounset' is set |
|
6 |
local -r glob_pattern=${1-} |
|
7 |
|
|
8 |
if (( $# != 1 )) ; then |
|
9 |
echo 'usage: newest_matching_file GLOB_PATTERN' >&2 |
|
10 |
return 1 |
|
11 |
fi |
|
12 |
|
|
13 |
# To avoid printing garbage if no files match the pattern, set |
|
14 |
# 'nullglob' if necessary |
|
15 |
local -i need_to_unset_nullglob=0 |
|
16 |
if [[ ":$BASHOPTS:" != *:nullglob:* ]] ; then |
|
17 |
shopt -s nullglob |
|
18 |
need_to_unset_nullglob=1 |
|
19 |
fi |
|
20 |
|
|
21 |
newest_file= |
|
22 |
for file in $glob_pattern ; do |
|
23 |
[[ -z $newest_file || $file -nt $newest_file ]] \ |
|
24 |
&& newest_file=$file |
|
25 |
done |
|
26 |
|
|
27 |
# To avoid unexpected behaviour elsewhere, unset nullglob if it was |
|
28 |
# set by this function |
|
29 |
(( need_to_unset_nullglob )) && shopt -u nullglob |
|
30 |
|
|
31 |
# Use printf instead of echo in case the file name begins with '-' |
|
32 |
[[ -n $newest_file ]] && printf '%s\n' "$newest_file" |
|
33 |
|
|
34 |
return 0 |
|
35 |
} |
|
36 |
|
|
37 |
for d in 'emacs-git' |
|
38 |
do |
|
39 |
cd $d |
|
40 |
git pull |
|
41 |
makepkg |
|
42 |
latest=$(newest_matching_file '*.pkg.tar.xz') |
|
43 |
cd .. |
|
44 |
repo-add ./repo.db.tar.xz $d/$latest |
|
45 |
done |
|
46 |
|