diff --git a/initrd/bin/change-time b/initrd/bin/change-time new file mode 100755 index 000000000..d7719b7e8 --- /dev/null +++ b/initrd/bin/change-time @@ -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" + + +get_date () { + echo -e -n "enter the $1 please ($2-$3) (enter for $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 "wrong $1, you enter "$value" please enter it again, must be a $4 digits number between $2 and $3 (press enter for $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 "min" "00" "59" "2" +min=$value +get_date "sec" "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 set it again" + echo -e "\n" + read -n 1 noting + clear + change-time +else + hwclock -w + echo -e "the 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 \ No newline at end of file diff --git a/initrd/bin/gui-init b/initrd/bin/gui-init index dc9ec20da..75de07113 100755 --- a/initrd/bin/gui-init +++ b/initrd/bin/gui-init @@ -221,6 +221,7 @@ update_totp() If you have not just reflashed your BIOS, THIS COULD INDICATE TAMPERING!\n How would you like to proceed?" 0 80 4 \ 'g' ' Generate new HOTP/TOTP secret' \ + 'h' ' Change system time' \ 'i' ' Ignore error and continue to main menu' \ 'p' ' Reset the TPM' \ 'x' ' Exit to recovery shell' \ @@ -234,6 +235,9 @@ update_totp() generate_totp_hotp && update_totp && BG_COLOR_MAIN_MENU="normal" && reseal_tpm_disk_decryption_key fi ;; + h ) + change-time + ;; i ) skip_to_menu="true" return 1 @@ -430,6 +434,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 +455,9 @@ show_options_menu() t ) show_tpm_totp_hotp_options_menu ;; + h ) + change-time + ;; u ) prompt_update_checksums ;;