Page 1 of 1

Resetting the system, then resuming from the point after it in BASH script

Posted: Mon Aug 13, 2018 11:51 pm
by Azsorlex26
Hello forums. What I'm trying to do is create a script that sets up my computer from a clean installation of Raspbian Lite (in case the backup fails). I've done a lot of testing on this, and it simply cannot be done without rebooting; some commands such as

Code: Select all

pivpn -a
require a reboot to not break the system. So, what I want to do is have the system reboot at a certain point in the script, and then resume after that point. Anyone can put

Code: Select all

sudo reboot
in a script, but it'll end it.

Re: Resetting the system, then resuming from the point after it in BASH script

Posted: Tue Aug 14, 2018 1:18 am
by DirkS
Create a file just before the reboot (e.g. using 'touch') and check for the existence of that file at the start of your script. If it exists you jump to a location after the reboot.

Re: Resetting the system, then resuming from the point after it in BASH script

Posted: Tue Aug 14, 2018 1:57 am
by Azsorlex26
DirkS wrote:
Tue Aug 14, 2018 1:18 am
Create a file just before the reboot (e.g. using 'touch') and check for the existence of that file at the start of your script. If it exists you jump to a location after the reboot.
So how would I do this? Something like this:

Code: Select all

if [ *continue doesn't exist* ] ; then
    *first block of code*
    *set script to run at boot*
    touch continue
else
    *second block of code*
    *set script to not run at boot*
    rm continue
fi
sudo reboot
?

Re: Resetting the system, then resuming from the point after it in BASH script

Posted: Tue Aug 14, 2018 3:07 am
by Heater
Azsorlex26,
...it simply cannot be done without rebooting; some commands such as
...pivpn -a...
require a reboot to not break the system...
I'm very sure this is not true.

pivpn is only installing and configuring openvpn. I know from experience that this does not require a reboot to get working.

Further, when installing/upgrading things with apt-get and friends a reboot is almost never required. Only when the kernel is upgraded. Given that it's unlikely you need to do a reboot.

As for how to deal with the reboot solution with a script. The idea is of creating a file as a flag that a reboot has occurred is pretty solid. Suggest learning how to use BASH. There are thousands of documents, tutorials, discussions, etc all over the net on BASH scripting.