setup-ntp.in 1.08 KB
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 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
install_ntpchoice() {
	if [ "$1" = "none" ]; then
		exit 0
	elif [ "$1" = "chrony" ]; then
		if [ "$acfinstalled" != "ERROR:" ]; then
			apk add acf-chrony -q
		else
			apk add chrony -q
		fi
		
		echo "10 chronypass" > /etc/chrony/chrony.keys
	
		/etc/init.d/chronyd start
		rc-update add chronyd default
	elif [ "$1" = "openntpd" ]; then		
		apk add openntpd -q
		/etc/init.d/ntpd start
		rc-update add ntpd default
	fi
}

while getopts "hc:" opt; do
42
        case $opt in
43
                c) ntpchoice="$OPTARG";;
44 45 46 47 48
		h) usage;;
        esac
done

acfinstalled="`apk version acf-core -q | awk '{print $1}'`"
49 50 51 52 53 54 55

if [ -n "$ntpchoice" ]; then
	install_ntpchoice "$ntpchoice"
else
        echo "Which NTP service would you like to use? (openntpd, chrony, none) [openntpd]"
        default_read ntpchoice "openntpd"
	install_ntpchoice "$ntpchoice"
56
fi