-
Notifications
You must be signed in to change notification settings - Fork 10
/
void-updates.sh
executable file
·183 lines (154 loc) · 3 KB
/
void-updates.sh
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
#!/bin/sh
set -e
init_src() {
if ! [ -d $src/.git ]; then
mkdir -p $src
git clone -q $repo $src
fi
}
update_src() {
printf "updating clone\n"
GIT_WORK_TREE=$src GIT_DIR=$src/.git git pull -q
printf "update complete\n"
}
is_meta() {
(
cd $src
./xbps-src show $1 | grep -q '^build_style:[[:blank:]]*meta$'
)
}
has_distfiles() {
(
cd $src
./xbps-src show $1 | grep -q '^distfiles:'
)
}
is_versioned() {
case $1 in
*-git) return 1;;
esac
return 0
}
find_pkgs() {
local f p
for f in $src/srcpkgs/*; do
p=$(basename $f)
if [ ! -h $f ] &&
[ -f $f/template ] &&
! is_meta $p &&
has_distfiles $p &&
is_versioned $p; then
printf -- '%s\n' $p
fi
done
}
get_var() {
grep ^$2= $src/srcpkgs/$1/template | cut -d= -f2- | tr -d "\"'"
}
add_maintainer() {
local p m
while IFS= read -r p; do
m=$(get_var $p maintainer | awk -F\< '{ print $2 }' | tr -d '> ')
if [ "$m" ]; then
printf '%s %s\n' $p $dest/updates_$m.txt
fi
done
}
get_date() {
local f=$1
local p=$2
local v="$3"
local lookback=30
local i dt pf
for i in $(seq $lookback -1 0); do
dt=$(date --date="-$i days" +%Y-%m-%d)
pf=$out/${name}_$dt/$f
[ -f $pf ] || continue
if fgrep -q "$p $v" $pf; then
if [ $lookback -ne $i ]; then
printf '%s' $dt
fi
return 0
fi
done
}
add_date() {
local f=$1
local p v
while read -r p v; do
printf '%s\t%s\t%s\n' $p "$v" "$(get_date $f $p "$v")"
done
}
add_homepage() {
local p v
while read -r p v; do
printf '%s\t%s\t%s\n' $p "$v" "$(get_var $p homepage)"
done
}
parallel_check() {
printf "beginning checks\n"
xargs -P$procs -L1 /bin/sh -c "
(cd $src && ./xbps-src update-check \$0) |
sed -e \"s|\$0-||g\" -e \"s|^|\$0 |\" >> \$1
"
}
create_summary() {
local f m
{
for f in $dest/updates_*.txt; do
if [ -s $f ]; then
m=$(basename ${f%%.txt} | sed 's/updates_//')
printf '%s\n%s\n' $m $(printf %${#m}s |tr ' ' -)
sort $f | add_date $(basename $f) | add_homepage | column -t -s"$(printf '\t')"
printf -- '\n'
else
rm -f $f
fi
done
} > $dest.txt
}
create_heading() {
local d=$(($end - $start))
local t="Void Updates for $(date +%Y-%m-%d\ %H:%M\ %Z) (took: ${d}s)"
local s
s=$(printf %${#t}s |tr ' ' =)
sed -e "1s/^/$s\n\n/" -e "1s/^/$t\n/" -i $dest.txt
}
make_current() {
ln -vsf ${dest##*/}.txt $out/$name.txt
ln -vsfn ${dest##*/} $out/$name
}
while getopts "p:r:s:o:" opt; do
case $opt in
p)
procs=$OPTARG
;;
r)
repo=$OPTARG
;;
s)
src=$OPTARG
;;
o)
out=$OPTARG
;;
esac
done
[ "$procs" ] || procs=1
[ "$repo" ]
[ "$src" ]
[ "$out" ]
name=$(basename $0)
date=$(date +%Y-%m-%d)
dest=$out/${name}_$date
mkdir -p $dest
{
start=$(date +%s)
init_src
update_src
find_pkgs | add_maintainer | parallel_check
create_summary
end=$(date +%s)
create_heading
make_current
} 2> $dest/_log.txt