Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alexgithublab: change time (superseeds #1730) #1737

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions initrd/bin/change-time
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
#change time using hwclock and date -s

clear

echo -e -n "Please enter the date and time you wish to set\n"
echo -e -n "You need to set the time according to the UTC/GMT timezone please check https://time.is/UTC\n\n"


get_date () {
echo -e -n "Please insert $1 (between $2-$3) (Enter key to accept $2)\n"
read -n $4 value
echo -e "\n"
#if enter
if [[ $value = "" ]]; then
value=$2
fi

#must be a $4 digits number between $2 and $3
while [[ ! $value =~ ^[0-9]{$4} ]] || [[ ${value#0} -lt $2 ]] || [[ ${value#0} -gt $3 ]];
do
echo -e -n "$1 is wrong: you entered "$value". Please try again, it must be $4 digits number between $2 and $3 (press Enter to accept $2) \n"
read -n $4 value
echo -e "\n"
if [[ $value = "" ]]; then
value=$2
fi
done
}

get_date "year" "2024" "2200" "4"
year=$value
get_date "month" "01" "12" "2"
month=$value
get_date "day" "01" "31" "2"
day=$value
get_date "hour" "00" "23" "2"
hour=$value
get_date "minute" "00" "59" "2"
min=$value
get_date "second" "00" "59" "2"
sec=$value

##getting the output of date -s
OUTPUT=$(date -s "$year-$month-$day $hour:$min:$sec" 2>&1)

##if output is starting with the letter d which is the beginning of the error message then we do the script again
if [[ ${OUTPUT} == d* ]]; then
echo "The date is not correct, press any key to try again"
echo -e "\n"
read -n 1 nothing
clear
change-time
else
hwclock -w
echo -e "The system date has been sucessfully set to $year-$month-$day $hour:$min:$sec"
echo -e "\n"

echo -e "Press any key to return to the menu"
echo -e "\n"
read -n 1 nothing
fi
16 changes: 6 additions & 10 deletions initrd/bin/gui-init
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->' \
Expand All @@ -450,6 +451,9 @@ show_options_menu()
t )
show_tpm_totp_hotp_options_menu
;;
h )
change-time
;;
u )
prompt_update_checksums
;;
Expand Down Expand Up @@ -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 either TPM tampering or clock drift.\n\nHere, we will manually set system time to see if TOTP code mismatch was because of time drift.\n\nAlternatively you could sync time from network automatically with 'network-init-recovery' helper from Recovery shell\n " 0 80) then
change-time
fi
}

Expand Down