Alright, it's been a while, though I finally had some time to sit down and write out my solution. This was my first ever time writing a bash script so it was exciting.
I ended up utilizing a combination of 3 scripts, 2 of which were given root permissions in the sudoers file. Perhaps there is a better way to do this; however, I simply put the full path to the script.
sudo visudo
Then under the tab #includedir /etc/sudoers.d
userName ALL=NOPASSWD PATH/AutoStartMiner.sh, PATH/TeamRedMiner_Config.sh, Path/teamredminer
This would set the stage for the 3 scripts to work one after the other without issues.
To start start AutoStartMiner.sh in a terminal window, I utilized the gnome-terminal emulator. For those implementing something similar, you'll need to install the emulator via:
sudo apt install gnome-terminal
I then utilized the LXQT configuration center and navigated to the session settings. In session settings I set the script StartTerminalASM.sh to execute after the system tray had loaded. This was accomplished by pressing add, giving the autostart function a name, pasting the whole path to the script, including the script itself, and then clicking the box that says load after system tray. It's important to note that this first script does not need to run with elevated privileges, so this method works. The autostart function of LXQT does not run scripts requiring elevated privileges automatically.
Here is the contents of the first script: StartTerminalASM.sh
#!/bin/bash
gnome-terminal --command="bash -c 'sudo /home/userName/Scripts/AutoStartMiner.sh; $SHELL'"
This script simply starts up the AutoStartMiner.sh in a gnome terminal. Since we added this script to the sudoers file earlier, the sudo command executes without a password prompt.
Here is the second script: AutoStartMiner.sh
#!/bin/bash
# Prompt user with information.
echo "Miner will begin in 60 seconds."
echo "Press s + enter to stop the process and resume normal operation."
# Delare variables.
input="a"
let seconds=60
#Await user input and countdown.
while [ $seconds -gt 0 ]; do
printf "\r........."$seconds
read -s -t 1 input
let "seconds-=1"
if [ "$input" = "s" ] || [ "$input" = "S" ]; then
break
fi
done
echo
#Initiate user selection
if [ "$input" = "s" ] || [ "$input" = "S" ]; then
echo "Resuming normal operation."
sleep 2
else
echo "Starting miner."
sleep 2
sudo /home/userName/Documents/Crypto/Miners/TeamRedMiner/teamredminer-v0.8.4-linux/TeamRedMiner_Config.sh
fi
So this essentially does as I described in the original question. The only problem it has is that when the time drops below 10 seconds, for some reason, a 0 appears in the 1s place and the numbers count down in the 10s place (e.g. 10, 90, 80, 70, ..., etc). Probably something I don't fully understand about the printf
statement that I made. Similarly above, the sudo
command here doesn't ask for a password due to the line created in sudoers.
Finally it executes a third script: TeamRedMiner_Config.sh
This script simply establishes the parameters for the miner to run. It also executes the miner with sudo
, hence why we add a third command to sudoers to ensure no prompt is required to start the miner itself.
So unless the user prompts the system to stop to miner from starting, the miner will execute without any input. This is extremely useful as it saves me a ton of headache if the kernel happens to crash. I simply press the power button and boom, the miner is running one min later. If I really wanted to automate it, I could make a little servo to push the button or set up wake on lan.
That all being said, it's onto the latest problem. After updating to Linux kernel 5.11.0-27-generic, my wireless adapter refuses to connect to my network, though at least it's recognized by the system.
Thanks for the input everyone and I hope this helps other beginners like me one day.