diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-13 09:16:58 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2022-05-13 15:52:55 +0200 |
commit | 3dbbe145c7eb4eb0d5fec75f10ebf063c0d40151 (patch) | |
tree | d3da75471cbbc68464203d166756d622f944a280 /setup-ntp.in | |
parent | 64b0a5dfab682b68231fe1d0da0534398f7b7ba4 (diff) | |
download | alpine-conf-3dbbe145c7eb4eb0d5fec75f10ebf063c0d40151.zip |
setup-ntp: fix usage, and drop -c option
Let -h return success instead of error.
Send usage help to stderr on errors.
Use argument instead of option to set the NTP client non-interactivey
and make sure it doesn't block.
Give proper error message if uinsupported client is specified
Diffstat (limited to 'setup-ntp.in')
-rw-r--r-- | setup-ntp.in | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/setup-ntp.in b/setup-ntp.in index 6438e25..502aa4a 100644 --- a/setup-ntp.in +++ b/setup-ntp.in @@ -6,13 +6,14 @@ PREFIX=@PREFIX@ usage() { cat >&$(( $1 + 1 ))<<-__EOF__ - usage: setup-ntp [-h] [-c choice of NTP daemon] + usage: setup-ntp [-h] [busybox|openntpd|chrony|none] Setup NTP time synchronization options: -h Show this help - -c Choice of NTP daemon: busybox openntpd chrony none + + User is prompted if no NTP daemon is specified __EOF__ exit $1 } @@ -24,32 +25,39 @@ while getopts "hc:" opt; do '?') usage 1;; esac done +shift $(( $OPTIND - 1 )) + +resp=$1 -while ! isin "$resp" busybox openntpd chrony none abort; do +while [ $# -eq 0 ] && ! isin "$resp" busybox openntpd chrony none abort; do ask "Which NTP client to run? ('busybox', 'openntpd', 'chrony' or 'none')" chrony done pkgs="$resp" case "$resp" 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 - ;; + 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 + ;; + *) + echo "setup-ntp: '$resp' is not a supported NTP client" >&2 + usage 1 + ;; esac -[ -z "$pkgs" ] || apk add --quiet $pkgs -rc-update add $svc default -rc-service $svc start +[ -z "$pkgs" ] || $MOCK apk add --quiet $pkgs +$MOCK rc-update add $svc default +$MOCK rc-service $svc start |