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

PREFIX=

. "$PREFIX/lib/libalpine.sh"

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

Setup NTP time synchronization

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

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

Natanael Copa's avatar
Natanael Copa committed
27
if [ -z "$ntpchoice" ]; then
28
        echo -n "Which NTP client to run? ('openntpd', 'chrony' or 'none') [chrony] "
Natanael Copa's avatar
Natanael Copa committed
29
        default_read ntpchoice "chrony"
30
fi
Natanael Copa's avatar
Natanael Copa committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

pkgs="$ntpchoice"

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

49
apk add --quiet $pkgs
Natanael Copa's avatar
Natanael Copa committed
50 51 52
rc-update add $svc default
rc-service $svc start