mirror of
https://github.com/linuxboot/heads.git
synced 2024-12-18 20:47:55 +00:00
change-time: Infer value digits automatically
Infer digits from the length of the maximum value. Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
This commit is contained in:
parent
b908e0b8bd
commit
234595df4a
@ -8,11 +8,10 @@ echo -e -n "You need to set the time according to the UTC/GMT timezone please ch
|
||||
|
||||
|
||||
get_date () {
|
||||
local field_name min max digits
|
||||
local field_name min max
|
||||
field_name="$1"
|
||||
min="$2"
|
||||
max="$3"
|
||||
digits="$4"
|
||||
echo "Please insert $field_name (between $min-$max)"
|
||||
read -r value
|
||||
echo
|
||||
@ -25,21 +24,21 @@ get_date () {
|
||||
echo
|
||||
done
|
||||
|
||||
# Pad with zeroes to digits
|
||||
value="$(printf "%0${digits}u" "$value")"
|
||||
# Pad with zeroes to length of maximum value
|
||||
value="$(printf "%0${#max}u" "$value")"
|
||||
}
|
||||
|
||||
get_date "year" "2024" "2200" "4"
|
||||
get_date "year" "2024" "2200"
|
||||
year=$value
|
||||
get_date "month" "01" "12" "2"
|
||||
get_date "month" "01" "12"
|
||||
month=$value
|
||||
get_date "day" "01" "31" "2"
|
||||
get_date "day" "01" "31"
|
||||
day=$value
|
||||
get_date "hour" "00" "23" "2"
|
||||
get_date "hour" "00" "23"
|
||||
hour=$value
|
||||
get_date "minute" "00" "59" "2"
|
||||
get_date "minute" "00" "59"
|
||||
min=$value
|
||||
get_date "second" "00" "59" "2"
|
||||
get_date "second" "00" "59"
|
||||
sec=$value
|
||||
|
||||
if ! date -s "$year-$month-$day $hour:$min:$sec" &>/dev/null; then
|
||||
|
Loading…
Reference in New Issue
Block a user