Azsorlex26
Posts: 16
Joined: Sat Feb 10, 2018 8:41 am
Location: Australia

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

Mon Aug 13, 2018 11:51 pm

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.

DirkS
Posts: 10345
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

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

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.

Azsorlex26
Posts: 16
Joined: Sat Feb 10, 2018 8:41 am
Location: Australia

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

Tue Aug 14, 2018 1:57 am

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
?

Heater
Posts: 15777
Joined: Tue Jul 17, 2012 3:02 pm

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

Tue Aug 14, 2018 3:07 am

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.
Memory in C++ is a leaky abstraction .

Return to “Other programming languages”