-
Notifications
You must be signed in to change notification settings - Fork 6
/
obsd-update
executable file
·80 lines (66 loc) · 1.77 KB
/
obsd-update
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
#!/bin/sh
set -e
: "${_tgz_dir="/usr/rel"}"
: "${_sha="SHA256"}"
: "${_sha_sig="SHA256.sig"}"
_rel="${2:-"$(uname -r)"}"
_rel_underscore="$(printf '%s' "$_rel" | sed 's/\./_/')"
_rel_nodot="$(printf '%s' "$_rel" | sed 's/\.//')"
: "${_arch="$(uname -m)"}"
__status () {
printf ':: %s\n' "$1" >&2
}
__verify () {
__status "Verifying $1"
signify -C -q -p "/etc/signify/openbsd-${_rel_nodot}-base.pub" -x \
"$_sha_sig" "$1"
}
__dl () {
__status "Downloading $1 for ${_rel} ${_arch}"
ftp -o "$1" \
"$(cat /etc/installurl)/${_rel}/${_arch}/$1" \
>/dev/null
}
__usage () {
cat << EOH
Initialize ${_tgz_dir} with OpenBSD's RELEASE tarballs for ${_rel}
$0 -h|help
$0 fetch [release]
fetch [release] will:
* Download ${_sha} and ${_sha_sig} from the mirrors for [release]
* Validate them with signify(1)
* Download the base, game, comp, man tarballs
* Download the bsd bsd.mp bsd.rd tarballs
* Validate everything with signify(1)
EOH
}
case "$1" in
-h|help)
__usage
;;
fetch)
cd "$_tgz_dir"
: > "${_sha}"
: > "${_sha_sig}"
# We download both SHA256.sig and SHA256 as base of truth
for _h in "${_sha}" "${_sha_sig}"; do
__dl "$_h"
done
# Check SHA256 against known signature keys (on current system)
__status "Checking ${_sha} and ${_sha_sig}"
signify -V -q -x "${_sha_sig}" \
-p "/etc/signify/openbsd-${_rel_nodot}-base.pub" -m "${_sha}"
# We download the archives until signify checks out
for _f in base${_rel_nodot}.tgz game${_rel_nodot}.tgz \
comp${_rel_nodot}.tgz man${_rel_nodot}.tgz bsd bsd.mp bsd.rd; do
while ! __verify "$_f"; do
__dl "$_f"
done
done
__status "Now: https://www.openbsd.org/faq/upgrade${_rel_nodot}.html"
;;
*)
__usage >&2
exit 5
;;
esac