LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   First Time After Install, Run Configuration Script (https://www.linuxquestions.org/questions/linux-newbie-8/first-time-after-install-run-configuration-script-4175538937/)

agoknight 04-06-2015 02:08 PM

First Time After Install, Run Configuration Script
 
Hello,

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:

Install Disk
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?

T3RM1NVT0R 04-06-2015 02:28 PM

Welcome to LQ!!!

You can have a look at this: https://www.centos.org/docs/5/html/5...-firewall.html

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:

Code:

sh /tmp/config.sh
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:

Code:

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


michaelk 04-06-2015 02:34 PM

Welcome to LinuxQuestions.

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?

Too late...

T3RM1NVT0R 04-06-2015 02:38 PM

I think I missed something. If your script require human intervention then running it via /etc/rc.d/rc.local wouldn't work. It works well with unattended stuff.

agoknight 04-06-2015 03:16 PM

I am running RHEL 6.6 (Santiago)

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:

Install
Remove Disk
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.

T3RM1NVT0R 04-06-2015 03:38 PM

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?

agoknight 04-06-2015 04:37 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.

michaelk 04-06-2015 05:41 PM

I would think that your script run via rc.local as T3RM1NVT0R suggested would work. By default would run as root and after install.

T3RM1NVT0R 04-07-2015 09:27 AM

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.


All times are GMT -5. The time now is 08:49 AM.