Fix tests, the run tests script and ubuntu git installs.

* The run tests script now requires root permissions to execute.
* Ubuntu git installs were starting upstarts services without checking if they were already running.
* We now also check if upstart support exists and use upstarts files instead of the `init.d` files, ie, or upstart or `init.d`.
* On Debian and Ubuntu we gather the packages to install(master, minion, syndic) and install them in one command.
* We now detect if the script is running piped or not.
This commit is contained in:
Pedro Algarvio 2013-01-25 20:18:08 +00:00
parent 9cd312f7d6
commit 3369cf8b3d
2 changed files with 85 additions and 42 deletions

View file

@ -17,29 +17,50 @@
set -o nounset # Treat unset variables as an error
if [ $(whoami) != "root" ] ; then
title="You need to run this script as root."
line="$(printf "%${COLUMNS}s" "")"
printf "\033[1;31m%*s\033[0m\n" $(((${#title}+$COLUMNS)/2)) "$title"
printf "\033[1;31m%s\033[0m\n" "${line// /*}"
exit 1
fi
# Change to the scripts parent directory
cd $(dirname $0)
# Find out the available columns on our tty
COLUMNS=$(tput cols || 80)
title_echo() {
title="$1"
line="$(printf "%${COLUMNS}s" "")"
printf "\033[0;33m%s\033[0m\n" "${line// /*}"
printf "\033[0;33m%*s\033[0m\n" $(((${#title}+$COLUMNS)/2)) "$title"
# printf "\033[1;34m%s\033[0m\n" "${line// /*}"
title="$1"
line="$(printf "%${COLUMNS}s" "")"
printf "\033[0;33m%s\033[0m\n" "${line// /*}"
printf "\033[0;33m%*s\033[0m\n" $(((${#title}+$COLUMNS)/2)) "$title"
}
failed_echo() {
title="FAILED"
line="$(printf "%${COLUMNS}s" "")"
printf "\033[1;31m%*s\033[0m\n" $(((${#title}+$COLUMNS)/2)) "$title"
printf "\033[1;31m%s\033[0m\n" "${line// /*}"
exit 1
title="FAILED"
line="$(printf "%${COLUMNS}s" "")"
printf "\033[1;31m%*s\033[0m\n" $(((${#title}+$COLUMNS)/2)) "$title"
printf "\033[1;31m%s\033[0m\n" "${line// /*}"
exit 1
}
passed_echo() {
title="OK"
line="$(printf "%${COLUMNS}s" "")"
printf "\033[1;32m%*s\033[0m\n" $(((${#title}+$COLUMNS)/2)) "$title"
printf "\033[1;32m%s\033[0m\n" "${line// /*}"
title="OK"
line="$(printf "%${COLUMNS}s" "")"
printf "\033[1;32m%*s\033[0m\n" $(((${#title}+$COLUMNS)/2)) "$title"
printf "\033[1;32m%s\033[0m\n" "${line// /*}"
}
cleanup() {
apt-get remove -y -o DPkg::Options::=--force-confold --purge salt-master salt-minion salt-syndic
apt-get autoremove -y -o DPkg::Options::=--force-confold --purge
[ -d /tmp/git ] && rm -rf /tmp/git
return 0
}
title_echo "Running checkbashisms"
@ -48,31 +69,31 @@ title_echo "Running checkbashisms"
title_echo "Passing '-N'(no minion) without passing '-M'(install master) or '-S'(install syndic) fails"
./bootstrap-salt-minion.sh -N && failed_echo || passed_echo
title_echo "Using an unknown installation type fails"
./bootstrap-salt-minion.sh foobar && failed_echo || passed_echo
title_echo "Installing using bash"
(sudo /bin/bash bootstrap-salt-minion.sh && salt-minion --versions-report && sudo apt-get remove salt-common salt-minion) && passed_echo || failed_echo
(/bin/bash bootstrap-salt-minion.sh && salt-minion --versions-report && cleanup) && passed_echo || failed_echo
title_echo "Installing using sh"
(sudo ./bootstrap-salt-minion.sh && salt-minion --versions-report && sudo apt-get remove salt-common salt-minion) && passed_echo || failed_echo
(./bootstrap-salt-minion.sh && salt-minion --versions-report && cleanup) && passed_echo || failed_echo
title_echo "Installing stable with sh"
(sudo ./bootstrap-salt-minion.sh stable && salt-minion --versions-report && sudo apt-get remove salt-common salt-minion) && passed_echo || failed_echo
(./bootstrap-salt-minion.sh stable && salt-minion --versions-report && cleanup) && passed_echo || failed_echo
title_echo "Installing ubuntu daily packages using sh"
(sudo ./bootstrap-salt-minion.sh daily && salt-minion --versions-report && sudo apt-get remove salt-common salt-minion) && passed_echo || failed_echo
title_echo "Using an unknown installation type fails"
sudo ./bootstrap-salt-minion.sh foobar && failed_echo || passed_echo
(./bootstrap-salt-minion.sh daily && salt-minion --versions-report && cleanup) && passed_echo || failed_echo
title_echo "Installing stable piped through sh"
(cat ./bootstrap-salt-minion.sh | sudo sh && salt-minion --versions-report && sudo apt-get remove salt-common salt-minion) && passed_echo || failed_echo
(cat ./bootstrap-salt-minion.sh | sh && salt-minion --versions-report && cleanup) && passed_echo || failed_echo
title_echo "Installing latest develop branch from git"
(sudo ./bootstrap-salt-minion.sh git develop && salt --versions-report && sudo rm -rf /tmp/git ) && passed_echo || failed_echo
(./bootstrap-salt-minion.sh git develop && salt --versions-report && cleanup ) && passed_echo || failed_echo
title_echo "Installing from a specific git tag"
(sudo ./bootstrap-salt-minion.sh git v0.12.1 && salt --versions-report && sudo rm -rf /tmp/git ) && passed_echo || failed_echo
(./bootstrap-salt-minion.sh git v0.12.1 && salt --versions-report && cleanup ) && passed_echo || failed_echo
title_echo "Installing from a specific git sha commit"
(sudo ./bootstrap-salt-minion.sh git bf1d7dfb733a6133d6a750e0ab63a27e72cf7e81 && salt --versions-report && sudo rm -rf /tmp/git ) && passed_echo || failed_echo
(./bootstrap-salt-minion.sh git bf1d7dfb733a6133d6a750e0ab63a27e72cf7e81 && salt --versions-report && cleanup ) && passed_echo || failed_echo
exit 0

View file

@ -144,6 +144,9 @@ if [ $(whoami) != "root" ] ; then
fi
CALLER=$(echo `ps a -o pid,command | grep $$ | grep -v grep | tr -s ' '` | cut -d ' ' -f 2)
if [ "${CALLER}x" = "${0}x" ]; then
CALLER="PIPED TROUGH"
fi
echo " * INFO: ${CALLER} $0 -- Version ${ScriptVersion}"
#--- FUNCTION ----------------------------------------------------------------
# NAME: __exit_cleanup
@ -437,7 +440,7 @@ __git_clone_and_checkout() {
# DESCRIPTION: (DRY) apt-get install with noinput options
#-------------------------------------------------------------------------------
__apt_get_noinput() {
apt-get install -y -o DPkg::Options::=--force-confold $@
apt-get install -y -o DPkg::Options::=--force-confold $@; return $?
}
@ -519,9 +522,17 @@ install_ubuntu_1110_post() {
}
install_ubuntu_stable() {
[ $INSTALL_MINION -eq 1 ] && __apt_get_noinput salt-minion
[ $INSTALL_MASTER -eq 1 ] && __apt_get_noinput salt-master
[ $INSTALL_SYNDIC -eq 1 ] && __apt_get_noinput salt-syndic
packages=""
if [ $INSTALL_MINION -eq 1 ]; then
packages="${packages} salt-minion"
fi
if [ $INSTALL_MASTER -eq 1 ]; then
packages="${packages} salt-master"
fi
if [ $INSTALL_SYNDIC -eq 1 ]; then
packages="${packages} salt-syndic"
fi
__apt_get_noinput "${packages}"
}
install_ubuntu_daily() {
@ -534,17 +545,20 @@ install_ubuntu_git() {
install_ubuntu_git_post() {
for fname in minion master syndic; do
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
if [ -f /usr/sbin/service ]; then
# We have upstart support
if [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.upstart ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.upstart /etc/init/salt-$fname.conf
elif [ -f ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart /etc/init/salt-$fname.conf
fi
service salt-$fname status && service salt-$fname restart || service salt-$fname start
else
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
chmod +x /etc/init.d/salt-$fname
fi
fi
if [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.upstart ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.upstart /etc/init/salt-$fname.conf
elif [ -f ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart ]; then
cp ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart /etc/init/salt-$fname.conf
fi
chmod +x /etc/init.d/salt-$fname
service salt-$fname start
done
}
#
@ -602,9 +616,17 @@ install_debian_60_git_deps() {
}
install_debian_stable() {
[ $INSTALL_MINION -eq 1 ] && __apt_get_noinput salt-minion
[ $INSTALL_MASTER -eq 1 ] && __apt_get_noinput salt-master
[ $INSTALL_SYNDIC -eq 1 ] && __apt_get_noinput salt-syndic
packages=""
if [ $INSTALL_MINION -eq 1 ]; then
packages="${packages} salt-minion"
fi
if [ $INSTALL_MASTER -eq 1 ]; then
packages="${packages} salt-master"
fi
if [ $INSTALL_SYNDIC -eq 1 ]; then
packages="${packages} salt-syndic"
fi
__apt_get_noinput "${packages}"
}