#!/bin/sh ########################################################################### # # Copyright (c) 2021-2023 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file date_time_set.sh # # @author (last) Behrouz NematiPour # @date (last) 20-Apr-2021 # @author (original) Behrouz NematiPour # @date (original) 20-Apr-2021 # ############################################################################ # 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" sudo hwclock -w check_result "$?" "$ERR_CMDFAIL_HW_CLOCK" # exit gracefully sleep 0.1 echo "" exit 0