Created
May 25, 2013 20:03
-
-
Save xtraclass/5650579 to your computer and use it in GitHub Desktop.
bash script for installing a SCM server (i.e. Puppet master). Didn't use that for a while, don't know if it still works.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Setup script for a new | |
# | |
# Software Configuration Server | |
# | |
# with: | |
# - a Puppet server | |
# - including my Puppet modules | |
# - a Git repository | |
# - a Yum repository | |
# | |
# based on Red Hat Enterprise Linux 6. | |
# | |
######################################## | |
function check_root() | |
{ | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
} | |
######################################## | |
check_cli() | |
{ | |
if [ -z $1 ]; then | |
echo 'Missing parameter: fqdn' 1>&2 | |
exit 100 | |
fi | |
} | |
######################################## | |
function install() | |
{ | |
if [ -z $1 ]; then | |
echo 'Missing parameter in function install.' 1>&2 | |
exit 2 | |
fi | |
echo Installing $1 | |
\yum install -y -q $1 | |
} | |
######################################## | |
function set_fqdn() | |
{ | |
echo Setting fqdn to $1 | |
fqdn=$1 | |
scriptname='/etc/sysconfig/network' | |
\echo "NETWORKING=yes" > $scriptname | |
\echo "HOSTNAME=$fqdn" >> $scriptname | |
\service network restart | |
\hostname | |
} | |
######################################## | |
function register_at_RHN() | |
{ | |
echo Registering at Red Hat Network | |
\rhn_register | |
} | |
######################################## | |
function update_all_packages() | |
{ | |
echo Updating all packages, this may take a while | |
\yum -y -q update | |
} | |
######################################## | |
function make_yum_repo() | |
{ | |
echo Making Yum repository | |
dir='/var/www/lighttpd' | |
\rm -rf ${dir}/* | |
\chmod 777 $dir | |
\ln -s $dir /yumrepo | |
echo "Yum Repository" > ${dir}/index.html | |
service lighttpd start | |
} | |
######################################## | |
function make_git_repo() | |
{ | |
echo Making Git repository | |
\groupadd --gid 2091 git | |
\adduser --uid 2091 --gid 2091 git | |
dir='/srv/git' | |
\mkdir -p $dir | |
\cd $dir | |
\chown -R git.git . | |
\git init --bare | |
\git update-server-info | |
} | |
######################################## | |
function configure_puppetmaster() | |
{ | |
echo Configuring PuppetMaster, fqdn=$1 | |
# puppet.conf servername | |
fqdn=$1 | |
conf_file='/etc/puppet/puppet.conf' | |
\sed -i "2iserver=$fqdn" $conf_file | |
\cat $conf_file | |
# manifests site.pp | |
site_dir="/etc/puppet/manifests" | |
site_file="${site_dir}/site.pp" | |
\mkdir -p $site_dir | |
echo "node default {" > $site_file | |
echo " package { 'htop': ensure => installed, }" >> $site_file | |
echo "}" >> $site_file | |
cat $site_file | |
} | |
######################################## | |
function download_puppet_my_modules() | |
{ | |
dir='puppet-my' | |
tar="${dir}.tar.gz" | |
url="http://abc/${tar}" | |
puppet_modules_dir='/etc/puppet/modules' | |
\mkdir -p $puppet_modules_dir && \cd /tmp && \wget $url && \tar xfz $tar -C $puppet_modules_dir && \rm $tar && \cd $dir && \ls -al | |
} | |
######################################## | |
function start_puppetmaster() | |
{ | |
\puppet master --no-daemonize -v -d | |
} | |
######################################## | |
check_root | |
check_cli $1 | |
fqdn=$1 | |
set_fqdn $fqdn | |
register_at_RHN | |
update_all_packages | |
install vim | |
install git | |
install yum | |
install puppet | |
install lighttpd | |
make_yum_repo | |
make_git_repo | |
configure_puppetmaster $fqdn | |
download_puppet_my_modules | |
start_puppetmaster |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment