diff --git a/setup-ntp.in b/setup-ntp.in index 6090aac8cf067d9dccc2ec7f436667e9778c5363..739e1b9caf87b8638875c2d2d62d66da4f852292 100644 --- a/setup-ntp.in +++ b/setup-ntp.in @@ -30,6 +30,12 @@ shift $(( $OPTIND - 1 )) : ${resp:=$1} while [ $# -eq 0 ] && ! isin "$resp" busybox openntpd chrony none abort; do + if date -d "$resp" >/dev/null 2>&1; then + $MOCK date -s "$resp" + else + # display current time before asking for NTP client + date + fi ask "Which NTP client to run? ('busybox', 'openntpd', 'chrony' or 'none')" chrony done diff --git a/tests/setup_ntp_test b/tests/setup_ntp_test index 6746277558389106b7cac123e09f81d3c2729c5a..035264e873d202714b3727fac30132bf61c95116 100755 --- a/tests/setup_ntp_test +++ b/tests/setup_ntp_test @@ -8,7 +8,8 @@ init_tests \ setup_ntp_chrony \ setup_ntp_openntpd \ setup_ntp_none \ - setup_ntp_none_backwards_compat + setup_ntp_none_backwards_compat \ + setup_ntp_interactive_datetime setup_ntp_usage_body() { test_usage setup-ntp @@ -58,3 +59,14 @@ setup_ntp_none_backwards_compat_body() { setup-ntp -c none } +setup_ntp_interactive_datetime_body() { + init_env + ( + echo "2024-05-16 22:28:50" + echo busybox + ) > answers + atf_check -s exit:0 \ + -o match:"date -s 2024-05-16 22:28:50" \ + -o match:"Which NTP client" \ + setup-ntp < answers +}