setup-ntp.in 844 Bytes
Newer Older
1 2 3 4 5 6 7
#!/bin/sh

PREFIX=

. "$PREFIX/lib/libalpine.sh"

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

11
		Setup NTP time synchronization
12

13 14 15 16
		options:
		 -h  Show this help
		 -c  Choice of NTP daemon: busybox openntpd chrony none
	__EOF__
17
	exit 1
18 19
}

20
while getopts "hc:" opt; do
21 22
	case $opt in
		c) ntpchoice="$OPTARG";;
23
		h) usage;;
24
	esac
25 26
done

Natanael Copa's avatar
Natanael Copa committed
27
if [ -z "$ntpchoice" ]; then
28 29
	echo -n "Which NTP client to run? ('busybox', 'openntpd', 'chrony' or 'none') [chrony] "
	default_read ntpchoice "chrony"
30
fi
Natanael Copa's avatar
Natanael Copa committed
31 32 33 34 35 36 37

pkgs="$ntpchoice"

case "$ntpchoice" in
none|abort)
	exit 0
	;;
38 39 40 41
busybox)
	pkgs=''
	svc=ntpd
	;;
Natanael Copa's avatar
Natanael Copa committed
42 43 44 45 46 47 48
chrony)
	if apk info --installed --quiet acf-core; then
		pkgs="$pkgs acf-chrony"
	fi
	svc=chronyd
	;;
openntpd)
49
	svc=openntpd
Natanael Copa's avatar
Natanael Copa committed
50 51 52
	;;
esac

53
[ -z "$pkgs" ] || apk add --quiet $pkgs
Natanael Copa's avatar
Natanael Copa committed
54 55
rc-update add $svc default
rc-service $svc start