mirror of
https://github.com/linuxboot/heads.git
synced 2024-12-18 20:47:55 +00:00
Merge pull request #1748 from JonathonHall-Purism/change-time-improvements
Alexgithublab: change time, 3.0 (supersedes #1737)
This commit is contained in:
commit
c5e449ddf9
73
initrd/bin/change-time.sh
Executable file
73
initrd/bin/change-time.sh
Executable file
@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
#change time using hwclock and date -s
|
||||
|
||||
clear
|
||||
|
||||
echo "The system time is: $(date "+%Y-%m-%d %H:%M:%S %Z")"
|
||||
echo
|
||||
echo "Please enter the current date and time in UTC"
|
||||
echo "To find the current date and time in UTC, please check https://time.is/UTC"
|
||||
echo
|
||||
|
||||
get_date () {
|
||||
local field_name min max
|
||||
field_name="$1"
|
||||
min="$2"
|
||||
max="$3"
|
||||
echo -n "Enter the current $field_name [$min-$max]: "
|
||||
read -r value
|
||||
echo
|
||||
|
||||
#must be a number between $2 and $3
|
||||
while [[ ! $value =~ ^[0-9]+$ ]] || [[ ${value#0} -lt $min ]] || [[ ${value#0} -gt $max ]];
|
||||
do
|
||||
echo "Please try again, it must be a number from $min to $max."
|
||||
echo -n "Enter the current $field_name [$min-$max]: "
|
||||
read -r value
|
||||
echo
|
||||
done
|
||||
|
||||
# Pad with zeroes to length of maximum value.
|
||||
# The "$((10#$value))" is needed to handle 08 and 09 correctly, which printf
|
||||
# would otherwise interpret as octal. This effectively strips the leading
|
||||
# zero by evaluating an arithmetic expression with the base set to 10.
|
||||
value="$(printf "%0${#max}u" "$((10#$value))")"
|
||||
}
|
||||
|
||||
enter_time_and_change()
|
||||
{
|
||||
get_date "year" "2024" "2200"
|
||||
year=$value
|
||||
get_date "month" "01" "12"
|
||||
month=$value
|
||||
get_date "day" "01" "31"
|
||||
day=$value
|
||||
get_date "hour" "00" "23"
|
||||
hour=$value
|
||||
get_date "minute" "00" "59"
|
||||
min=$value
|
||||
get_date "second" "00" "59"
|
||||
sec=$value
|
||||
|
||||
if ! date -s "$year-$month-$day $hour:$min:$sec" &>/dev/null; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
while ! enter_time_and_change; do
|
||||
echo "Could not set the date to $year-$month-$day $hour:$min:$sec"
|
||||
read -rp "Try again? [Y/n]: " try_again_confirm
|
||||
if [ "${try_again_confirm^^}" = N ]; then
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
done
|
||||
|
||||
hwclock -w
|
||||
echo "The system date has been sucessfully set to $year-$month-$day $hour:$min:$sec UTC"
|
||||
echo
|
||||
|
||||
echo "Press Enter to return to the menu"
|
||||
echo
|
||||
read -r nothing
|
@ -430,6 +430,7 @@ show_options_menu()
|
||||
--menu "" 0 80 10 \
|
||||
'b' ' Boot Options -->' \
|
||||
't' ' TPM/TOTP/HOTP Options -->' \
|
||||
'h' ' Change system time' \
|
||||
'u' ' Update checksums and sign all files in /boot' \
|
||||
'c' ' Change configuration settings -->' \
|
||||
'f' ' Flash/Update the BIOS -->' \
|
||||
@ -450,6 +451,9 @@ show_options_menu()
|
||||
t )
|
||||
show_tpm_totp_hotp_options_menu
|
||||
;;
|
||||
h )
|
||||
change-time.sh
|
||||
;;
|
||||
u )
|
||||
prompt_update_checksums
|
||||
;;
|
||||
@ -543,16 +547,8 @@ prompt_totp_mismatch()
|
||||
{
|
||||
TRACE_FUNC
|
||||
if (whiptail_warning --title "TOTP/HOTP code mismatched" \
|
||||
--yesno "TOTP/HOTP code mismatches could indicate either TPM tampering or clock drift:\n\nTo correct clock drift: 'date -s yyyy-MM-DD hh:mm:ss' in UTC timezone\nand save it to the RTC: 'hwclock -w'\nthen reboot and try again.\n\nWould you like to exit to a recovery console?" 0 80) then
|
||||
echo ""
|
||||
echo "To correct clock drift: 'date -s yyyy-MM-DD hh:mm:ss' in UTC timezone"
|
||||
echo "and save it to the RTC: 'hwclock -w'"
|
||||
echo ""
|
||||
echo "Alternatively you could do this automatically with an Ethernet cable connected to a functional network: 'network-init-recovery'"
|
||||
echo ""
|
||||
echo "Then reboot and try again"
|
||||
echo ""
|
||||
recovery "TOTP/HOTP mismatch"
|
||||
--yesno "TOTP/HOTP code mismatches could indicate TPM tampering or clock drift.\n\nThe current UTC time is: $(date "+%Y-%m-%d %H:%M:%S")\nIf this is incorrect, set the correct time and check TOTP/HOTP again.\n\nDo you want to change the time?" 0 80) then
|
||||
change-time.sh
|
||||
fi
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user