-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubcheck
executable file
·208 lines (184 loc) · 6.51 KB
/
githubcheck
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
#!/bin/bash
#
# Check that the github repo has the same package and db files as the given local folder.
#
echo2() { echo "$@" >&2 ; }
DIE() {
echo2 "Error: $1"
exit 1
}
NameCheck() {
local xx yy
for xx in "$@" ; do
for yy in $remotefilelist ; do
test "$xx" = "$yy" && break
done
if [ "$xx" = "$yy" ] ; then
echo2 " OK: $xx"
else
echo2 "file $xx missing from $MIRROR_NAME !"
problemfiles+="$xx "
fi
done
}
ContentsCheck() {
local xx remfiles=""
local failcode=0
sleep 1 # github has problems if fetching fast and repeatedly ???
for xx in "$@" ; do
remfiles+="$MIRROR_URL/$xx "
done
pushd $tmpdir >/dev/null
if false ; then
wget -q --timeout=20 --show-progress $remfiles || failcode=$?
else
curl --location --remote-time --max-time 20 --remote-name-all --progress-bar --fail $remfiles || failcode=$?
fi
popd >/dev/null
if [ $failcode -ne 0 ] ; then
echo2 "Error: fetching github files failed (code $failcode)."
problemfiles+="$remfiles "
return $failcode
fi
for xx in "$@" ; do
cmp $xx $tmpdir/$xx >/dev/null
if [ $? -eq 0 ] ; then
echo2 " OK: $xx"
else
echo2 "file $xx is different !"
problemfiles+="$xx "
fi
rm -f $tmpdir/$xx
done
}
Usage() {
local progname="$(basename $0)"
cat <<EOF >&2
$progname: Check the validity of $SIGNER packages in the $MIRROR_NAME mirror.
Usage: $progname [parameters]
parameters:
--slow Check contents of each file.
--fast Check just the name of all package files.
--optimized Check contents of some files, and names of other files.
--no-filelist Don't generate list of latest files into the repo.
folder-name Name of the local folder that contains package files.
If not given, current folder is used.
EOF
}
Main()
{
if [ 1 -eq 1 ] ; then
if [ ! -r assets.conf ] ; then
DIE "no assets.conf found!"
fi
source assets.conf
local MIRROR_NAME=Github
local MIRROR_URL=""
local findpart=""
if [ -z "$REPO_COMPRESSOR" ] ; then
local REPO_COMPRESSOR=xz
fi
case "$SIGNER" in
EndeavourOS)
case "$REPONAME" in
endeavouros | endeavouros_calamares)
MIRROR_URL=https://github.com/endeavouros-team/mirrors/releases/tag/"${RELEASE_TAGS[0]}"
findpart=/endeavouros-team/mirrors/releases/download/"${RELEASE_TAGS[0]}"/
;;
endeavouros-testing-dev)
MIRROR_URL=https://github.com/endeavouros-team/repo-testing/releases/tag/"${RELEASE_TAGS[0]}"
findpart=/endeavouros-team/repo-testing/releases/download/"${RELEASE_TAGS[0]}"/
;;
*)
DIE "sorry, unsupported repo name '$REPONAME'."
;;
esac
;;
*)
MIRROR_URL=https://github.com/$REPO_OWNER/$REPONAME/releases/tag/"${RELEASE_TAGS[0]}"/
findpart=/$REPO_OWNER/$REPONAME/releases/download/"${RELEASE_TAGS[0]}"/
;;
esac
else
local conf=/etc/eos-mirrorcheck.conf
test -r $conf || DIE "configuration file $conf is required but not found."
source $conf
test -n "$MIRROR_URL" || DIE "variable MIRROR_URL has no value, check file $conf."
test -n "$MIRROR_NAME" || DIE "variable MIRROR_NAME has no value, check file $conf."
fi
local folder=""
local remotefilelist
local packages repofiles
local problemfiles=""
local arg
# options
local mode=fast # show, optimized, fast
local has_filelist=no
for arg in "$@" ; do
case "$arg" in
--2) : # not used anymore
# check mirror2 instead of mirror1
# MIRROR_URL=https://github.com/endeavouros-team/mirrors/releases/tag/"${RELEASE_TAGS[1]}"
# findpart=/endeavouros-team/mirrors/releases/download/"${RELEASE_TAGS[1]}"/
;;
--slow) mode=slow ;;
--fast) mode=fast ;;
--optimized) mode=optimized ;;
--filelist) has_filelist=yes ;; # use repofiles.txt
-*) Usage ; return ;;
*) folder="$arg" ;;
esac
done
test -n "$folder" || folder=.
test -d "$folder" || DIE "folder $folder does not exist!"
# test -r "$folder/endeavouros.db" || {
# echo2 "$(basename $0): nothing to see here."
# return
# }
echo2 "Fetching $MIRROR_NAME package info..."
remotefilelist="$(curl -s "$MIRROR_URL" | grep $findpart | sed -e 's|^.*'$findpart'||' -e 's|" rel=.*$||')"
test -n "$remotefilelist" || DIE "cannot fetch package info from '$MIRROR_URL'."
MIRROR_URL="$(echo "$MIRROR_URL" | sed 's|/tag/|/download/|')"
pushd "$folder" >/dev/null
packages="$(ls -1 *.pkg.tar.*)"
local SigLevel="$(grep -A3 "^\[$REPONAME\]$" /etc/pacman.conf | grep "^SigLevel = " | awk '{print $3}')"
case "$SigLevel" in
Required) repofiles="$(echo $REPONAME.{db,files}{,.tar.$REPO_COMPRESSOR}{,.sig})" ;;
*) repofiles="$(echo $REPONAME.{db,files}{,.tar.$REPO_COMPRESSOR})" ;;
esac
# Check files. 'NameCheck' is very fast but unreliable. 'ContentsCheck' is quite slow but reliable.
local tmpdir=$(mktemp -d)
ContentsCheck $repofiles # This should make sure all is OK ! (?)
if [ "$has_filelist" = "yes" ] ; then
ContentsCheck repofiles.txt
fi
case "$mode" in
fast)
NameCheck $packages
;;
slow)
ContentsCheck $packages
;;
optimized)
for arg in $packages ; do
case "$arg" in
# icon theme packages are very big
paper-icon-theme-*.pkg.tar.xz | paper-icon-theme-*.pkg.tar.zst | \
arc-x-icons-theme-*.pkg.tar.xz | arc-x-icons-theme-*.pkg.tar.zst)
NameCheck "$arg" ;;
*)
ContentsCheck "$arg" ;;
esac
done
;;
esac
rm -rf $tmpdir
if [ -z "$problemfiles" ] ; then
echo2 "No issues."
else
echo2 -n "Problematic files: "
echo $problemfiles
fi
popd >/dev/null
}
Main "$@"