Define truth values to use within the script. Omit debug output while still allowing it to show up with the -D flag.

This commit is contained in:
Pedro Algarvio 2013-02-11 20:44:46 +00:00
parent 2c90980644
commit 062fe28091
2 changed files with 79 additions and 69 deletions

View file

@ -22,6 +22,9 @@ ScriptName="bootstrap-salt.sh"
# LET THE BLACK MAGIC BEGIN!!!! # LET THE BLACK MAGIC BEGIN!!!!
#=============================================================================== #===============================================================================
# Bootstrap script truth values
BS_TRUE=1
BS_FALSE=0
#--- FUNCTION ---------------------------------------------------------------- #--- FUNCTION ----------------------------------------------------------------
# NAME: __detect_color_support # NAME: __detect_color_support
@ -65,7 +68,9 @@ echoinfo() {
# DESCRIPTION: Echo debug information to stdout. # DESCRIPTION: Echo debug information to stdout.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
echodebug() { echodebug() {
echo "${BC} * DEBUG${EC}: $@"; if [ $ECHO_DEBUG -eq $BS_TRUE ]; then
echo "${BC} * DEBUG${EC}: $@";
fi
} }
#=== FUNCTION ================================================================ #=== FUNCTION ================================================================
@ -94,6 +99,7 @@ usage() {
-h Display this message -h Display this message
-v Display script version -v Display script version
-n No colours. -n No colours.
-D Show debug output.
-c Temporary minion configuration directory -c Temporary minion configuration directory
-M Also install salt-master -M Also install salt-master
-S Also install salt-syndic -S Also install salt-syndic
@ -105,11 +111,12 @@ EOT
# Handle command line arguments # Handle command line arguments
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
TEMP_CONFIG_DIR="null" TEMP_CONFIG_DIR="null"
INSTALL_MASTER=0 INSTALL_MASTER=$BS_FALSE
INSTALL_SYNDIC=0 INSTALL_SYNDIC=$BS_FALSE
INSTALL_MINION=1 INSTALL_MINION=$BS_TRUE
ECHO_DEBUG=$BS_FALSE
while getopts ":hvnc:MSN" opt while getopts ":hvnDc:MSN" opt
do do
case "${opt}" in case "${opt}" in
@ -117,10 +124,11 @@ do
v ) echo "$0 -- Version $ScriptVersion"; exit 0 ;; v ) echo "$0 -- Version $ScriptVersion"; exit 0 ;;
n ) COLORS=0; __detect_color_support ;; n ) COLORS=0; __detect_color_support ;;
D ) ECHO_DEBUG=$BS_TRUE ;;
c ) TEMP_CONFIG_DIR="$OPTARG" ;; c ) TEMP_CONFIG_DIR="$OPTARG" ;;
M ) INSTALL_MASTER=1 ;; M ) INSTALL_MASTER=$BS_TRUE ;;
S ) INSTALL_SYNDIC=1 ;; S ) INSTALL_SYNDIC=$BS_TRUE ;;
N ) INSTALL_MINION=0 ;; N ) INSTALL_MINION=$BS_FALSE ;;
\?) echo \?) echo
echoerror "Option does not exist : $OPTARG" echoerror "Option does not exist : $OPTARG"
@ -149,7 +157,7 @@ __check_unparsed_options() {
} }
# Check that we're actually installing one of minion/master/syndic # Check that we're actually installing one of minion/master/syndic
if [ $INSTALL_MINION -eq 0 ] && [ $INSTALL_MASTER -eq 0 ] && [ $INSTALL_SYNDIC -eq 0 ]; then if [ $INSTALL_MINION -eq $BS_FALSE ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ]; then
echoerror "Nothing to install" echoerror "Nothing to install"
exit 1 exit 1
fi fi
@ -495,9 +503,9 @@ echoinfo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}"
echo echo
# Let users know what's going to be installed # Let users know what's going to be installed
[ $INSTALL_MINION -eq 1 ] && echoinfo "Installing minion" [ $INSTALL_MINION -eq $BS_TRUE ] && echoinfo "Installing minion"
[ $INSTALL_MASTER -eq 1 ] && echoinfo "Installing master" [ $INSTALL_MASTER -eq $BS_TRUE ] && echoinfo "Installing master"
[ $INSTALL_SYNDIC -eq 1 ] && echoinfo "Installing syndic" [ $INSTALL_SYNDIC -eq $BS_TRUE ] && echoinfo "Installing syndic"
# Simplify version naming on functions # Simplify version naming on functions
@ -645,13 +653,13 @@ install_ubuntu_1110_post() {
install_ubuntu_stable() { install_ubuntu_stable() {
packages="" packages=""
if [ $INSTALL_MINION -eq 1 ]; then if [ $INSTALL_MINION -eq $BS_TRUE ]; then
packages="${packages} salt-minion" packages="${packages} salt-minion"
fi fi
if [ $INSTALL_MASTER -eq 1 ]; then if [ $INSTALL_MASTER -eq $BS_TRUE ]; then
packages="${packages} salt-master" packages="${packages} salt-master"
fi fi
if [ $INSTALL_SYNDIC -eq 1 ]; then if [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
packages="${packages} salt-syndic" packages="${packages} salt-syndic"
fi fi
__apt_get_noinput ${packages} __apt_get_noinput ${packages}
@ -669,9 +677,9 @@ install_ubuntu_git_post() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f /sbin/initctl ]; then if [ -f /sbin/initctl ]; then
# We have upstart support # We have upstart support
@ -693,9 +701,9 @@ install_ubuntu_git_start_daemons() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f /sbin/initctl ]; then if [ -f /sbin/initctl ]; then
# We have upstart support # We have upstart support
@ -770,13 +778,13 @@ install_debian_60_git_deps() {
install_debian_stable() { install_debian_stable() {
packages="" packages=""
if [ $INSTALL_MINION -eq 1 ]; then if [ $INSTALL_MINION -eq $BS_TRUE ]; then
packages="${packages} salt-minion" packages="${packages} salt-minion"
fi fi
if [ $INSTALL_MASTER -eq 1 ]; then if [ $INSTALL_MASTER -eq $BS_TRUE ]; then
packages="${packages} salt-master" packages="${packages} salt-master"
fi fi
if [ $INSTALL_SYNDIC -eq 1 ]; then if [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
packages="${packages} salt-syndic" packages="${packages} salt-syndic"
fi fi
__apt_get_noinput ${packages} __apt_get_noinput ${packages}
@ -799,9 +807,9 @@ install_debian_git_post() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init ]; then if [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init /etc/init.d/salt-$fname cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init /etc/init.d/salt-$fname
@ -815,9 +823,9 @@ install_debian_git_start_daemons() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
/etc/init.d/salt-$fname start & /etc/init.d/salt-$fname start &
done done
@ -837,10 +845,10 @@ install_fedora_deps() {
install_fedora_stable() { install_fedora_stable() {
packages="" packages=""
if [ $INSTALL_MINION -eq 1 ]; then if [ $INSTALL_MINION -eq $BS_TRUE ]; then
packages="${packages} salt-minion" packages="${packages} salt-minion"
fi fi
if [ $INSTALL_MASTER -eq 1 ] || [ $INSTALL_SYNDIC -eq 1 ]; then if [ $INSTALL_MASTER -eq $BS_TRUE ] || [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
packages="${packages} salt-master" packages="${packages} salt-master"
fi fi
yum install -y ${packages} yum install -y ${packages}
@ -867,9 +875,9 @@ install_fedora_git_post() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
cp ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname.service /lib/systemd/system/salt-$fname.service cp ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname.service /lib/systemd/system/salt-$fname.service
@ -883,9 +891,9 @@ install_fedora_git_start_daemons() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
systemctl try-restart salt-$fname.service systemctl try-restart salt-$fname.service
done done
@ -915,10 +923,10 @@ install_centos_stable_deps() {
install_centos_stable() { install_centos_stable() {
packages="" packages=""
if [ $INSTALL_MINION -eq 1 ]; then if [ $INSTALL_MINION -eq $BS_TRUE ]; then
packages="${packages} salt-minion" packages="${packages} salt-minion"
fi fi
if [ $INSTALL_MASTER -eq 1 ] || [ $INSTALL_SYNDIC -eq 1 ]; then if [ $INSTALL_MASTER -eq $BS_TRUE ] || [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
packages="${packages} salt-master" packages="${packages} salt-master"
fi fi
yum -y install ${packages} --enablerepo=epel-testing yum -y install ${packages} --enablerepo=epel-testing
@ -927,9 +935,9 @@ install_centos_stable() {
install_centos_stable_post() { install_centos_stable_post() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ ! -f /sbin/initctl ] && [ -f /etc/init.d/salt-$fname ]; then if [ ! -f /sbin/initctl ] && [ -f /etc/init.d/salt-$fname ]; then
# Still in SysV init!? # Still in SysV init!?
@ -941,9 +949,9 @@ install_centos_stable_post() {
install_centos_stable_start_daemons() { install_centos_stable_start_daemons() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f /sbin/initctl ]; then if [ -f /sbin/initctl ]; then
# We have upstart support # We have upstart support
@ -992,9 +1000,9 @@ install_centos_git_post() {
for fname in master minion syndic; do for fname in master minion syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f /sbin/initctl ]; then if [ -f /sbin/initctl ]; then
# We have upstart support # We have upstart support
@ -1016,9 +1024,9 @@ install_centos_git_start_daemons() {
for fname in master minion syndic; do for fname in master minion syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f /sbin/initctl ]; then if [ -f /sbin/initctl ]; then
# We have upstart support # We have upstart support
@ -1216,9 +1224,9 @@ install_arch_post() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f /usr/bin/systemctl ]; then if [ -f /usr/bin/systemctl ]; then
# Using systemd # Using systemd
@ -1239,9 +1247,9 @@ install_arch_git_post() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f /usr/bin/systemctl ]; then if [ -f /usr/bin/systemctl ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname.service /lib/systemd/system/salt-$fname.service cp ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname.service /lib/systemd/system/salt-$fname.service
@ -1268,9 +1276,9 @@ install_arch_start_daemons() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
if [ -f /usr/bin/systemctl ]; then if [ -f /usr/bin/systemctl ]; then
/usr/bin/systemctl try-restart salt-$fname.service /usr/bin/systemctl try-restart salt-$fname.service
@ -1360,9 +1368,9 @@ install_freebsd_start_daemons() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
salt-$fname -d & salt-$fname -d &
done done
@ -1436,9 +1444,9 @@ install_smartos_start_daemons() {
for fname in minion master syndic; do for fname in minion master syndic; do
# Skip if not meant to be installed # Skip if not meant to be installed
[ $fname = "minion" ] && [ $INSTALL_MINION -eq 0 ] && continue [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
[ $fname = "master" ] && [ $INSTALL_MASTER -eq 0 ] && continue [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
[ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq 0 ] && continue [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
# Start services # Start services
svcadm enable salt-$fname svcadm enable salt-$fname
@ -1469,7 +1477,7 @@ config_salt() {
[ -d $SALT_DIR ] || mkdir $SALT_DIR [ -d $SALT_DIR ] || mkdir $SALT_DIR
[ -d $PKI_DIR ] || mkdir -p $PKI_DIR && chmod 700 $PKI_DIR [ -d $PKI_DIR ] || mkdir -p $PKI_DIR && chmod 700 $PKI_DIR
if [ $INSTALL_MINION -eq 1 ]; then if [ $INSTALL_MINION -eq $BS_TRUE ]; then
# Create the PKI directory # Create the PKI directory
[ -d $PKI_DIR/minion ] || mkdir -p $PKI_DIR/minion && chmod 700 $PKI_DIR/minion [ -d $PKI_DIR/minion ] || mkdir -p $PKI_DIR/minion && chmod 700 $PKI_DIR/minion
@ -1488,7 +1496,7 @@ config_salt() {
fi fi
if [ $INSTALL_MASTER -eq 1 ] || [ $INSTALL_SYNDIC -eq 1 ]; then if [ $INSTALL_MASTER -eq $BS_TRUE ] || [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
# Create the PKI directory # Create the PKI directory
[ -d $PKI_DIR/master ] || mkdir -p $PKI_DIR/master && chmod 700 $PKI_DIR/master [ -d $PKI_DIR/master ] || mkdir -p $PKI_DIR/master && chmod 700 $PKI_DIR/master

View file

@ -187,4 +187,6 @@ class BootstrapTestCase(TestCase):
err_msg = '{0}STDOUT:\n{1}\n'.format(err_msg, '\n'.join(out)) err_msg = '{0}STDOUT:\n{1}\n'.format(err_msg, '\n'.join(out))
if err: if err:
err_msg = '{0}STDERR:\n{1}\n'.format(err_msg, '\n'.join(err)) err_msg = '{0}STDERR:\n{1}\n'.format(err_msg, '\n'.join(err))
if not err and not out:
err_msg = '{0} No std{out,err} captured.'.format(err_msg)
raise AssertionError(err_msg.rstrip()) raise AssertionError(err_msg.rstrip())