File: buildprep

package info (click to toggle)
ntpsec 1.2.0%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,044 kB
  • sloc: ansic: 60,737; python: 31,610; sh: 1,494; yacc: 1,291; makefile: 176; javascript: 138
file content (342 lines) | stat: -rwxr-xr-x 8,906 bytes parent folder | download | duplicates (2)
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#! /bin/sh
#
# buildprep - prepare your system for an NTPsec source build.
#
# Use the -n option to dry-run this command, showing what would be done
# without actually doing it

# Set the defaults
DRYRUN="no"
NTPVIZ="no"
DOC="no"
PYVERS=""

OS=`uname -s`

# Loop through option flags
for optflag in "$@"
do
	case "$optflag" in
	 -h|--help)
		cat <<EOF
$0 - prepare your system for an NTPsec source build

  Options:
    -h --help    Show usage information and exit
    -n --dry-run Only show what would be done instead of doing it
       --ntpviz  Install dependencies for ntpviz tool
       --doc     Install dependencies for building documentation
    -a --all     Install all possible dependencies
EOF
		exit 0
		;;
	 -n|--dry-run)
		DRYRUN="yes"
		;;
	 --ntpviz)
		NTPVIZ="yes"
		;;
	 --doc)
		DOC="yes"
		;;
	 -a|--all)
		NTPVIZ="yes"
		DOC="yes"
		;;
	 *)
		echo "# WARNING: Unknown argument: $optflag"
		echo "#"
		;;
	esac
done

# Some Python 2 packages (e.g python-devel, python-psutils) conventionally have
# Python 3 equivalents with a python3 prefix.  Compute the correct value for the
# infix based on system Python.  This eill start to be significant after Python 2
# EOLs at the beginning of 2020.
PYVERS=`python --version 2>&1 | sed -n -e '/Python \([0-9]\).*/s//\1/p'`
if [ "$PYVERS" = "2" ]
then
    PYVERS=""
fi

cat <<EOF
# Preparing your system for ntpsec source build...
# This script presently knows about:
#   CentOS, Debian, Fedora, Gentoo, NetBSD, FreeBSD,
$   SLES, Ubuntu, and Alpine Linux
# If you are running something else, such as macOS or Solaris, please
# read the source for this buildprep script to get an idea of what packages
# are required.
#
EOF

if [ "$DRYRUN" = "yes" ]
then
	do=echo
	echo "# Run this without -n|--dry-run, as root, for actual installation."
	echo "#"
else
	do=""
	if [ "$(id -u)" != 0 ]
	then
		echo "# ERROR: You must be running as root for your installer to do its thing."
		echo "# ERROR: If you just wish to see what would be done, use the -n option."
		exit 1
	fi
fi

if emerge --version 2>/dev/null
then
    installer=emerge
    install="$do $installer -q y"
elif yum version 2>/dev/null
then
    installer=yum
    install="$do $installer -y install"
elif dnf --version >/dev/null 2>&1
then
    installer=dnf
    install="$do $installer -y install"
elif apt-get --version >/dev/null 2>&1
then
    installer=apt
    install="$do apt-get install -y"
elif zypper -h >/dev/null 2>&1
then
    # OpenSUSE prefers zypper over yast
    installer=zypper
    install="$do $installer install -y"
elif yast -h >/dev/null 2>&1
then
    installer=yast
    install="$do $installer --install"
elif  apk --version >/dev/null 2>&1
then
    # Alpine Linux, musl rather than glibc
    installer=apk
    install="$do $installer add"
elif test "$OS" = "NetBSD"
then
  if pkgin -v
  then
    # NetBSD binary package installer
    installer=pkgin
    install="$do $installer install"
  else
    echo "## Looks like a NetBSD system"
    echo "## You need to setup pkgin"
    echo "## The last page of install disk has a check-box to do it"
    echo "## But you don't get that option on a Raspberry Pi."
    echo "## For the Pi, do something like:"
    echo "## pkg_add ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/earmv7hf/8.0/All/pkgin-0.9.4nb8.tgz"
    echo "## Adjust the version and arch to match your setup."
    exit 1
  fi
elif test "$OS" = "FreeBSD"
then
  if pkg -v
  then
    # FreeBSD binary package installer
    installer=pkg
    install="$do $installer install"
  fi
else
    echo "# ERROR: Package manager unidentified - Unsupported operating system"
    exit 1
fi
echo "# Your package installer is ${installer}."
echo ""

# In order to have a single point of truth about prerequisite package names,
# these package name lists have been *removed* from INSTALL.

# Build time vs. run time:
# Build dependencies are marked.  You'll need them all when building from a
# repository copy; the unmarked (run-time) dependencies are information for
# packagers.  Under Gentoo, all dependencies are build dependencies.

# Notes on optional packages:
# libdnssd is optional for ntpd. Support for mDNS Service Discovery registration
# libcap (under Linux) enables dropping root and is not strictly required.

daemon () {
    # Prerequisites to build the daemon: bison, pps-tools, service libraries
    case $installer in
	apk)
	    $install build-base python                  # basic tools
	    $install bison python${PYVERS}-dev linux-headers
	    $install openssl-dev libcap-dev libseccomp-dev
	    # probably needs more, but this builds
	    # can't find timepps.h: gpsd and chrony have their own ??
	    ;;
	apt)
	    $install build-essential			# Build environment
	    $install bison libssl-dev			# build
	    $install libcap-dev libseccomp-dev		# build
	    $install libavahi-compat-libdnssd-dev	# optional build
	    $install pps-tools
	    ;;
	emerge)
						# Build environment included!
	    $install sys-libs/libcap sys-libs/libseccomp
	    $install sys-devel/bison net-misc/pps-tools
	    ;;
	pkgin)
	    # NetBSD
	    #  There is nothing magic about 3.7.
	    #  In Dec 2018, 3.6 and 2.7 are also good candidates.
	    $install bison python37 py37-curses-3.7
	    # certificates for NTS
	    $install mozilla-rootcerts mozilla-rootcerts-openssl
	    # Also needs "nts ca /etc/openssl/certs/"
	    # setup "python" from command line
	    $do ln -s /usr/pkg/bin/python3.7 /usr/pkg/bin/python
	    $do ln -s /usr/pkg/bin/python3.7 /usr/pkg/bin/python3
	    # Add to Python search path
	    if [ "$DRYRUN" = "yes" ]
            then
		echo echo /usr/local/lib/python3.7/site-packages \> \\
		echo "  " /usr/pkg/lib/python3.7/site-packages/ntpsec.pth
	    else
		echo /usr/local/lib/python3.7/site-packages > \
			/usr/pkg/lib/python3.7/site-packages/ntpsec.pth
	    fi
	    ;;
	pkg)
	    # FreeBSD
	    $install bison python3
	    $do ln -s /usr/local/bin/python3 /usr/local/bin/python
	    # certificates for NTS
	    $install ca_root_nss
	    ;;
	yum|dnf)
	    $do $installer groupinstall "Development Tools" 	# Build environment
	    $install bison openssl-devel 		# build
	    $install libcap-devel libseccomp-devel	# build
	    $install pps-tools-devel			# build
	    $install avahi-compat-libdns_sd-devel	# optional build
	    $install libcap openssl-libs pps-tools
	    ;;
	yast)
	    echo "# SLES versions 12 and earlier do not have pps-tools"
	    $install basis-devel 			# Build environment
	    $install libcap-devel libseccomp-devel 	# build
	    $install openssl-devel			# build
	    $install libcap2 openssl-libs
	    $install python${PYVERS}-curses
	    ;;
	zypper)
	    $install -t pattern devel_basis		# Build environment
	    $install bison				# build
	    $install libcap-devel libseccomp-devel	# build
	    $install openssl-devel			# build
	    echo "# SLES versions 12 and earlier do not have pps-tools"
	    $install pps-tools-devel			# build
	    $install pps-tools
	    $install libcap2 openssl-libs
	    $install python${PYVERS}-curses
	    ;;
    esac
}

tools () {
    # Prerequisites for the client Python tools: python extensions
    case $installer in
	apt)
	    $install python${PYVERS}-dev
	    ;;
	yum|dnf|yast|zypper)
	    $install python${PYVERS}-devel
	    ;;
    esac
}

ntpviz () {
    # Prerequisites to use ntpviz: gnuplot and liberation fonts
    case $installer in
	apk)
	    $install gnuplot || echo "# You need to enable the community repository"
	    $install ttf-liberation
	    ;;
	apt)
	    distro=`lsb_release -i -s`
	    if [ "$distro" = "Ubuntu" ]
	    then
		echo "# Looks like an Ubuntu system"
		$install gnuplot5
	    else
		echo "# Looks like a generic Debian system"
		$install gnuplot
	    fi
	    $install fonts-liberation python${PYVERS}-psutil
	    ;;
	emerge)
	    $install sci-visualization/gnuplot
	    $install media-fonts/liberation-fonts
	    ;;
	yum|dnf)
	    $install gnuplot
	    $install liberation-fonts-common.noarch
	    $install liberation-mono-fonts.noarch
	    $install liberation-narrow-fonts.noarch
	    $install liberation-sans-fonts.noarch
	    $install liberation-serif-fonts.noarch
	    ;;
	yast|zypper)
	    $install gnuplot liberation-fonts
	    ;;
    esac
}

doc () {
	# prerequisites to build documentation
	case $installer in
	 apk)
		$install asciidoc
		;;
	 apt)
		$install asciidoc
		;;
	 emerge)
		$install app-text/asciidoc
		;;
	 yum|dnf)
		echo "# Please check that your asciidoc is at least 8.6.0"
		echo "# You may need to enable EPEL repositories"
		$install asciidoc
		;;
	 pkgin)
		$install asciidoc
		;;
	 pkg)
		$install asciidoc
		;;
	 yast|zypper)
		$install asciidoc
		;;
	esac
}

# Main sequence
daemon
tools

if [ "$NTPVIZ" = "yes" ]
then
	ntpviz
else
	echo ""
	echo "# Skipping ntpviz dependencies [--ntpviz]"
fi

if [ "$DOC" = "yes" ]
then
	doc
else
	echo ""
	echo "# Skipping documentation dependencies [--doc]"
fi

echo ""
echo "# Done."