I make a bash script that calls another two bash script and reboots the system in a condition is match.
The condition is: REBOOT_REQUIRED>0
#!/bin/bash
# Declare a variable used as counter in order to count the reboot requests.
declare -i REBOOT_REQUIRED=0
# Script List
RESTORE_ETHERNET_NAME='restore-eth-names.sh'
RESTORE_WIFI_DRIVER='restore-wifi-driver.sh'
#####################################
# Execute RestoreEthNames.sh script #
#####################################
echo -e "Performing Startup Checks"
chmod +x $RESTORE_ETHERNET_NAME
./$RESTORE_ETHERNET_NAME
# Store return code
RESTORE_ETHERNET_NAME_RET_CODE=$?
if [[ $RESTORE_ETHERNET_NAME_RET_CODE == 0 ]]
then
echo -e "==> Ethernet Configuration: Ok"
else
echo -e "==> Ethernet Configuration: Fixed"
((REBOOT_REQUIRED++))
fi
#######################################
# Execute RestoreWiFiDriver.sh script #
#######################################
chmod +x $RESTORE_WIFI_DRIVER
./$RESTORE_WIFI_DRIVER
# Store return code
RESTORE_WIFI_DRIVER_RET_CODE=$?
if [[ $RESTORE_WIFI_DRIVER_RET_CODE == 0 ]]
then
echo -e "==> WiFi Driver: Ok"
else
echo -e "==> WiFi Driver: Fixed"
((REBOOT_REQUIRED++))
fi
if [[ $REBOOT_REQUIRED > 0 ]]
then
echo -e "System Reboot in 5 seconds"
sleep 5
reboot
fi
This script is executed at startup, adding a system service with another installation script:
################################################
# Create Service to execute scripts on startup #
################################################
if [ -e $SERVICE_FULL_PATH ]; then
echo "File $SERVICE_FULL_PATH already exists!"
else
echo -e "[Unit]\nDescription=Startup Script\n\n[Service]\nExecStart=$\/$SCRIPT_STARTUP_CHECKS\n\n[Install]\nWantedBy=default.target" >> $SERVICE_FULL_PATH
chmod 664 $SERVICE_FULL_PATH
# Enable the service
systemctl enable $SERVICE_NAME
fi
The service is created correctly and the service is enabled.
The problem is that the PC enters into a reboot loop... the PC starts, at the login, after 5 seconds the system reboots again and again.