blob: 6d2d6c1602eefbd136288df69230024cb97b4009 (
plain)
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
# parameters and default values
ARCH="i686"
DATE=$(date +%Y.%m.%d)
ISO="archlinux32-${DATE}-${ARCH}.iso"
OUTPUT_DIR="${HOME}/archisos"
#Andreas Baumann (sign) <mail@andreasbaumann.cc>
SIGN_KEY='16194A82231E9EF823562181C8E8F5A0AF9BA7E7'
# Archlinux 32 Release Key <release@archlinux32.org>
#SIGN_KEY='33CA3597B0D161AAE4173F65C17F1214114574A4'
usage() {
>&2 echo ""
>&2 echo "check-iso: checks sanity of ISOs built for Archlinux32 and returns data about the ISO"
>&2 echo ""
>&2 echo "possible options:"
>&2 echo " -h|--help: show this help and exit"
>&2 echo " --iso name of ISO to be checked, default is '${ISO}'."
>&2 echo " --output-dir where to write the isos, default is '${OUTPUT_DIR}."
>&2 echo " --check check sanity of the image, returns an exit code only."
>&2 echo " --expected-sign-key expected PGP key the ISO has to be signed with, default '${SIGN_KEY}'."
>&2 echo " --md5sum get md5 of the ISO."
>&2 echo " --sha512sum get sha512sum of the ISO."
>&2 echo " --sign-key get GPG signing key of the ISO."
>&2 echo " --size get size of the ISO."
>&2 echo " --kernel-version get version of the kernel on the ISO."
>&2 echo " --no-cleanup do not clean up tmpdir after run, for debugging."
[ -z "$1" ] && exit 1 || exit "$1"
}
# fail on first error
set -e
# cleanup hook
tmp_dir="$(mktemp -d)"
cleanup() {
if mountpoint -q "${tmp_dir}"; then
sudo umount "${tmp_dir}"
fi
rm -rf --one-file-system "${tmp_dir}"
}
trap cleanup EXIT
eval set -- "$(
getopt -o h \
--long help \
--long iso: \
--long output-dir: \
--long check \
--long expected-sign-key: \
--long md5sum \
--long sha512sum \
--long sign-key \
--long size \
--long kernel-version \
-n "$(basename "$0")" -- "$@" || \
echo usage
)"
iso="$ISO"
output_dir="${OUTPUT_DIR}"
check=0
expected_sign_key="${SIGN_KEY}"
md5sum=0
sha512sum=0
sign_key=0
size=0
kernel_version=0
while [ $# -gt 0 ]; do
case "$1" in
'--iso')
shift
iso="$1"
;;
'--output-dir')
shift
output_dir="$1"
;;
'--check')
check=1
;;
'--expected-sign-key')
shift
expected_sign_key="$1"
;;
'--md5sum')
md5sum=1
;;
'--sha512sum')
sha512sum=1
;;
'--sign-key')
sign_key=1
;;
'--size')
size=1
;;
'--kernel-version')
kernel_version=1
;;
'--help'|'-h')
usage 0
;;
'--')
shift
break
;;
*)
printf 'Whoops, option "%s" is not yet implemented!\n' "$1" >&2
exit 42
;;
esac
shift
done
if [ $# -gt 0 ]; then
>&2 echo 'Too many arguments.'
exit 2
fi
if [ "${md5sum}" = 1 ]; then
md5sum="$(
grep "\s${iso/}\$" "${output_dir}/md5sums" | \
awk '{print $1}'
)"
echo "${md5sum}"
fi
if [ "${sha512sum}" = 1 ]; then
sha512sum="$(
grep "\s${iso/}\$" "${output_dir}/sha512sums" | \
awk '{print $1}'
)"
echo "${sha512sum}"
fi
if [ "${sign_key}" = 1 -o "${check}" = 1 ]; then
sign_keys="$(
printf '%s\n' $(
gpg --status-fd=1 --verify "${output_dir}/${iso}.sig" "${output_dir}/${iso}" 2> /dev/null | \
grep '^\[GNUPG:] VALIDSIG [0-9A-F]\+ ' | \
cut -d' ' -f3
) | \
sort -u
)"
if [ $(echo "${sign_keys}" | grep -c '\S') -ne 1 ]; then
>&2 echo 'Not exactly one key used for signing the iso:'
>&2 echo "'${sign_keys}'"
exit 1
fi
sign_key="${sign_keys}"
if [ "${sign_key}" != "${expected_sign_key}" ]; then
>&2 printf "Isos are signed with key '%s' instead of '%s'.\n" \
"${sign_key}" \
"${expected_sign_key}"
exit 1
fi
if [ "${check}" = 0 ]; then
echo "${sign_key}"
fi
fi
if [ "${size}" = 1 ]; then
size="$(
printf 'scale=1; %s/1024/1024\n' "$(stat -c'%s' "${output_dir}/${iso}")" | \
bc
)"
echo "${size}"
fi
if [ "${kernel_version}" = 1 -o "${check}" = 1 ]; then
sudo mount -o loop,ro "${output_dir}/${iso}" "${tmp_dir}"
kernels="$(
printf '%s\n' $(
find "${tmp_dir}/arch" \
-maxdepth 1 \
-name 'pkglist.*.txt' \
-not -name 'pkglist.x86_64.txt' \
-execdir cat {} \; \
| sed '
s/^linux\s\+\([^-]\+-[^-]\+\)$/\1/
t
d
'
) | \
sort -u
)"
sudo umount "${tmp_dir}"
if [ $(echo "${kernels}" | grep -c '\S') -ne 1 ]; then
>&2 echo 'Not exactly one kernel on the iso:'
>&2 echo "${kernels}"
exit 1
fi
kernel_version="${kernels}"
if [ "${check}" = 0 ]; then
echo "${kernel_version}"
fi
fi
exit 0
|