LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 04-06-2015, 02:08 PM   #1
agoknight
LQ Newbie
 
Registered: Apr 2015
Posts: 3

Rep: Reputation: Disabled
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?
 
Old 04-06-2015, 02:28 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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
 
Old 04-06-2015, 02:34 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,730

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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...

Last edited by michaelk; 04-06-2015 at 02:37 PM.
 
Old 04-06-2015, 02:38 PM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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.
 
Old 04-06-2015, 03:16 PM   #5
agoknight
LQ Newbie
 
Registered: Apr 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-06-2015, 03:38 PM   #6
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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 04:13 PM.
 
Old 04-06-2015, 04:37 PM   #7
agoknight
LQ Newbie
 
Registered: Apr 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-06-2015, 05:41 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,730

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
I would think that your script run via rc.local as T3RM1NVT0R suggested would work. By default would run as root and after install.
 
Old 04-07-2015, 09:27 AM   #9
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
configuration to run a cgi script mdunicorn Linux - Server 9 09-20-2011 07:53 AM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM
Script that will run a command, time it etc. kinetik Programming 7 06-20-2006 04:42 PM
Run script each time cd is used c19h28O2 Linux - Newbie 14 05-02-2006 04:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration