First Time After Install, Run Configuration Script
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
First Time After Install, Run Configuration Script
My job is having me get back into Linux. It has been awhile since I messed with it. My company releases Software that runs on Linux. As such, when we release a new version of the software, we have it packaged with the entire Linux OS. As such, when it is sent to our clients, they install, and then have to reconfigure, the Host Name, IP Address, Netmask, and Gateway. Our test environment consists of over ten different Linux boxes and configurations. To make life easier for me, I have written a shell script allowing me a menu to change all of these and to also enable or disable the gateway and how to set/change the localadm password.
I want the script available to users to be able to run it anytime they need to. It works great. I would like to add one more thing to this. I want to be able to run the script automatically on the very first boot after the installation. The script is set up where you have to log in as root to run it. So here is the process I want to happen:
System starts up for very first time after install
Automatically logs in as root and runs script
Exits as root.
I realize Linux will only do what I tell it to. How do I tell it to do this?
If the above link sounds complicated then another way is to invoke it by /etc/rc.d/rc.local for the first time. Apart from that you have to make the following addition in your script. Suppose your script is located at /tmp/config.sh then you have to make sure that the image that you are delivering should have the following in /etc/rc.d/rc.local:
Make sure /etc/rc.d/rc.local have execute permission. In RHEL6 it has by default but in RHEL7 I haven't seen that and you have to give it manually.
Once that part is done you have to add the following in your script:
cat /etc/rc.d/rc.local | grep -v config.sh > /etc/rc.d/rc.local.bak #Doing inverse match to make sure script doesn't show up in output
mv /etc/rc.d/rc.local /etc/rc.d/rc.local.orig
mv /etc/rc.d/rc.local.bak /etc/rc.local #This will make sure that we don't have that script line for the next reboot
Some distributions have a firstboot init script which appears to be what you want. It an be installed as enabled, runs after installation and disables at end of script. What distribution /version of linux are you using?
The script can be run by the user logged in as root at anytime. They just run ./script.sh from /root
I want them to be able to put the install disk in, install everything, then on the reboot the first time the machine boots up it will automatically log them in as root and bring up the menu. Then they make all the changes.
The documentation in our user manual currently says to install the software, take out the disk, reboot the machine, log in as root then change the Host Name, IP Addr, Netmask, and Gateway. Then to change the localadm password. I want to shrink it down to:
Reboot the machine
(Machine automatically logs in as root on very first boot up after install and runs the script producing the menu)
User uses menu to configure Host Name, IP Addr, Netmask, Gateway, and localadm passwd.
Upon exiting the menu there is a service network restart and then the user is exited out of root.
All of this happens only on the very first time the machine boots up after install.
If I am getting it correct it is some kind of an appliance / customized system. Basically you want them to have root access for the configuration part, once that is done revoke their root access and let them use localadm. Is that correct?
It will be good to know if your script requires GUI or it works in TUI?
Last edited by T3RM1NVT0R; 04-06-2015 at 05:13 PM.
Everything is run from the CLI. The administrators of the system will of course have root access. It just would be a smoother, quicker, install and configuration process to have a script that produces a menu to configure everything on the initial boot instead of going into each config file and hand jamming it.
As you said it works with TUI you might want to separate auto login section of your script. This is what I am thinking of:
1. Have a separate script for auto login, put that script in /etc/rc.d/rc.local so that will let them in.
2. As you said that you want users to drive, that is they will run the script and configure Host Name, IP Addr, Netmask, Gateway, and localadm passwd. Have a separate script for this and in your document share the location of this script.
3. Make sure that the second script (configuration script) should also perform cleanup from /etc/rc.d/rc.local so that they don't auto login after reboot.