LinuxQuestions.org
Visit Jeremy's Blog.
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 06-26-2016, 03:46 AM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Rep: Reputation: 0
Unhappy Creating an auto-deployment script for centos


Hi Moderator,

Update, fixed the script until the point that it is now failing because a package is already installed. Need help with actual failure than a false failure.

Hi Guys,

Is this script good enough??

I build a CentOS VM every now and then and I what I want to achieve is to create a package(much preferred) but to begin with I want to create an auto deployment script which would do all the work for me while I do rest of the things.

Code:
[root@agent2 jim]# cat installation.sh 
#!/bin/bash

set -x

function failed
{
STATUS=$(echo $?)

if [[ "${STATUS}" ==  "0" ]]; then
	echo "All good continue"
else
	exit 1
fi
}

cd /tmp
failed

yum -y install epel-release #Adding EPEL Repositories
failed

cd /tmp/
failed

wget https://centos7.iuscommunity.org/ius-release.rpm
failed

sudo rpm -Uvh ius-release*.rpm
failed

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
failed

sudo rpm -Uvh remi-release-7*.rpm
failed

cd /tmp/ && wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
failed

yum repolist
failed

rpm -Uvh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
failed

yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
failed

yum -y install http://linuxdownload.adobe.com/linux/x86_64/adobe-release-x86_64-1.0-1.noarch.rpm
failed

yum -y install flash-plugin
failed

yum -y install icedtea-web
failed

yum -y install vlc smplayer ffmpeg HandBrake-{gui,cli}
failed

yum -y install libdvdcss gstreamer{,1}-plugins-ugly gstreamer-plugins-bad-nonfree gstreamer1-plugins-bad-freeworld
failed

yum groupinstall "Development Tools"
failed

yum -y update
failed

exit 0
[root@agent2 jim]#
Output:
Code:
+ sudo rpm -Uvh ius-release.rpm
warning: ius-release.rpm: Header V4 DSA/SHA1 Signature, key ID 9cd4953f: NOKEY
Preparing...                          ################################# [100%]
	package ius-release-1.0-14.ius.centos7.noarch is already installed
+ failed
++ echo 1
+ STATUS=1
+ [[ 1 == \0 ]]
+ exit 1
[root@agent2 jim]#
1. At professional level is this script good enough? Yeah I am newbie therefore asking.
2. Why I am getting error at the execution step ? The installation shouldn't failed because a package is already existing but carry on with rest of the script.

Any help would be very much appreciated.

Last edited by sysmicuser; 06-26-2016 at 04:22 AM.
 
Old 06-26-2016, 08:45 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
A script is good enough if it accomplishes the desired goal. Even though it is only a warning rpm sets the return value to nonzero which causes your failed function to exit.

If the result status is not important then your failed function is not required.
 
Old 06-26-2016, 09:26 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
My question would be why the arbitrary points at checking for failure? I do follow that the points where you have multiple programs listed to install, you have tried to group together
like programs or dependent ones, but really, if you have a failure on any one program, shouldn't that be cause for alarm?

As stated above by michaelk, if the warning is to be allowed to pass then you need to alter the failure test to allow for it.

As to the script itself, my first thought is always towards the future editing (that will always occur). To that end, currently when you want to add a new program or group you need to scroll
through the script until you find the appropriate spot. I generally prefer to put all like things together, so with this type of script it would scream array(s) to me.

So here is an example of the sort of thing I would do, with some vague comments that you would need to flesh out:
Code:
set -x

function failed
{
STATUS=$(echo $?)

if [[ "${STATUS}" ==  "0" ]]; then
  echo "All good continue"
else
  # where is the error message that something went wrong??
  exit 1
fi
}

download_rpms=(
                "https://centos7.iuscommunity.org/ius-release.rpm"
                "http://rpms.famillecollet.com/enterprise/remi-release-7.rpm"
                "http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm"
              )

yum_installs=(
              epel-release
              "http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm"
              "http://linuxdownload.adobe.com/linux/x86_64/adobe-release-x86_64-1.0-1.noarch.rpm"
              flash-plugin
              icedtea-web
              vlc smplayer ffmpeg HandBrake-{gui,cli}
              libdvdcss gstreamer{,1}-plugins-ugly gstreamer-plugins-bad-nonfree gstreamer1-plugins-bad-freeworld
             )

# Perform work in /tmp
cd /tmp
#failed - if this step fails you have much bigger issues

# Get all the rpms required
wget "${download_rpms[@]}"
failed

# Install retrieved rpms
for address in "${download_rpms[@]}"
do
  file=${address##*/}

  sudo rpm -Uvh "$file"
  failed
done

# Update the repolist
yum repolist
failed

# Yum installs
for file in "${yum_installs[@]}"
do
  yum -y "$file"
  failed
done

# Perform singular group install
yum groupinstall "Development Tools"
failed

# Update entire machine as needed
yum -y update
failed

exit 0
 
1 members found this post helpful.
Old 06-26-2016, 04:59 PM   #4
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I think CentOS (Red Hat, Fedora) uses kickstart to create auto installation scripts. You can install the system the way you wish, and then grab /root/anaconda-ks.cfg file. Put that file on some media. Read the rest here:
https://access.redhat.com/documentat...tallation.html
 
  


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
Creating an init script for uwsgi using a deployment script spadez Programming 1 02-23-2015 01:11 PM
[SOLVED] help with creating auto-update script? jamtat Programming 9 10-01-2014 08:50 PM
creating an auto install script mia_tech Linux - General 1 03-10-2014 07:43 PM
run auto script when interface comes up or down on centos bobo0110 Linux - Server 1 03-15-2011 04:31 AM
run auto script when interface comes up or down on centos bobo0110 Linux - Newbie 2 03-15-2011 02:15 AM

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

All times are GMT -5. The time now is 10:45 PM.

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