mirror of
https://github.com/femtofox/femtofox.git
synced 2026-12-01 12:26:39 -05:00
Fix timezone setting tool and add time setting feature
This commit is contained in:
parent
70b6341252
commit
f56968c85b
6 changed files with 97 additions and 76 deletions
|
|
@ -166,7 +166,7 @@ utilities() {
|
|||
while true; do
|
||||
local option=""
|
||||
option=$(dialog --cancel-label "Back" --menu "$title" 17 40 4 \
|
||||
1 "Set system timezone" \
|
||||
1 "Set system time" \
|
||||
2 "Kernel modules" \
|
||||
3 "Re-run first-boot script" \
|
||||
4 "Run USB configuration tool" \
|
||||
|
|
@ -183,7 +183,7 @@ utilities() {
|
|||
fi
|
||||
|
||||
case $option in
|
||||
1) femto-set-timezone.sh ;; # set timezone)
|
||||
1) femto-set-time.sh ;; # set timezone)
|
||||
2) # Kernel modules)
|
||||
dialog --title "$title" --msgbox "Kernel modules are loadable pieces of code that extend a Linux kernel's functionality without requiring a reboot. Common examples include device drivers, file systems, or system calls.\n\nThis tool will allow you to add pre-compiled modules to the Foxbuntu kernel.\n\nModules currently autostarting at boot: $(modules=$(sed -n '6,$p' /etc/modules | sed ':a;N;$!ba;s/\n/, /g;s/, $//'); [ -z "$modules" ] && echo "none" || echo "$modules")\n\nCurrently active modules: $(lsmod | awk 'NR>1 {print $1}' | tr '\n' ' ')" 18 65
|
||||
femto-kernel-modules.sh
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ title="Install Wizard"
|
|||
|
||||
wizard() {
|
||||
|
||||
femto-set-timezone.sh
|
||||
femto-set-time.sh
|
||||
|
||||
new_hostname=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter hostname:" 8 40 $(hostname) 3>&1 1>&2 2>&3)
|
||||
if [ $? -eq 0 ]; then #unless cancel/no
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
#!/bin/bash
|
||||
export NCURSES_NO_UTF8_ACS=1 # prevents weirdness over tty
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo -e "This script must be run as root. Try \`sudo femto-set-timezone\`."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
arg_count=$#
|
||||
|
||||
help=$(cat <<EOF
|
||||
If no argument is specified, a menu system will be used. Options are:
|
||||
-h This message
|
||||
-t "TIMEZONE" Set timezone
|
||||
EOF
|
||||
)
|
||||
|
||||
log_message() {
|
||||
logger $1
|
||||
if [ $arg_count -eq 0 ]; then
|
||||
dialog --msgbox "$1" 12 50
|
||||
else
|
||||
echo $1
|
||||
fi
|
||||
}
|
||||
|
||||
set_timezone() {
|
||||
if timedatectl set-timezone "$1"; then
|
||||
log_message "\nTime zone set to $1 (UTC$(date +%z)) successfully."
|
||||
else
|
||||
log_message "\nFailed to set the time zone to $1."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
while getopts ":t:h" opt; do
|
||||
case ${opt} in
|
||||
t) # Option -t (timezone)
|
||||
set_timezone "$OPTARG"
|
||||
;;
|
||||
h) # Option -h (help)
|
||||
echo -e "$help"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Fetch available time zones
|
||||
echo "Loading timezones..."
|
||||
timezones=$(timedatectl list-timezones)
|
||||
# Build the options array
|
||||
options=()
|
||||
while IFS= read -r timezone; do
|
||||
options+=("$timezone" "x")
|
||||
done <<< "$timezones"
|
||||
|
||||
# Convert options array to string
|
||||
options_str=$(printf '%s\n' "${options[@]}")
|
||||
|
||||
# Show timezone selection menu with preselection of current timezone
|
||||
selected_timezone=$(dialog --title "Select Timezone" \
|
||||
--default-item "$(cat /etc/timezone)" \
|
||||
--menu "Current timezone: $(cat /etc/timezone) (UTC$(date +%z))" 20 60 10 \
|
||||
$(printf "%s " "${options[@]}") 3>&1 1>&2 2>&3)
|
||||
exit_status=$?
|
||||
if [[ $exit_status -eq 0 && -n "$selected_timezone" ]]; then
|
||||
# Set the selected time zone
|
||||
set_timezone $selected_timezone
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DATE=$(echo "$(dialog --title "Select Date" --calendar "Choose a date:\nCurrent date: $(date "+%B %d, %Y")\nPress [TAB] to select." 0 0 $(date +%d) $(date +%m) $(date +%Y) 3>&1 1>&2 2>&3)" | awk -F/ '{printf "%04d-%02d-%02d", $3, $2, $1}')
|
||||
if [ $? -eq 1 ]; then #if cancel/no
|
||||
exit 1
|
||||
fi
|
||||
TIME=$(dialog --title "Set Time" --timebox "Select time:\nCurrent time: $(date +%H:%M:%S)\nPress [TAB] to select." 0 0 3>&1 1>&2 2>&3) # Dialog timebox for time
|
||||
if [ $? -eq 1 ]; then #if cancel/no
|
||||
exit 1
|
||||
fi
|
||||
if date -s "$DATE $TIME"; then # set time
|
||||
if hwclock --systohc; then
|
||||
rtc="New time successfully saved to RTC."
|
||||
else
|
||||
rtc="Unable to communicate with RTC module. An RTC module can save system time between reboots/power outages."
|
||||
fi
|
||||
log_message "System time updated to:\n$(date)\n\n$rtc\nTime & date are also set automatically from internet."
|
||||
else
|
||||
log_message "Failed to set system time."
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
#!/bin/bash
|
||||
export NCURSES_NO_UTF8_ACS=1 # prevents weirdness over tty
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root. Try \`sudo femto-set-timezone\`."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
arg_count=$#
|
||||
|
||||
help=$(cat <<EOF
|
||||
If no argument is specified, a menu system will be used. Options are:
|
||||
-h This message
|
||||
-t "TIMEZONE" Set timezone
|
||||
EOF
|
||||
)
|
||||
|
||||
set_timezone() {
|
||||
if timedatectl set-timezone "$1"; then
|
||||
msg="Time zone set to $1 successfully."
|
||||
status=0
|
||||
else
|
||||
msg="Failed to set the time zone to $1. Please try again." 8 40
|
||||
status=1
|
||||
fi
|
||||
if [ $arg_count -eq 0 ]; then
|
||||
dialog --msgbox "$msg" 8 40
|
||||
else
|
||||
echo $msg
|
||||
logger $msg
|
||||
fi
|
||||
exit $status
|
||||
}
|
||||
|
||||
|
||||
|
||||
while getopts ":t:h" opt; do
|
||||
case ${opt} in
|
||||
t) # Option -t (timezone)
|
||||
set_timezone "$OPTARG"
|
||||
;;
|
||||
h) # Option -h (help)
|
||||
echo -e "$help"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Fetch available time zones
|
||||
timezones=$(timedatectl list-timezones)
|
||||
if [[ -z "$timezones" ]]; then
|
||||
dialog --msgbox "\nFailed to retrieve time zones. Ensure 'timedatectl' is installed and functional." 8 40
|
||||
return
|
||||
fi
|
||||
|
||||
# Build options for dialog menu
|
||||
while IFS= read -r timezone; do
|
||||
options+=("$timezone" "x")
|
||||
done <<< "$timezones"
|
||||
|
||||
# Convert options array to string
|
||||
options_str=$(printf '%s\n' "${options[@]}")
|
||||
|
||||
# Show timezone selection menu
|
||||
selected_timezone=$(dialog --title "Select Time Zone" --cancel-label "Skip" --menu "Choose a time zone:" 20 60 10 $(printf "%s " "${options[@]}") 3>&1 1>&2 2>&3)
|
||||
exit_status=$?
|
||||
if [[ $exit_status -eq 0 && -n "$selected_timezone" ]]; then
|
||||
# Set the selected time zone
|
||||
set_timezone $selected_timezone
|
||||
fi
|
||||
|
|
@ -68,9 +68,9 @@ package_intro() {
|
|||
$(if $package_dir/$1.sh -O | grep -q 'A'; then echo -e "by $($package_dir/$1.sh -A)"; fi)\n\
|
||||
$(if $package_dir/$1.sh -O | grep -q 'D'; then echo "\n$($package_dir/$1.sh -D)"; fi)\n\
|
||||
\n\
|
||||
$(echo "Currently: " && $package_dir/$1.sh -I && echo "\Zuinstalled\Zn" || echo "\Zunot installed\Zn")\n\
|
||||
$(if output=$($package_dir/$1.sh -L); [ -n "$output" ]; then echo "Installs to: \Zu$output\Zn"; fi)\
|
||||
$(if output=$($package_dir/$1.sh -C); [ -n "$output" ]; then echo "Installs to: \Zu$output\Zn"; fi)\
|
||||
$(echo "Currently: " && $package_dir/$1.sh -I && echo "\Zuinstalled\Zn" || echo " \Zunot installed\Zn")\n\
|
||||
$(if output=$($package_dir/$1.sh -L); [ -n "$output" ]; then echo "Installs to: \Zu$output\Zn\n"; fi)\
|
||||
$(if output=$($package_dir/$1.sh -C); [ -n "$output" ]; then echo "Conflicts with: \Zu$output\Zn\n"; fi)\
|
||||
An internet connection is required for installation.\n\
|
||||
$(if $package_dir/$1.sh -O | grep -q 'U'; then echo "\nFor more information, visit $($package_dir/$1.sh -U)"; fi)" 0 0
|
||||
package_menu $1 # after user hits "OK", move on to package menu
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
if [[ -n "$timezone" ]]; then # set timezone
|
||||
timezone=$(echo "$timezone" | sed 's/\\//g')
|
||||
log_message "Updating system timezone to $timezone."
|
||||
femto-set-timezone.sh -t "$timezone"
|
||||
femto-set-time.sh -t "$timezone"
|
||||
found_config="true"
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue