Update RM520_rgmii_toolkit_beta.sh

Add daily reboot (first try)
This commit is contained in:
iamromulan
2023-11-21 00:04:13 -05:00
committed by GitHub
parent 722c2b0247
commit 0aa55a9a93

View File

@@ -183,20 +183,131 @@ remove_simple_admin() {
remount_ro
}
# Function to create systemd service and timer files with the user-specified time
create_service_and_timer() {
# Create the systemd service file for reboot
echo "[Unit]
Description=Reboot Modem Daily
[Service]
Type=oneshot
ExecStart=/sbin/reboot
Restart=no
RemainAfterExit=no" > /lib/systemd/system/rebootmodem.service
# Create the systemd timer file with the user-specified time
echo "[Unit]
Description=Starts rebootmodem.service daily at the specified time
[Timer]
OnCalendar=*-*-* $user_time:00
Persistent=false" > /lib/systemd/system/rebootmodem.timer
# Create a trigger service that starts the timer at boot
echo "[Unit]
Description=Trigger the rebootmodem timer at boot
[Service]
Type=oneshot
ExecStart=/bin/systemctl start rebootmodem.timer
RemainAfterExit=yes" > /lib/systemd/system/rebootmodem-trigger.service
# Create symbolic links for the trigger service in the wanted directory
ln -sf /lib/systemd/system/rebootmodem-trigger.service /lib/systemd/system/multi-user.target.wants/
# Reload systemd to recognize the new timer and trigger service
systemctl daemon-reload
sleep 2s
# Start the trigger service, which will start the timer
systemctl start rebootmodem-trigger.service
# Confirmation
echo "Rebootmodem-trigger service created and started successfully."
echo "Reboot schedule set successfully. The modem will reboot daily at $user_time UTC."
}
# Function to manage Daily Reboot Timer
manage_reboot_timer() {
# Remount root filesystem as read-write
mount -o remount,rw /
# Check if the rebootmodem service, timer, or trigger already exists
if [ -f /lib/systemd/system/rebootmodem.service ] || [ -f /lib/systemd/system/rebootmodem.timer ] || [ -f /lib/systemd/system/rebootmodem-trigger.service ]; then
printf "The rebootmodem service/timer/trigger is already installed. Do you want to change or remove it? (change/remove): "
read user_action
case $user_action in
remove)
# Stop and disable timer and trigger service by removing symlinks
systemctl stop rebootmodem.timer
systemctl stop rebootmodem-trigger.service
# Remove symbolic links and files
rm -f /lib/systemd/system/multi-user.target.wants/rebootmodem-trigger.service
rm -f /lib/systemd/system/rebootmodem.service
rm -f /lib/systemd/system/rebootmodem.timer
rm -f /lib/systemd/system/rebootmodem-trigger.service
# Reload systemd to apply changes
systemctl daemon-reload
echo "Rebootmodem service, timer, and trigger removed successfully."
;;
change)
printf "Enter the new time for daily reboot (24-hour format in Coordinated Universal Time, HH:MM): "
read new_time
# Validate the new time format using grep
if ! echo "$new_time" | grep -qE '^([01]?[0-9]|2[0-3]):[0-5][0-9]$'; then
echo "Invalid time format. Exiting."
exit 1
else
# Remove old symlinks
rm -f /lib/systemd/system/multi-user.target.wants/rebootmodem-trigger.service
# Set the user time to the new time and recreate the service, timer, and trigger
user_time=$new_time
create_service_and_timer
fi
;;
*)
echo "Invalid action. Exiting."
exit 1
;;
esac
else
printf "Enter the time for daily reboot (24-hour format in UTC, HH:MM): "
read user_time
# Validate the time format using grep
if ! echo "$user_time" | grep -qE '^([01]?[0-9]|2[0-3]):[0-5][0-9]$'; then
echo "Invalid time format. Exiting."
exit 1
else
create_service_and_timer
fi
fi
# Remount root filesystem as read-only
mount -o remount,ro /
}
# Main menu
while true; do
echo "Select an option:"
echo "1) Send AT Commands"
echo "2) Install/Update or remove AT Telnet Daemon"
echo "3) Install/Update or remove Simple Admin"
echo "4) Exit"
echo "4) Install/Change or remove Daily Reboot Timer"
echo "5) Exit"
read -p "Enter your choice: " choice
case $choice in
1)
1)
send_at_commands
;;
2)
2)
if is_at_telnet_installed; then
echo "AT Telnet Daemon is already installed."
echo "1) Update"
@@ -228,9 +339,17 @@ while true; do
install_update_simple_admin
fi
;;
4) break;;
*) echo "Invalid option";;
4)
manage_reboot_timer
;;
5)
break
;;
*)
echo "Invalid option"
;;
esac
done
echo "Exiting script."