Checking/configuring scripts for fuel-devops

Example of usage:
  $ virtualenv venv-devops
  $ . venv-devops
  $ pip install /path/to/fuel-devops
  $ dos_check_env.sh -I

- dos_check_env.sh - Wrapper which run all checks with/without options.

- dos_check_system.sh - System requirements check
(kvm module/hardware virtualization etc).

- dos_check_packages.sh - Check if all necessary packages are installed.

- dos_check_db.sh - Check DB USER and user GRANTs on DB
in case of PostgreSQL: Check if all necessary packages are installed
in case of SQLite : Check if database exists.

- dos_functions.sh - Set of functions that are used inside of scripts above.

blueprint fuel-devops-installer

Change-Id: Ifa3f0adc3deee85d084ca84fc224a5a8df713838
This commit is contained in:
Serhii Boikov 2016-06-29 18:37:58 +03:00 committed by Serhii Boikov
parent db7af150bb
commit 20f026ba46
6 changed files with 724 additions and 0 deletions

301
bin/dos_check_db.sh Executable file
View File

@ -0,0 +1,301 @@
#!/bin/bash
location=$(dirname $0)
db_opts() {
if [ "${PGSQL}" == "PGSQL" ]; then
if $(dpkg -l|grep -q postgresql); then
if [ "${VERBOSE}" == "VERBOSE" ]; then
echo "PostgreSQL package installed. ----- OK"
sleep 1
fi
else
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "PostgreSQL wasn't installed, would you like to install it?"
if [[ ${YESNO} == [Yy][Ee][sS] ]]; then
echo "Installing PostgreSQL..."
run "apt-get install postgresql --yes"
echo -e "Installation of PostgreSQL successfull. ----- OK\n"
else
echo -e "You've chosen PostgreSQL as backend.\n"\
"PostgreSQL is not installed and your answer is "NO".\nExiting..."
exit 2
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
echo "PostgreSQL wasn't installed.\nInstalling PostgreSQL..."
run "apt-get install postgresql --yes"
echo -e "Installation of PostgreSQL successfull. ----- OK\n"
else
echo -e "PostgreSQL is not installed. ----- ERR\nExiting..."
exit 1
fi
if $(apt-cache policy libpq-dev|grep -q "Installed: (none)"); then
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "libpq-dev wasn't installed, would you like to install it?"
if [[ ${YESNO} == [Yy][Ee][sS] ]]; then
echo "Installing \"libpq-dev\"..."
run "apt-get install libpq-dev --yes"
echo -e "Installation of libpq-dev successfull. ----- OK\n"
else
echo -e "You've chosen PostgreSQL as backend.\n"\
"libpq-dev is not installed and your answer is "NO" devops cannot interact with postgreSQL.\nExiting..."
exit 2
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
echo "\"libpq-dev\" wasn't installed.\nInstalling \"libpq-dev\"..."
run "apt-get install libpq-dev --yes"
echo -e "Installation of libpq-dev successfull. ----- OK\n"
else
echo -e "\"libpq-dev\" is not installed. ----- ERR\nExiting..."
exit 1
fi
fi
fi
if [ "${PG_TRUST}" == "PG_TRUST" ]; then
echo "Replacing peer auth to trust"
run "sed -ir 's/peer/trust/' /etc/postgresql/9.*/main/pg_hba.conf"
check_exit "Can't change peer auth to trust in PostgreSQL settings."
echo "Restarting PostgreSQL service..."
run "service postgresql restart >>/dev/null"
check_exit "PostgreSQL wasn't restarted properly."
else
if [ "${FORCE_YES}" == "FORCE_YES" ]; then
echo "Replacing peer auth to trust"
run "sed -ir 's/peer/trust/' /etc/postgresql/9.*/main/pg_hba.conf"
check_exit "Can't change peer auth to trust in PostgreSQL settings."
echo "Restarting PostgreSQL service..."
run "service postgresql restart >>/dev/null"
check_exit "PostgreSQL wasn't restarted properly."
elif (run "grep -q peer /etc/postgresql/9.*/main/pg_hba.conf"); then
ask "Would you like to change auth method from "peer" to "trust"?"
if [[ ${YESNO} == [Yy][Ee][sS] ]]; then
echo "Replacing peer auth to trust"
run "sed -ir 's/peer/trust/' /etc/postgresql/9.*/main/pg_hba.conf"
check_exit "Can't change peer auth to trust in PostgreSQL settings."
echo "Restarting PostgreSQL service..."
run "service postgresql restart >>/dev/null"
fi
else
echo -e "Auth method \"peer\" can't be used. ----- ERR\nExiting..."
exit 1
fi
fi
if [ -z "${PG_USER}" ]; then
echo "Postgresql database user wasn't set using default ${PG_USER:=fuel_devops}"
fi
if [ -z "${PG_PASS}" ]; then
echo "Password for user ${PG_USER} wasn't set using default ${PG_PASS:=fuel_devops}"
fi
if [ -z "${PG_DATABASE}" ];then
echo "Name for Postgresql database wasn't set using default ${PG_DATABASE:=fuel_devops}"
fi
else
if [ -z "${SQLITE_DB_PATH}" ]; then
echo "SQLite database path wasn't set using default ${SQLITE_DB_PATH:=$(readlink -f ~/devops_$(dos.py version).sqlite3)}"
fi
if [ -s "${SQLITE_DB_PATH}" ]; then
if [ "${INTERACTIVE}" == "INTERACTIVE" -a -s "${SQLITE_DB_PATH}" ]; then
ask "SQLite database \"${SQLITE_DB_PATH}\" already exist would you like to rewrite it with the new content?"
if [[ ${YESNO} == [Yy][Ee][sS] ]]; then
echo -e "SQLite database wil be rewritten"
fi
elif [ "${FORCE_YES}" == "FORCE_YES"]; then
echo -e "SQLite database exists but force mode set so it will be rewritten"
else
echo -e "SQLite database \"${SQLITE_DB_PATH}\" already exists. ----- ERR\nExiting..."
exit 1
fi
fi
fi
}
create_db_user() {
if [[ "$(psql -U postgres -tAc 'SELECT 1 FROM pg_roles WHERE rolname='\'${PG_USER}\''')" == "1" ]]; then
echo -e "User with the name ${PG_USER} already exists. ----- ERR\nExiting..."
exit 1
else
psql -U postgres -c 'CREATE ROLE '${PG_USER}' PASSWORD '\'${PG_PASS}\'' LOGIN'
fi
}
create_db() {
if ! $(createdb -U postgres ${PG_DATABASE} -O "${PG_USER}"); then
echo "Database with the name \"${PG_DATABASE}\" already exists. ----- ERR\nExiting..."
exit 1
fi
}
env_check() {
if [ ! -z ${VIRTUAL_ENV} ]; then
echo -e "Adding necessary ENV variables into \"${VIRTUAL_ENV}/bin/activate\""
devops_env_vars "${VIRTUAL_ENV}/bin/activate"
else
echo -e "Adding necessary ENV variables into \"$(readlink -f ~/.bashrc_devops)\""
devops_env_vars ~/.bashrc_devops
fi
}
devops_env_vars() {
if [ ! -z "${SQLITE_DB_PATH}" ]; then
echo "Adding \"export DEVOPS_DB_ENGINE='django.db.backends.sqlite3'\" to ${1} ----- OK"
echo "export DEVOPS_DB_ENGINE='django.db.backends.sqlite3'" >> "${1}"
echo "Adding \"export DEVOPS_DB_NAME=\"${SQLITE_DB_PATH}\"\" to ${1} ----- OK"
echo "export DEVOPS_DB_NAME=\"${SQLITE_DB_PATH}\"" >> "${1}"
if [ ! -z "${VIRTUAL_ENV}" ]; then
echo "Adding ability for VIRTUAL_ENV to remove DB variables with deactivate function ----- OK"
sed -i "s/\(unset VIRTUAL_ENV\)/\1 DEVOPS_DB_ENGINE DEVOPS_DB_NAME/" "${1}"
fi
else
echo "Adding \"export DEVOPS_DB_ENGINE='django.db.backends.postgresql_psycopg2'\" to ${1} ----- OK"
echo "export DEVOPS_DB_ENGINE='django.db.backends.postgresql_psycopg2'" >> "${1}"
echo "Adding \"export DEVOPS_DB_NAME=\"${PG_DATABASE}\"\" to ${1} ----- OK"
echo "export DEVOPS_DB_NAME=\"${PG_DATABASE}\"" >> "${1}"
echo "Adding \"export DEVOPS_DB_USER=\"${PG_USER}\"\" to ${1} ----- OK"
echo "export DEVOPS_DB_USER=\"${PG_USER}\"" >> "${1}"
echo "Adding \"export DEVOPS_DB_PASSWORD=\"${PG_PASS}\"\" to ${1} ----- OK"
echo "export DEVOPS_DB_PASSWORD=\"${PG_PASS}\"" >> "${1}"
if [ ! -z "${VIRTUAL_ENV}" ]; then
echo "Adding ability for VIRTUAL_ENV to remove DB variables with deactivate function ----- OK"
sed -i "s/\(unset VIRTUAL_ENV\)/\1 DEVOPS_DB_ENGINE DEVOPS_DB_NAME DEVOPS_DB_PASSWORD DEVOPS_DB_USER/" "${1}"
fi
fi
source "${1}"
dos-manage.py migrate
echo "Please activate virtual env or run \"source ~/.bashrc_devops\" (in case if fuel-devops was installed into system) so database variables get in your user env and you could use dos.py"
}
alter_db_owner() {
echo -e "Creating user \"${PG_USER}\"..."
psql -U postgres -c 'CREATE ROLE '${PG_USER}' PASSWORD '\'${PG_PASS}\'' LOGIN'
echo -e "Making user \"${PG_USER}\" owner of \"${PG_DATABASE}\""
psql -U postgres -c "ALTER DATABASE ${PG_DATABASE} OWNER TO ${PG_USER}"
}
drop_db() {
echo -e "Dropping database \"${PG_DATABASE}\"..."
dropdb -U "${PG_USER}" "${PG_DATABASE}" 2>&1 >/dev/null
check_exit "Something has happened while terminating database \"${PG_DATABASE}\"."
}
drop_db_user() {
echo -e "Dropping user \"${PG_USER}\""
dropuser -U postgres "${PG_USER}"
check_exit "Something has happened while terminating \"${PG_USER}\"."
}
install_func() {
if [ ! -z "${PGSQL}" ]; then
if [ ! -z "${PG_DATABASE}" ] && $(psql -Upostgres -lqAt|grep -Eq "^${PG_DATABASE}\|"); then
if [[ "$(psql -U postgres -tAc 'SELECT 1 FROM pg_roles WHERE rolname='\'${PG_USER}\''')" == "1" ]]; then
echo -e "Database \"${PG_DATABASE}\" and user \" ${PG_USER}\" exists. ----- OK"
if [ $(psql -U ${PG_USER} -tc "select datdba from pg_database where datname='${PG_DATABASE}';") == $(psql -U ${PG_USER} -tc "select usesysid from pg_user where usename='${PG_USER}';") ]; then
echo -e "User \"${PG_USER}\" is owner of \"${PG_DATABASE}\""
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "Would you like to re-create database and user?"
if [[ "${YESNO}" == [Yy][Ee][sS] ]]; then
drop_db
drop_db_user
echo -e "Creating user \"${PG_USER}\" and database \"${PG_DATABASE}\"."
create_db_user
create_db
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
drop_db
drop_db_user
echo -e "Creating user \"${PG_USER}\" and database \"${PG_DATABASE}\"."
create_db_user
create_db
else
echo -e "User \"${PG_USER}\" is owner of \"${PG_DATABASE}\" continue checking. ----- OK"
fi
else
echo -e "User \"${PG_USER}\" is not owner of database \"${PG_DATABASE}\" cannot continue configuration of database. ----- ERR\nExiting..."
exit 1
fi
else
echo -e "User with the name \"${PG_USER}\" doesn't exist."
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "Would you like to create user \"${PG_USER}\" and make it owner of \"${PG_DATABASE}\"?"
if [[ "${YESNO}" == [Yy][Ee][sS] ]]; then
alter_db_owner
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
alter_db_owner
else
echo -e "User doesn't exist. ----- ERR\nExiting..."
exit 1
fi
fi
else
if [[ "$(psql -U postgres -tAc 'SELECT 1 FROM pg_roles WHERE rolname='\'${PG_USER}\''')" == "1" ]]; then
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "User \"${PG_USER}\" already exist, would you like to create Database \"${PG_DATABASE}\" and set owner to \"${PG_USER}\"?"
if [[ "${YESNO}" == [Yy][Ee][sS] ]]; then
echo -e "Creating database \"${PG_DATABASE}\""
create_db
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
echo -e "Creating database \"${PG_DATABASE}\""
create_db
else
echo -e "User \"${PG_USER}\" already exist, but database \"${PG_DATABASE}\" doesn't exist. ----- ERR\nExiting..."
exit 1
fi
else
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "No user and database were found, would you like to create them?"
if [[ "${YESNO}" == [Yy][Ee][sS] ]]; then
echo -e "Creating database \"${PG_DATABASE}\" and user \"${PG_USER}\""
create_db_user
create_db
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
echo -e "Creating database \"${PG_DATABASE}\" and user \"${PG_USER}\""
create_db_user
create_db
else
echo -e "No database \"${PG_DATABASE}\" and user \"${PG_USER}\" were found. ----- ERR\nExiting..."
exit 1
fi
fi
fi
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "Would you like to add database variables into env variables?"
if [[ "${YESNO}" == [Yy][Ee][sS] ]]; then
env_check
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
env_check
else
echo "Neither \"interacitve\" nor \"force-yes\" modes were set check is successfully complete without any changes to system. ----- OK"
exit 0
fi
else
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "Would you like to add database variables into env variables?"
if [[ "${YESNO}" == [Yy][Ee][sS] ]]; then
env_check
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
env_check
else
echo "Neither \"interactive\" nor \"force-yes\" modes were set check is successfully complete without any changes to system. ----- OK"
exit 0
fi
fi
}
. "${location}/dos_functions.sh"
if [ $(basename -- "$0") == "dos_check_db.sh" ]; then
set -ex
opts $@
db_opts
install_func
fi

38
bin/dos_check_env.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/bash
set -e
longopts="help,verbose,interactive,pgsql-auth-trust,force-yes,pgsql,pg-user:,pg-password:,pg-database:,sqlite-database:"
package_list="git,libyaml-dev,libffi-dev,python-dev,python-pip,qemu,libvirt-bin,libvirt-dev,vlan,bridge-utils,genisoimage"
location=$(dirname $0)
usage() {
cat << EOF
Usage $0 [OPTIONS]...VALUE
########################################################################################################################################################################
# -H/-h (--help) - Show this help. #
# -V (--vebose) - Option that is increase verbosity level (bash -x). #
# -I (--interactive) - Option makes script to ask questions. #
# -A (--pgsql-auth-trust) - Change auth method to trust insteacd of peer (required --pgsql). #
# -P (--pgsql) - Use pgsql db instead of sqlite3. #
# -F (--force-yes) - Yes to all additional changes (required SUDO PASSWD or run by root). #
# -U (--pg-user) - User for devops database (required --pgsql) DEFAULT value "fuel_devops". #
# -p (--pg-password) - User password for potgreSQL (required --pgsql) DEFAULT value "fuel_devops" . #
# -D (--pg-database) - Name of PostgreSQL database (required --pgsql) DEFAULT value "fuel_devops". #
# -S (--sqlite-database) - Path to the sqlite database with the name (e.g. /path/somewhere/database_name) DEFAULT $HOME/devops.sqlite3. #
########################################################################################################################################################################
EOF
}
. "${location}/dos_functions.sh"
. "${location}/dos_check_system.sh"
. "${location}/dos_check_packages.sh"
. "${location}/dos_check_db.sh"
opts $@
cpu_check
check_packages "${package_list}"
db_opts
install_func

