LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-06-2012, 12:24 AM   #1
xsbravo
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Rep: Reputation: Disabled
How to write installation script in linux?


Hi

I performed following 3 steps Setting Up Ethernet Card, Install libpcap, Install libdnet...Now i want to automate this using shell scripting.
Can anyone explain how to convert the following procedures into a shell script.

Regards

Steps are given below...

-Setting Up Ethernet Card

nano /etc/network/interfaces

add following;
auto eth1
iface eth1 inet dhcp

auto eth0
iface eth0 inet static
address 10.10.0.1
netmask 255.0.0.0
network 10.0.0.0
broadcast 10.255.255.255


/etc/init.d/networking restart

-libpcap
cd /usr/src
wget http://www.tcpdump.org/release/libpcap-1.2.0.tar.gz
tar -zxf libpcap-1.2.0.tar.gz && cd libpcap-1.2.0
./configure --prefix=/usr --enable-shared
make && make install


-Install libdnet:
cd /usr/src
wget http://libdnet.googlecode.com/files/libdnet-1.12.tgz
tar -zxf libdnet-1.12.tgz && cd libdnet-1.12
./configure --prefix=/usr --enable-shared
make && make install
 
Old 08-06-2012, 04:51 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Other than the /etc/network/interfaces bit, you already have a script.

In interfaces, are you replacing/deleting anything, or just adding those lines? If you're just adding, you can do it with echo:
Code:
echo "auto eth1
iface eth1 inet dhcp

auto eth0
iface eth0 inet static
address 10.10.0.1
netmask 255.0.0.0
network 10.0.0.0
broadcast 10.255.255.255" >> /etc/network/interfaces
The rest you should be able to just stick in the script verbatim. You could do some exit code checks to make sure everything is working well along the way, and you might want to put a check at the beginning to ensure it's being run as root, but these are just optional. All depends on how "bulletproof" you want to make this script.

Last edited by suicidaleggroll; 08-06-2012 at 04:54 PM.
 
Old 08-07-2012, 10:13 AM   #3
yuripaes
LQ Newbie
 
Registered: Aug 2012
Distribution: Scientific Linux
Posts: 3

Rep: Reputation: Disabled
I wrote a sample to give you an idea... but as suicidaleggroll said you it all depends on how much "bulletproof" you want your script

Code:
#!/bin/bash

# installation-v1.sh
# setup eth1, install libs
# Aug 07, 2012

# setup eth1

if [ $(whoami) != "root"]; then
	echo "ERROR"
	exit 1
fi

# file exists AND is writable?
if [ -f /etc/network/interfaces ] && [ -w /etc/network/interfaces ]; then

	# appends configuration to /etc/network/interfaces
	echo "
	auto eth1
	iface eth1 inet dhcp

	auto eth0
	iface eth0 inet static
	address 10.10.0.1
	netmask 255.0.0.0
	network 10.0.0.0
	broadcast 10.255.255.255

	" >> /etc/network/interfaces;
else
	echo "ERROR";
fi

# restart network interfaces
/etc/init.d/networking restart

# last operation ok?
if [ $? -ne "0" ]; then
 echo "ERROR"
 exit 1; 
fi


# install libpcap
cd /usr/usr; wget http://www.tcpdump.org/release/libpcap-1.2.0.tar.gz
tar -zxf libpcap-1.2.0.tar.gz && cd libpcap-1.2.0
./configure --prefix=/usr --enable-shared
make && make install

# last operation ok?
if [ $? -ne "0" ]; then
 echo "ERROR"
 exit 1; 
fi

# install libdnet: 
cd /usr/src; wget http://libdnet.googlecode.com/files/libdnet-1.12.tgz
tar -zxf libdnet-1.12.tgz && cd libdnet-1.12
./configure --prefix=/usr --enable-shared
make && make install

# last operation ok?
if [ $? -ne "0" ]; then
 echo "ERROR"
 exit 1; 
fi
I didn't run it 'cause I don't have any debian-based distros here...
 
Old 08-07-2012, 11:16 PM   #4
xsbravo
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Usage of sed & su through shell script

Hi,
Thankyou for your reply I am studying those and they seem helpful (specially # last operation ok?
check by yuripaes) but still there are 4 other things in which I need help.

1: What will be the bullet proof type script to install following;

apt-get update && apt-get install build-essential default-jre unzip libxslt1-dev libpng12-dev libjpeg62-dev ttf-dejavu libtiff4-dev libjasper-dev libfontconfig1-dev libxml2-dev ghostscript libopenexr-dev libwmf-dev librsvg2-dev libfftw3-dev liblzma-dev liblcms1-dev graphviz-dev libdjvulibre-dev openssl xorg libssl-dev mysql-server

2: How to replace the following line in file "/etc/apt/sources.list" with my own using sed;

New Content:
------------
deb http://http.us.debian.org/debian/ squeeze main contrib non-free

Prev content:
------------

deb http://security.debian.org/ squeeze/updates main




3:Now i tried the following script to check if user is logged in as a root user or not, if not then login as root user but when I run this script the shell get login as root user but does not run the remaining script.

if [ `whoami` != root ]; then
echo "$0:Logging as root ";
su
fi

//Remaining script

4: Can any one share link to some recommended shell script tutorial

regards

Last edited by xsbravo; 08-08-2012 at 12:55 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to write script file in Linux? rust8y Linux - General 3 05-20-2006 05:49 AM
Need to learn how to write a script for my RH Linux box. NssOne Programming 3 04-02-2004 11:03 PM

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

All times are GMT -5. The time now is 08:27 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