Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of an interactivr shell script
#!/bin/bash
checkParam() {
for PARAM in $*; do
test "${PARAM}" == "-i" && INTERACTIVE=true
test "${PARAM}" == "--interactive" && INTERACTIVE=true
done
}
setVars() {
if [ "$INTERACTIVE" == "true" ];
then
read -p "Hostname:" HOSTNAME
##### Environment
echo -n "
Environment:
1: development
2: QA
3: liveDE
4: liveUK
"
read -p "Num:" ENVNUM
case "$ENVNUM" in
1 ) ENVIRONMENT=development
;;
2 ) ENVIRONMENT=QA
;;
3 ) ENVIRONMENT=liveDE
;;
4 ) ENVIRONMENT=liveUK
;;
* ) echo "Sorry... wrong key."
return 0
;;
esac
##### Hostgroup
echo -n "
Host Group:
1: Webnode
2: Cronserver
3: Devnode
4:
"
read -p "Num:" GROUPNUM
case "$GROUPNUM" in
1 ) HOSTGROUP=1
;;
2 ) HOSTGROUP=2
;;
3 ) HOSTGROUP=3
;;
4 ) HOSTGROUP=4
;;
* ) echo "Sorry... wrong key."
return 0
;;
esac
else
HOSTNAME=$1
ENVIRONMENT=$2
HOSTGROUP=$3
fi
sudo echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
}
spellCheck() {
if [ "$INTERACTIVE" != "true" ];
then
case "$ENVIRONMENT" in
development | liveDE | liveUK | QA | QATest )
;;
* ) echo "Sorry... wrong environment."
return 0
;;
esac
case "$HOSTGROUP" in
Webnode | Cronserver )
;;
* ) echo "Sorry... wrong Host Group."
return 0
;;
esac
return 1
fi
}
aptupdate() {
sudo apt-get update
}
installPuppet() {
# Install puppet client
# Set hostname
echo "$HOSTNAME" > /etc/hostname
sudo hostname $HOSTNAME
sudo apt-get install puppet -y
# Make puppet client to know our foreman
sudo echo "[main]
logdir=/var/log/puppet
vardir=/var/log/puppet
ssldir=/var/log/puppet/ssl
rundir=/var/run/puppet
factpath=\$vardir/lib/facter
templatedir=\$confdir/templates
prerun_command=/etc/puppet/etckeeper-commit-pre
postrun_command=/etc/puppet/etckeeper-commit-post
server=foreman.it.mau.myhammer.net
listen=true
environment=$ENVIRONMENT
[master]
# These are needed when the puppetmaster is run by passenger
# and can safely be removed if webrick is used.
ssl_client_header = SSL_CLIENT_S_DN
ssl_client_verify_header = SSL_CLIENT_VERIFY
" > /etc/puppet/puppet.conf
# allow autthentication with foreman
sudo echo "path /run
auth any
method save
allow foreman.it.mau.myhammer.net
" > /etc/puppet/auth.conf
# auto start of puppet agent during VM boot
sudo echo "#Start puppet on boot?
START=yes
# Startup options
DAEMON_OPTS=\"\"
" > /etc/default/puppet
# Start puppet agent
sudo service puppet stop
sudo puppet agent --no-daemonize --onetime
sleep 5
}
installRuby() {
sudo apt-get install ruby1.9.1-full -y
sudo apt-get install rubygems -y
rm -f /etc/alternatives/ruby
ln -s /usr/bin/ruby1.9.1 /etc/alternatives/ruby
rm -f /etc/alternatives/gem
ln -s /usr/bin/gem1.9.1 /etc/alternatives/gem
sudo gem install rest-client
sudo gem install json
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment