aboutsummaryrefslogtreecommitdiffstats
path: root/setup-ntp.in
blob: c88e48655dff85ba443c8cacaa2c630b87167bd7 (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
#!/bin/sh

PREFIX=

. "$PREFIX/lib/libalpine.sh"

usage() {
	cat <<-__EOF__
		usage: setup-ntp [-h] [-c choice of NTP daemon]

		Setup NTP time synchronization

		options:
		 -h  Show this help
		 -c  Choice of NTP daemon: busybox openntpd chrony none
	__EOF__
	exit 1
}

while getopts "hc:" opt; do
	case $opt in
		c) ntpchoice="$OPTARG";;
		h) usage;;
	esac
done

if [ -z "$ntpchoice" ]; then
	echo -n "Which NTP client to run? ('busybox', 'openntpd', 'chrony' or 'none') [chrony] "
	default_read ntpchoice "chrony"
fi

pkgs="$ntpchoice"

case "$ntpchoice" in
none|abort)
	exit 0
	;;
busybox)
	pkgs=''
	svc=ntpd
	;;
chrony)
	if apk info --installed --quiet acf-core; then
		pkgs="$pkgs acf-chrony"
	fi
	svc=chronyd
	;;
openntpd)
	svc=openntpd
	;;
esac

[ -z "$pkgs" ] || apk add --quiet $pkgs
rc-update add $svc default
rc-service $svc start