51
bin/dos_check_packages.sh Executable file
View File

@ -0,0 +1,51 @@
#!/bin/bash
location=$(dirname $0)
package_list="git,libyaml-dev,libffi-dev,python-dev,python-pip,qemu,libvirt-bin,libvirt-dev,vlan,bridge-utils,genisoimage"
#Check if all necessary packages are installed.
check_packages() {
OLD_IFS="${IFS}"
IFS=","
if [ "${N}" == "" ]; then
echo "Running apt-get update before checking"
run "apt-get update"
N+="1"
fi
for package in ${1}; do
if $(apt-cache policy ${package}|grep -q "Installed: (none)"); then
if [ "${VERBOSE}" == "VERBOSE" ]; then
echo "Package ${package} doesn't installed"
sleep 1
fi
instalation_packages+="${package} "
else
if [ "${VERBOSE}" == "VERBOSE" ]; then
echo -e "Package ${package} is already installed. ----- OK\n"
sleep 1
fi
fi
done
IFS="${OLD_IFS}"
if [ "${INTERACTIVE}" == "INTERACTIVE" -a -n "${instalation_packages}" ]; then
ask "Would you like to install followig package\(s\): [ ${instalation_packages}]"
if [[ "${YESNO}" == [Yy][Ee][Ss] ]]; then
run "apt-get install --yes ${instalation_packages}"
fi
elif [ -n "${instalation_packages}" ]; then
if [ "${FORCE_YES}" == "FORCE_YES" ]; then
run "apt-get install --yes ${instalation_packages}"
else
echo -e "Following pakage(s) are not installed [ ${instalation_packages}]. ----- ERR\nExiting..."
exit 1
fi
fi
unset instalation_packages
}
. "${location}/dos_functions.sh"
if [ $(basename -- "$0") == "dos_check_packages.sh" ]; then
set -ex
check_packages "${package_list}"
fi

114
bin/dos_check_system.sh Executable file
View File

@ -0,0 +1,114 @@
#!/bin/bash
location=$(dirname $0)
#Body of script which check what CPU are in use.
cpu_check() {
case $(awk '/vendor_id/ {print $3}' /proc/cpuinfo|sort -u) in
GenuineIntel*)
cpu_type="intel"
cpu_virtualization_check "vmx"
;;
AuthenticAMD*)
cpu_type="amd"
cpu_virtualization_check "svm"
;;
*)
echo -e "Unknown CPU vendor. ----- ERR\nExiting..."
exit 1
;;
esac
}
#Check if hardware virtualization disabled.
cpu_virtualization_check() {
if $(grep -qom1 "${1}" /proc/cpuinfo); then
echo -e "Hardware virtualization enabled in BIOS. ----- OK\n"
echo -e "Checking kernel module \"kvm_${cpu_type}\" loaded or not.\n"
sleep 1
kvm_kernel_check
else
echo -e "Hardware virtualization doesn't enabled. ----- ERR\nExiting..."
exit 1
fi
}
#Check if KVM kernel module lodaded according to detected CPU(AMD/INTEL).
kvm_kernel_check() {
if $(lsmod|grep -qom1 "kvm_${cpu_type}"); then
echo -e "Kernel module \"kvm_${cpu_type}\" loaded. ----- OK\n"
echo -e "Checking \"Nested Paging\" enabled or not.\n"
nested_pagging_check
else
if [ ${INTERACTIVE} == "INTERACTIVE" ]; then
ask "Would you like to load kvm_${cpu_type} module till the reboot?"
if [[ ${YESNO} == [Yy][Ee][sS] ]]; then
run "/sbin/modprobe kvm_${cpu_type}"
check_exit "Something has happened while loading kernel module kvm_${cpu_type}."
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
run "/sbin/modprobe kvm_${cpu_type}"
check_exit "Something has happened while loading kernel module kvm_${cpu_type}."
else
echo -e "Kernel Module \"kvm_${cpu_type}\" isn't loaded. ----- ERR\nExiting..."
exit 1
fi
fi
}
#Check whether nested pagging enabled of not.
nested_pagging_check() {
if $(grep -q "^Y$" "/sys/module/kvm_${cpu_type}/parameters/nested"); then
echo -e "Nested pagging is enabled. ----- OK\n"
ip_filters
else
echo -e "Nested Pagging is not enabled. ----- ERR\nExiting..."
exit 1
fi
}
#Check whether bridge filtration rules enbled in kernel or not.
ip_filters() {
ORIG_IFS="${IFS}"
IFS=$'\n'
for filter in $(sysctl -a 2>&1|grep -P "net.bridge.bridge-nf-call-(arp|ip|ip6)tables"); do
if [ "${filter: -1}" == "1" ]; then
echo -e "${filter:26: -4} filter is enabled"
if [ "${INTERACTIVE}" == "INTERACTIVE" ]; then
ask "Would you like to permanently deactivate ${filter:26: -4} filter?"
if [[ ${YESNO} == [Yy][Ee][sS] ]]; then
if ! $(grep -q "${filter:: -1}0" "/etc/sysctl.d/net-bridge-filters.conf"); then
echo "Filter ${filter:26: -4} will be disabled"
run "echo ${filter:: -1}0 >> /etc/sysctl.d/net-bridge-filters.conf"
else
echo -e "${filter:: -1}0 already in /etc/sysctl.d/net-bridge-filters.conf\n"
fi
fi
elif [ "${FORCE_YES}" == "FORCE_YES" ]; then
if ! $(grep -q "${filter:: -1}0" "/etc/sysctl.d/net-bridge-filters.conf"); then
echo "Filter ${filter:26: -4} will be disabled"
run "echo ${filter:: -1}0 >> /etc/sysctl.d/net-bridge-filters.conf"
check_exit "Something has happened while addind ${filter:26: -4} to /etc/sysctl.d/net-bridge-filters.conf."
else
echo -e "${filter:: -1}0 already in /etc/sysctl.d/net-bridge-filters.conf\n"
echo "Will apply changes in the end"
fi
fi
else
echo "Filter ${filter:26: -4} not enabled. ----- OK"
disabled_filters+="${filter:26: -4}\n"
fi
done
if [ -s /etc/sysctl.d/net-bridge-filters.conf ]&&[ $(echo -e "${disabled_filters}" |wc -l) -lt "4" ]; then
echo -e "Applying changes to the kernel.\n"
run "sysctl -p /etc/sysctl.d/net-bridge-filters.conf"
fi
IFS="${ORIG_IFS}"
}
. "${location}/dos_functions.sh"
if [ $(basename -- "$0") == "dos_check_system.sh" ]; then
set -ex
cpu_check
fi

215
bin/dos_functions.sh Normal file
View File

@ -0,0 +1,215 @@
#!/bin/bash
#Function for execution with/without SUDO
run() {
if [ $(id -u) -eq 0 ]; then
/bin/bash -c "${1}" > /dev/null
else
sudo /bin/bash -c "${1}" >/dev/null
fi
}
#Function for checking exit code
check_exit() {
if [ "${?}" -ne 0 ]; then
echo -e "${1} ----- ERR\nExiting..."
exit 1
fi
}
#Function check whether user has sudo or run script as root.
get_pass() {
if [ $(id -u) -eq 0 ]; then
echo -e "You are running script with root permissions, be careful!\n"
else
read -sp "Please enter your SUDO password:" PASSWD
sudo -S -l <<< "${PASSWD}" 2>&1 >/dev/null
if [ "${?}" -ne 0 ]; then
echo -e "Sudo password (${PASSWD}) is incorrect. ----- ERR\nExiting..."
exit 1
fi
fi
}
#Determines which Linux Distro is on the host.
where_am_i() {
case $(lsb_release -is) in
Gentoo*)
echo -e "Gentoo Linux Detected.\n"
pkg_mng=$(which emerge)
;;
Ubuntu*)
echo -e "Ubuntu Linux detected.\n"
pkg_mng=$(which apt-get)
if [ -z "${pkg_mng}" ]; then
alt_pkg_mng=$(which dpkg)
fi
;;
Debian*)
echo -e "Debian Linux detected.\n"
pkg_mng=$(which apt-get)
if [ -z "${pkg_mng}" ]; then
alt_pkg_mng=$(which dpkg)
fi
;;
Fedora*)
echo -e "Fedora Linux detected.\n"
pkg_mng=$(which yum)
if [ -z "${pkg_mng}" ]; then
alt_pkg_mng=$(which rpm)
fi
;;
SUSE*)
echo -e "Suse Linux detected.\n"
pkg_mng=$(which zypper)
if [ -z "${pkg_mng}" ]; then
alt_pkg_mng=$(which rpm)
fi
;;
*)
if [ -s /etc/redhat-release ]; then
if $(grep -qo "el7" /proc/version); then
echo -e "CentOS 7 detected.\n"
pkg_mng=$(which yum)
if [ -z "${pkg_mng}" ]; then
alt_pkg_mng=$(which rpm)
fi
elif $(grep -qo "el6" /proc/version); then
echo -e "CentOS 6 detected.\n"
pkg_mng=$(which yum)
if [ -z "${pkg_mng}" ]; then
alt_pkg_mng=$(which rpm)
fi
else
echo "Unknown RedHat distro."
pkg_mng=$(which yum)
if [ -z "${pkg_mng}" ]; then
alt_pkg_mng=$(which rpm)
fi
if [ -z "${pkg_mng}" -o -z "${alt_pkg_mng}" ]; then
echo -e "Couldn't get any package manager. ----- ERR\nExiting"
exit 1
fi
fi
else
echo "Unknown Linux Distro! ----- ERR\nExiting..."
exit 1
fi
;;
esac
}
usage() {
cat << EOF
Usage $0 [OPTIONS]...VALUE
########################################################################################################################################################################
# -H/-h (--help) - Show this help. #
# -V (--vebose) - Option that is increase verbosity level (bash -x). #
# -I (--interactive) - Option makes script to ask questions. #
# -A (--pgsql-auth-trust) - Change auth method to trust insteacd of peer (required --pgsql). #
# -P (--pgsql) - Use pgsql db instead of sqlite3. #
# -F (--force-yes) - Yes to all additional changes (required SUDO PASSWD or run by root). #
# -U (--pg-user) - User for devops database (required --pgsql) DEFAULT value "fuel_devops". #
# -p (--pg-password) - User password for potgreSQL (required --pgsql) DEFAULT value "fuel_devops" . #
# -D (--pg-database) - Name of PostgreSQL database (required --pgsql) DEFAULT value "fuel_devops". #
# -S (--sqlite-database) - Path to the sqlite database with the name (e.g. /path/somewhere/database_name) DEFAULT $HOME/devops_${devops_version}.sqlite3. #
########################################################################################################################################################################
EOF
}
opts() {
opt=$(getopt -o HhVIAPFU:p:D:S: --long "${longopts}" -n "$0" -- "$@")
if [ $? -ne 0 ]; then
usage
exit 1
elif [[ $@ =~ ^\-\-$ ]]; then
# elif [[ ! $@ =~ ^\-.+ ]] || [[ $@ =~ ^\-\-$ ]]; then
usage
exit 0
# elif [[ ! $@ =~ ^\-.+ ]]; then
fi
eval set -- "$opt"
while true; do
case "${1}" in
-H|-h|--help)
usage
shift
exit 0
;;
-V|--verbose )
VERBOSE="VERBOSE"
echo "Verbose mode ON"
set -x
shift
;;
-I|--interactive )
INTERACTIVE="INTERACTIVE"
shift
echo "Interactive mode ON"
;;
-F|--force-yes)
FORCE_YES="FORCE_YES"
shift
;;
-P|--pgsql)
PGSQL="PGSQL"
shift
;;
-A|--pgsql-auth-trust)
PG_TRUST="PG_TRUST"
shift
;;
-U|--pg-user)
PG_USER="${2}"
shift 2
;;
-D|--pg-database)
PG_DATABASE="${2}"
shift 2
;;
-p|--pg-password)
PG_PASS="${2}"
shift 2
;;
-S|--sqlite-database)
SQLITE_DB_PATH=$(readlink -f "${2}".sqlite3)
shift 2
;;
-- )
shift
break
;;
* )
break
;;
esac
done
if [ "${INTERACTIVE}" == "INTERACTIVE" -a "${FORCE_YES}" == "FORCE_YES" ]; then
echo -e "Impossible to use both interactive and force-yes modes at the same time. ----- ERR\nExiting..."
exit 1
fi
if [ ! -z "${PGSQL}" -a ! -z "${SQLITE_DB_PATH}" ]; then
echo "Impossible to use both database engines at the same time. ----- ERR\nExiting..."
exit 1
fi
if ! [ "${PG_TRUST}" != "PG_TRUST" ]||[ "${PG_USER}" != "" ]||[ "${PG_DATABASE}" != "" ]||[ "${PG_PASS}" != "" ]&&[ "${PGSQL}" != "PGSQL" ]; then
echo -e "PGSQL option is not enabled. ----- ERR\nExiting."
exit 1
fi
}
#Question function which will ask questions.
ask() {
read -p "${1} [YES/no]: " YESNO
while ! $(grep -Eqi '(yes|no)' <<< "${YESNO}"); do
echo "Incorrect input please use only [YES/no]: "
sleep 1
read -p "${1} [YES/no]: " YESNO
done
}

View File

@ -31,7 +31,12 @@ setup(
scripts=[
'bin/dos.py',
'bin/dos-manage.py',
'bin/dos_check_env.sh',
'bin/dos_check_system.sh',
'bin/dos_check_packages.sh',
'bin/dos_check_db.sh',
],
data_files=[('bin', ['bin/dos_functions.sh'])],
install_requires=[
'keystoneauth1>=2.1.0',
'netaddr>=0.7.12,!=0.7.16',