It won't remember anything across reboots, so you need to create a file to store the state in.
#!/bin/bash
[ -f /path/to/state ] && STATE=$(cat /path/to/state)
case "$INSTALLSTATE" in
INSTALL)
# continue install stuff
;;
*) if apt-get update
then
echo "INSTALL" > /path/to/state
/sbin/reboot
else
echo "update failed" >&2
exit 1
fi
;;
esac
As for how to start it on reboot, you'll need to put it in your distro's equivalent of /etc/local.start . Making a full-fledged service for it would probably be overkill. Or if you want it to start on login, perhaps the users' .profile or .bashrc
Unless you're updating the kernel, why's a reboot needed?
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
update failed
here is what is put:
#Start Setup
#Let the craziness commence
#First update begins
if [ "$Update1" == "Y" ]
then
sudo apt-get update -y
else
echo "Skipping first Update"
fi
sleep 1
#Apply changes to be made in update manager VIA-script
#Confirm Competition of update
#add itself to "startup apps"
#Delete the above lines so it will not repeat the same actions again
#Reboot
case "$INSTALLSTATE" in
INSTALL)
# continue install stuff
;;
*) if apt-get update
then
echo "Hit control c now"
sleep 10
echo "INSTALL" > /path/to/state
/sbin/reboot
else
echo "update failed" >&2
exit 1
fi
;;
esac
#continue script...
---------- Post updated at 05:40 PM ---------- Previous update was at 05:36 PM ----------
on the clean install the first update will most likely need a restart from the update manager
Could you pls tell the wot does the below highlighted mean. I understand it to be the file descriptor 2 representing standard error. But wot it does exactly in this line.? Does it send the std output and std error to fd 2..?
Close. It sends standard output to standard error. I usually do that for printing error messages since stderr is where error messages traditionally go, not stdout.
By tradition most processes are started with three open files: Standard input at FD 0, standard output at FD 1, and standard error at FD 2. When you run a process in a shell without redirecting anything, stdin reads from the keyboard, stdout writes to the terminal screen, and stderr also writes to the terminal screen.
echo "hello world" prints "hello world" to standard output.
For error messages, we want to print to standard error, so that the error messages will show up even if standard out has been redirected, and so that error messages don't get shoved where they don't belong, like in the middle of a big flat file you're transforming or something.
So we print to stderr, by redirecting FD 1 into FD 2.
Thank you Corona688. Can you please tell in what instances we should go for this re-direction.? Im still uncertain on this because though we re-direct FD 1 into FD 2 still the output is going to be displayed in the terminal window.
Yes, it does. Do you want error messages ending up anywhere but the console? Usually not. You don't want them in whatever data you're saving from the process, which it will end up in if you just print it to stdout...