Skip to content

Instantly share code, notes, and snippets.

@jonathanelbailey
Last active October 8, 2017 03:17
Show Gist options
  • Save jonathanelbailey/784e54452723e5294f456ce46f907cf7 to your computer and use it in GitHub Desktop.
Save jonathanelbailey/784e54452723e5294f456ce46f907cf7 to your computer and use it in GitHub Desktop.
a parameterized script that spins up an ovirt-engine environment.
#! /bin/bash set -e
# run this script using the following command:
# curl -s \
# https://gist.githubusercontent.com/jonathanelbailey/784e54452723e5294f456ce46f907cf7/raw/ \
# | sudo bash /dev/stdin --postgres-password param1 --ovirt-password param2
# getopt is used to create long params for the script.
params=`getopt -o dp:o: --long debug,postgres-password:,ovirt-password: -n 'ovirt_engine_bootstrap' -- "$@"`
# unrecognized params terminate the script.
if [ $? != 0 ] ; then echo "Terminating..." >&2; exit 1; fi
eval set -- "$params"
# param defaults
debug=false
postgrespw=
ovirtpw=
# define parameter outputs.
while true; do
case "$1" in
-d | --debug) debug=true; shift ;;
-p | --postgres-password) postgrespw="$2"; shift 2 ;;
-o | --ovirt-password) ovirtpw="$2"; shift 2 ;;
-- ) shift; break ;;
* ) break ;;
esac
done
# sets debug mode if enabled.
if [ "$debug" == true ]; then
set -x
fi
check_service(){
service=$1
if [ "$(systemctl is-active $service | grep 'active')" ]; then
return 0
else
return 1
fi
}
check_installed_package(){
package=$1
if [ "$(yum list installed $package | grep $package | awk '{print $3}')" == 'installed' ]; then
return 0
else
return 1
fi
}
# install the ovirt 4.1 yum repo
if ! "$(check_installed_package ovirt-release41)"; then
echo "installing ovirt 4.1 release..."
yum install http://resources.ovirt.org/pub/yum-repo/ovirt-release41.rpm -y # allows for the installation of the ovirt host.
fi
if ! "$(check_installed_package ovirt-engine)"; then
echo "installing ovirt-engine..."
yum -y install ovirt-engine
su -l postgres -c "/usr/bin/initdb --locale=en_US.UTF8 --auth='ident' --pgdata=/var/lib/pgsql/data/"
echo "starting postgresql service..."
systemctl start postgresql.service
systemctl enable postgresql.service
echo "creating engine user..."
sudo -u postgres createuser -l -E -W engine
expect "Password: "
send "$postgrespw"
echo "creating engine db..."
sudo -u postgres psql -c "create database engine owner engine template template0 \
encoding 'UTF8' lc_collate 'en_US.UTF-8' lc_ctype 'en_US.UTF-8';"
echo "creating db language..."
sudo -u postgres psql -d engine CREATE LANGUAGE plpgsql;
echo "adding network configs..."
echo "host engine engine 0.0.0.0/0 md5" >> /var/lib/pgsql/data/pg_hba.conf
echo "host engine engine ::0/0 md5" >> /var/lib/pgsql/data/pg_hba.conf
echo "restarting postgresql service..."
systemctl restart postgresql.service
echo "postgresql setup complete. Downloading ovirt answer file..."
curl -s https://gist.githubusercontent.com/jonathanelbailey/08124b61e3346bba8e9d6a74b7d84a85/raw \
> /tmp/answers.conf
# if ![ "$(check_service ovirt-engine.service)" ]; then
# systemctl start
# disabling NetworkManager for compatibility with ovirt
if [ "$(check_service NetworkManager)" ]; then
echo "stopping the NetworkManager Service..."
systemctl stop NetworkManager
fi
engine-setup --config=/tmp/answers.conf
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment