-
Notifications
You must be signed in to change notification settings - Fork 6
/
obsd-src
executable file
·131 lines (109 loc) · 3.06 KB
/
obsd-src
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
#!/bin/sh
#set -x
set -e
: "${_src_dir="/usr/src"}"
: "${_tgz_dir="/usr/rel"}"
: "${_src_tgz="src.tar.gz"}"
: "${_sys_tgz="sys.tar.gz"}"
: "${_sha="SHA256"}"
: "${_sha_sig="SHA256.sig"}"
: "${_jobs="$(($(sysctl -n hw.ncpu) - 1))"}"
_rel="${2:-"$(uname -r)"}"
_rel_underscore="$(printf '%s' "$_rel" | sed 's/\./_/')"
_rel_nodot="$(printf '%s' "$_rel" | sed 's/\.//')"
__usage () {
cat << EOH
Update or initialize ${_src_dir} with OpenBSD's source.
$0 -h|help
$0 init [rel]
$0 deflate [rel]
$0 update [rel]
init [rel] will:
check for presence of the $_rel src and sys archives in ${_tgz_dir};
validate them (signify);
deflate [rel] will:
clean ${_src_dir};
decompress the $_rel tarballs;
update [rel] will:
cd to ${_src_dir};
launch the CVS command to follow -stable (OPENBSD_$_rel_underscore).
>> Don't forget to set \$CVSROOT
$CVSROOT
EOH
}
__status () {
printf ':: %s\n' "$1"
}
__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}"
ftp -o "$1" \
"https://mirrors.evowise.com/pub/OpenBSD/${_rel}/$1" >/dev/null
}
case "$1" in
-h|help)
__usage ; exit 0
;;
init)
cd "$_tgz_dir"
: > "${_sha}"
: > "${_sha_sig}"
# We download both SHA256 and SHA256.sig to avoid endless loops if we get
# a broken SHA256.sig
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 _tgz in "${_src_tgz}" "${_sys_tgz}"; do
while ! __verify "$_tgz"; do
__dl "$_tgz"
done
done
;;
deflate)
cd "$_tgz_dir"
__verify "$_src_tgz"
__verify "$_sys_tgz"
__status "Cleaning up $_src_dir, this might take a while"
rm -r "${_src_dir:?}"/*
__status "Deflating $_src_tgz"
mkdir -p "$_src_dir"
tar xzf "$_src_tgz" -C "$_src_dir"
__status "Deflating $_sys_tgz"
tar xzf "$_sys_tgz" -C "$_src_dir"
;;
update)
cd "$_src_dir"
# cvs will fail if there is no CVSROOT specified
# example: CVSROOT=anoncvs@anoncvs.fr.openbsd.org:/cvs <command>
# list of CVSROOTs that could work: https://www.openbsd.org/anoncvs.html#CVSROOT
cvs -q up -rOPENBSD_"${_rel_underscore}" -Pd
;;
build)
_start="$(date "+%s")"
__status "Cleaning up /usr/obj, this might take a while"
rm -rf /usr/obj/*
__status "Making obj"
cd "${_src_dir}"
make obj >/dev/null
__status "Making distrib-dirs"
cd "${_src_dir}"/etc
env DESTDIR=/ make distrib-dirs >/dev/null
__status "Making build ($_jobs jobs)"
cd "${_src_dir}"
make -j"${_jobs}" build >/dev/null
_stop="$(date "+%s")"
__status "Build finished: $(date -r $_start) to $(date -r $_stop)"
;;
*)
__usage >&2 ; exit 5
;;
esac