ntp.util: Fix rpeers mode in PeerSummary.summary
[ntpsec.git] / buildprep
blobb038dee078f7f9b29d59cf3e74a02e12fac6bba9
1 #! /bin/sh
3 # Copyright the NTPsec project contributors
5 # SPDX-License-Identifier: BSD-2-Clause
8 # buildprep - prepare your system for an NTPsec source build.
10 # Use the -n option to dry-run this command, showing what would be done
11 # without actually doing it
13 # Set the defaults
14 DRYRUN="no"
15 NTPVIZ="no"
16 DOC="no"
17 UPDATE="no"
18 PYVERS=""
20 OS=$(uname -s)
22 # Loop through option flags
23 for optflag in "$@"
25 case "$optflag" in
26 -h|--help)
27 cat <<EOF
28 $0 - prepare your system for an NTPsec source build
30 Options:
31 -h --help Show usage information and exit
32 -n --dry-run Only show what would be done instead of doing it
33 --ntpviz Install dependencies for ntpviz tool
34 --doc Install dependencies for building documentation
35 --update Update package repositories
36 -a --all Install all possible dependencies
37 EOF
38 exit 0
40 -n|--dry-run)
41 DRYRUN="yes"
43 --ntpviz)
44 NTPVIZ="yes"
46 --doc)
47 DOC="yes"
49 -a|--all)
50 NTPVIZ="yes"
51 DOC="yes"
53 --update)
54 UPDATE="yes"
57 echo "# WARNING: Unknown argument: $optflag"
58 echo "#"
60 esac
61 done
63 # Some Python 2 packages (e.g python-devel, python-psutils) conventionally have
64 # Python 3 equivalents with a python3 prefix. Compute the correct value for the
65 # infix based on system Python. This eill start to be significant after Python 2
66 # EOLs at the beginning of 2020.
67 PYVERS=$(python --version 2>&1 | sed -n -e '/Python \([0-9]\).*/s//\1/p')
68 if [ "$PYVERS" = "2" ]
69 then
70 PYVERS=""
73 cat <<EOF
74 # Preparing your system for ntpsec source build...
75 # This script presently knows about:
76 # CentOS, Debian, Fedora, Gentoo, NetBSD, FreeBSD,
77 $ SLES, Ubuntu, and Alpine Linux
78 # If you are running something else, such as macOS or Solaris, please
79 # read the source for this buildprep script to get an idea of what packages
80 # are required.
82 EOF
84 if [ "$DRYRUN" = "yes" ]
85 then
86 do="echo"
87 echo "# Run this without -n|--dry-run, as root, for actual installation."
88 echo "#"
89 else
90 do=""
91 if [ "$(id -u)" != 0 ]
92 then
93 echo "# ERROR: You must be running as root for your installer to do its thing."
94 echo "# ERROR: If you just wish to see what would be done, use the -n option."
95 exit 1
99 if emerge --version 2>/dev/null
100 then
101 installer=emerge
102 install="$do $installer -q y"
103 elif yum version 2>/dev/null
104 then
105 installer=yum
106 install="$do $installer -y install"
107 elif dnf --version >/dev/null 2>&1
108 then
109 installer=dnf
110 install="$do $installer -y install"
111 elif apt-get --version >/dev/null 2>&1
112 then
113 installer=apt
114 install="$do apt-get install -y"
115 elif zypper -h >/dev/null 2>&1
116 then
117 # OpenSUSE prefers zypper over yast
118 installer=zypper
119 install="$do $installer install -y"
120 elif yast -h >/dev/null 2>&1
121 then
122 installer=yast
123 install="$do $installer --install"
124 elif apk --version >/dev/null 2>&1
125 then
126 # Alpine Linux, musl rather than glibc
127 installer=apk
128 install="$do $installer add"
129 elif test "$OS" = "NetBSD"
130 then
131 if pkgin -v
132 then
133 # NetBSD binary package installer
134 installer=pkgin
135 install="$do $installer install"
136 else
137 echo "## Looks like a NetBSD system"
138 echo "## You need to setup pkgin"
139 echo "## The last page of install disk has a check-box to do it"
140 echo "## But you don't get that option on a Raspberry Pi."
141 echo "## For the Pi, do something like:"
142 echo "## pkg_add ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/earmv7hf/8.0/All/pkgin-0.9.4nb8.tgz"
143 echo "## Adjust the version and arch to match your setup."
144 exit 1
146 elif test "$OS" = "FreeBSD"
147 then
148 if pkg -v
149 then
150 # FreeBSD binary package installer
151 installer=pkg
152 install="$do $installer install"
154 else
155 echo "# ERROR: Package manager unidentified - Unsupported operating system"
156 exit 1
158 echo "# Your package installer is ${installer}."
159 echo ""
161 # In order to have a single point of truth about prerequisite package names,
162 # these package name lists have been *removed* from INSTALL.
164 # Build time vs. run time:
165 # Build dependencies are marked. You'll need them all when building from a
166 # repository copy; the unmarked (run-time) dependencies are information for
167 # packagers. Under Gentoo, all dependencies are build dependencies.
169 # Notes on optional packages:
170 # libdnssd is optional for ntpd. Support for mDNS Service Discovery registration
171 # libcap (under Linux) enables dropping root and is not strictly required.
173 daemon () {
174 # Prerequisites to build the daemon: bison, pps-tools, service libraries
175 case $installer in
176 apk)
177 $install build-base python # basic tools
178 $install bison "python${PYVERS}-dev" linux-headers
179 $install openssl-dev libcap-dev libseccomp-dev
180 # probably needs more, but this builds
181 # can't find timepps.h: gpsd and chrony have their own ??
183 apt)
184 $install build-essential # Build environment
185 $install bison libssl-dev # build
186 $install libcap-dev libseccomp-dev # build
187 $install libavahi-compat-libdnssd-dev # optional build
188 $install pps-tools
189 $install python3-dev python-is-python3
191 emerge)
192 # Build environment included!
193 $install sys-libs/libcap sys-libs/libseccomp
194 $install sys-devel/bison net-misc/pps-tools
196 pkgin)
197 # NetBSD
198 # There is nothing magic about 3.7.
199 # In Dec 2018, 3.6 and 2.7 are also good candidates.
200 $install bison python37 py37-curses-3.7
201 # certificates for NTS
202 $install mozilla-rootcerts mozilla-rootcerts-openssl
203 # Also needs "nts ca /etc/openssl/certs/"
204 # setup "python" from command line
205 $do ln -s /usr/pkg/bin/python3.7 /usr/pkg/bin/python
206 $do ln -s /usr/pkg/bin/python3.7 /usr/pkg/bin/python3
207 # Add to Python search path
208 if [ "$DRYRUN" = "yes" ]
209 then
210 echo echo /usr/local/lib/python3.7/site-packages \> \\
211 echo " " /usr/pkg/lib/python3.7/site-packages/ntpsec.pth
212 else
213 echo /usr/local/lib/python3.7/site-packages > \
214 /usr/pkg/lib/python3.7/site-packages/ntpsec.pth
217 pkg)
218 # FreeBSD
219 $install bison python3
220 $do ln -s /usr/local/bin/python3 /usr/local/bin/python
221 # certificates for NTS
222 $install ca_root_nss
224 yum|dnf)
225 $do $installer groupinstall "Development Tools" # Build environment
226 $install bison openssl-devel # build
227 $install libcap-devel libseccomp-devel # build
228 $install pps-tools-devel # build
229 $install avahi-compat-libdns_sd-devel # optional build
230 $install libcap openssl-libs pps-tools
232 yast)
233 echo "# SLES versions 12 and earlier do not have pps-tools"
234 $install basis-devel # Build environment
235 $install libcap-devel libseccomp-devel # build
236 $install openssl-devel # build
237 $install libcap2 openssl-libs
238 $install "python${PYVERS}-curses"
240 zypper)
241 $install -t pattern devel_basis # Build environment
242 $install bison # build
243 $install libcap-devel libseccomp-devel # build
244 $install openssl-devel # build
245 echo "# SLES versions 12 and earlier do not have pps-tools"
246 $install pps-tools-devel # build
247 $install pps-tools
248 $install libcap2 openssl-libs
249 $install "python${PYVERS}-curses"
251 esac
254 tools () {
255 # Prerequisites for the client Python tools: python extensions
256 case $installer in
257 apt)
258 $install "python${PYVERS}-dev"
260 yum|dnf|yast|zypper)
261 $install "python${PYVERS}-devel"
263 esac
266 ntpviz () {
267 # Prerequisites to use ntpviz: gnuplot and liberation fonts
268 case $installer in
269 apk)
270 $install gnuplot || echo "# You need to enable the community repository"
271 $install ttf-liberation
273 apt)
274 distro=$(lsb_release -i -s)
275 if [ "$distro" = "Ubuntu" ]
276 then
277 echo "# Looks like an Ubuntu system"
278 $install gnuplot5
279 else
280 echo "# Looks like a generic Debian system"
281 $install gnuplot
283 $install fonts-liberation "python${PYVERS}-psutil"
285 emerge)
286 $install sci-visualization/gnuplot
287 $install media-fonts/liberation-fonts
289 yum|dnf)
290 $install gnuplot
291 $install liberation-fonts-common.noarch
292 $install liberation-mono-fonts.noarch
293 $install liberation-narrow-fonts.noarch
294 $install liberation-sans-fonts.noarch
295 $install liberation-serif-fonts.noarch
297 yast|zypper)
298 $install gnuplot liberation-fonts
300 esac
303 doc () {
304 # prerequisites to build documentation
305 case $installer in
306 apk)
307 $install asciidoc
309 apt)
310 $install asciidoc
312 emerge)
313 $install app-text/asciidoc
315 yum|dnf)
316 echo "# Please check that your asciidoc is at least 8.6.0"
317 echo "# You may need to enable EPEL repositories"
318 $install asciidoc
320 pkgin)
321 $install asciidoc
323 pkg)
324 $install asciidoc
326 yast|zypper)
327 $install asciidoc
329 esac
332 update() {
333 # prerequisites to build documentation
334 case $installer in
335 emerge)
336 $do $installer --sync
338 apk|pkg|pkgin|yum)
339 $do $installer update
341 dnf)
342 $do $installer distro-sync
344 apt)
345 $do $installer-get update
347 zypper)
348 $do $installer-get refresh
350 esac
353 if [ "$UPDATE" = "yes" ]
354 then
355 update
356 else
357 echo ""
358 echo "# Skipping update of package repositories [-u] [--update]"
361 # Main sequence
362 daemon
363 tools
365 if [ "$NTPVIZ" = "yes" ]
366 then
367 ntpviz
368 else
369 echo ""
370 echo "# Skipping ntpviz dependencies [--ntpviz]"
373 if [ "$DOC" = "yes" ]
374 then
376 else
377 echo ""
378 echo "# Skipping documentation dependencies [--doc]"
381 echo ""
382 echo "# Done."