Index: scripts/date_time_set.sh =================================================================== diff -u -r2a5e8882fa17faacf0c58b430f570cbe095265b5 -rb743e6d20c409d112cfe5a82366dbdf79460203c --- scripts/date_time_set.sh (.../date_time_set.sh) (revision 2a5e8882fa17faacf0c58b430f570cbe095265b5) +++ scripts/date_time_set.sh (.../date_time_set.sh) (revision b743e6d20c409d112cfe5a82366dbdf79460203c) @@ -15,18 +15,38 @@ # ############################################################################ -if [ $# -eq 0 ]; then - currentFile=$(basename "$0") - echo "Usage: ./$currentFile 'yyyy-mm-dd HH:MM:SS' [ntp:true|false]" - exit 0 -fi +# Description +# Sets system time and NTP flag +# Parameters +# - DateTime to update +# - Network Time protocol flag +# Considerations +# Setting the system time with a custom time will only work if NTP is set to off + +# sources +. ./_errors_ +. ./_functions_ + +# variables +PARAM_COUNT=2 new_time="$1" ntp_flag="${2:-false}" # Default to 'false' if not provided +# checks +check_param_count "$#" "$PARAM_COUNT" + +# main sudo timedatectl set-ntp "$ntp_flag" +check_result "$?" "$ERR_CMDFAIL_TIMEDATECTL" sudo date -s "$new_time" +check_result "$?" "$ERR_CMDFAIL_DATE" -# set the hwclock from the system time -sudo hwclock -w +sudo hwclock -w +check_result "$?" "$ERR_CMDFAIL_HW_CLOCK" + +# exit gracefully +sleep 0.1 +echo "" +exit 0 \ No newline at end of file