2012-10-17 14:02:09 +01:00
|
|
|
#!/bin/bash -
|
|
|
|
#===============================================================================
|
|
|
|
# vim: softtabstop=4 shiftwidth=4 expandtab fenc=utf-8 spell spelllang=en
|
|
|
|
#===============================================================================
|
|
|
|
#
|
|
|
|
# FILE: bootstrap-salt-minion.sh
|
|
|
|
#
|
2012-10-17 16:28:43 +01:00
|
|
|
# DESCRIPTION: Bootstrap salt installation for various systems/distributions
|
2012-10-17 14:02:09 +01:00
|
|
|
#
|
2012-10-17 16:28:43 +01:00
|
|
|
# BUGS: https://github.com/saltstack/salty-vagrant/issues
|
2012-10-17 14:02:09 +01:00
|
|
|
# AUTHOR: Pedro Algarvio (s0undt3ch), pedro@algarvio.me
|
2012-10-17 16:28:43 +01:00
|
|
|
# Alec Koumjian (akoumjian)
|
|
|
|
# ORGANIZATION: Salt Stack (saltstack.org)
|
2012-10-17 14:02:09 +01:00
|
|
|
# CREATED: 10/15/2012 09:49:37 PM WEST
|
|
|
|
#===============================================================================
|
|
|
|
set -o nounset # Treat unset variables as an error
|
|
|
|
ScriptVersion="1.0"
|
2012-10-18 22:18:07 +01:00
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
# LET THE BLACK MAGIC BEGIN!!!!
|
|
|
|
#===============================================================================
|
|
|
|
|
2012-10-17 16:07:33 +01:00
|
|
|
#=== FUNCTION ================================================================
|
|
|
|
# NAME: usage
|
|
|
|
# DESCRIPTION: Display usage information.
|
|
|
|
#===============================================================================
|
|
|
|
usage() {
|
|
|
|
cat << EOT
|
|
|
|
|
2012-10-19 12:22:59 +01:00
|
|
|
Usage : ${0##/*/} [options] <install-type> <install-type-args>
|
2012-10-17 16:07:33 +01:00
|
|
|
|
|
|
|
Installation types:
|
|
|
|
- stable (default)
|
2012-10-19 12:22:59 +01:00
|
|
|
- daily (ubuntu specific)
|
2012-10-17 16:07:33 +01:00
|
|
|
- git
|
|
|
|
|
2012-10-19 12:22:59 +01:00
|
|
|
Examples:
|
|
|
|
$ ${0##/*/}
|
|
|
|
$ ${0##/*/} stable
|
|
|
|
$ ${0##/*/} daily
|
|
|
|
$ ${0##/*/} git
|
|
|
|
$ ${0##/*/} git develop
|
|
|
|
$ ${0##/*/} git 8c3fadf15ec183e5ce8c63739850d543617e4357
|
|
|
|
|
2012-10-17 16:07:33 +01:00
|
|
|
Options:
|
|
|
|
-h|help Display this message
|
|
|
|
-v|version Display script version
|
|
|
|
EOT
|
|
|
|
} # ---------- end of function usage ----------
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# Handle command line arguments
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
2012-10-19 11:24:05 +01:00
|
|
|
while getopts ":hv" opt
|
2012-10-17 16:07:33 +01:00
|
|
|
do
|
|
|
|
case $opt in
|
|
|
|
|
|
|
|
h|help ) usage; exit 0 ;;
|
|
|
|
|
|
|
|
v|version ) echo "$0 -- Version $ScriptVersion"; exit 0 ;;
|
|
|
|
|
2012-10-18 11:41:35 +01:00
|
|
|
\? ) echo "\n Option does not exist : $OPTARG\n"
|
2012-10-17 16:07:33 +01:00
|
|
|
usage; exit 1 ;;
|
|
|
|
|
|
|
|
esac # --- end of case ---
|
|
|
|
done
|
|
|
|
shift $(($OPTIND-1))
|
2012-10-17 14:02:09 +01:00
|
|
|
|
|
|
|
# Define installation type
|
|
|
|
if [ "$#" -eq 0 ];then
|
|
|
|
ITYPE="stable"
|
|
|
|
else
|
|
|
|
ITYPE=$1
|
2012-10-19 12:22:59 +01:00
|
|
|
shift
|
2012-10-17 14:02:09 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$ITYPE" != "stable" -a "$ITYPE" != "daily" -a "$ITYPE" != "git" ]; then
|
2012-10-18 11:41:35 +01:00
|
|
|
echo " ERROR: Installation type \"$ITYPE\" is not known..."
|
2012-10-17 14:02:09 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2012-09-06 23:17:02 +10:00
|
|
|
|
2012-10-19 12:22:59 +01:00
|
|
|
if [ $ITYPE = "git" ]; then
|
|
|
|
if [ "$#" -eq 0 ];then
|
|
|
|
GIT_REV="master"
|
|
|
|
else
|
|
|
|
GIT_REV=$1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$#" -gt 0 ]; then
|
|
|
|
usage
|
|
|
|
echo
|
|
|
|
echo " * ERROR: Too many arguments."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-10-17 14:02:09 +01:00
|
|
|
# Root permissions are required to run this script
|
|
|
|
if [ $(whoami) != "root" ] ; then
|
2012-10-18 11:41:35 +01:00
|
|
|
echo " * ERROR: Salt requires root privileges to install. Please re-run this script as root."
|
2012-09-06 23:17:02 +10:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-10-18 17:28:00 +01:00
|
|
|
# Define our logging file and pipe paths
|
2012-10-18 22:18:07 +01:00
|
|
|
LOGFILE="/tmp/$(basename $0 | sed s/.sh/.log/g )"
|
|
|
|
LOGPIPE="/tmp/$(basename $0 | sed s/.sh/.logpipe/g )"
|
2012-10-17 14:02:09 +01:00
|
|
|
|
|
|
|
# Create our logging pipe
|
|
|
|
mknod $LOGPIPE p
|
|
|
|
|
|
|
|
# What ever is written to the logpipe gets written to the logfile
|
|
|
|
tee < $LOGPIPE $LOGFILE &
|
|
|
|
|
|
|
|
# Close STDOUT, reopen it directing it to the logpipe
|
|
|
|
exec 1>&-
|
|
|
|
exec 1>$LOGPIPE
|
|
|
|
# Close STDERR, reopen it directing it to the logpipe
|
|
|
|
exec 2>&-
|
|
|
|
exec 2>$LOGPIPE
|
|
|
|
|
2012-10-23 04:16:03 +01:00
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __exit_cleanup
|
|
|
|
# DESCRIPTION: Cleanup any leftovers after script has ended
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__exit_cleanup() {
|
|
|
|
EXIT_CODE=$?
|
|
|
|
|
|
|
|
# Remove the logging pipe when the script exits
|
|
|
|
echo " * Removing the logging pipe $LOGPIPE"
|
|
|
|
rm -f $LOGPIPE
|
|
|
|
|
|
|
|
# Kill tee when exiting, CentOS, at least requires this
|
|
|
|
TEE_PID=$(ps ax | grep tee | grep $LOGFILE | awk '{print $1}')
|
|
|
|
echo " * Killing logging pipe tee's with pid(s): $TEE_PID"
|
|
|
|
|
|
|
|
# We need to trap errors since killing tee will cause a 127 errno
|
|
|
|
# We also do this as late as possible so we don't "mis-catch" other errors
|
|
|
|
__trap_errors() {
|
|
|
|
echo "Errors Trapped: $EXIT_CODE"
|
|
|
|
# Exit with the "original" exit code, not the trapped code
|
|
|
|
exit $EXIT_CODE
|
|
|
|
}
|
|
|
|
trap "__trap_errors" ERR
|
|
|
|
|
|
|
|
# Now we're "good" to kill tee
|
|
|
|
kill -TERM $TEE_PID
|
|
|
|
|
|
|
|
# In case the 127 errno is not triggered, exit with the "original" exit code
|
|
|
|
exit $EXIT_CODE
|
|
|
|
}
|
|
|
|
trap "__exit_cleanup" EXIT
|
|
|
|
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-21 16:04:57 +01:00
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __gather_hardware_info
|
|
|
|
# DESCRIPTION: Discover hardware information
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__gather_hardware_info() {
|
|
|
|
CPU_VENDOR_ID=$(cat /proc/cpuinfo | grep vendor_id | head -n 1 | awk '{print $3}')
|
|
|
|
CPU_VENDOR_ID_L=$( echo $CPU_VENDOR_ID | tr '[:upper:]' '[:lower:]' )
|
|
|
|
CPU_ARCH=$(uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown")
|
|
|
|
CPU_ARCH_L=$( echo $CPU_ARCH | tr '[:upper:]' '[:lower:]' )
|
|
|
|
|
|
|
|
}
|
|
|
|
__gather_hardware_info
|
|
|
|
|
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __gather_os_info
|
2012-10-18 22:30:20 +01:00
|
|
|
# DESCRIPTION: Discover operating system information
|
2012-10-18 22:18:07 +01:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__gather_os_info() {
|
|
|
|
OS_NAME=$(uname -s 2>/dev/null)
|
|
|
|
OS_NAME_L=$( echo $OS_NAME | tr '[:upper:]' '[:lower:]' )
|
|
|
|
OS_VERSION=$(uname -r)
|
|
|
|
OS_VERSION_L=$( echo $OS_VERSION | tr '[:upper:]' '[:lower:]' )
|
2012-10-17 14:02:09 +01:00
|
|
|
}
|
2012-10-18 22:18:07 +01:00
|
|
|
__gather_os_info
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-09-06 23:17:02 +10:00
|
|
|
|
2012-10-24 01:32:48 +01:00
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __parse_version_string
|
|
|
|
# DESCRIPTION: Parse version strings ignoring the revision.
|
|
|
|
# MAJOR.MINOR.REVISION becomes MAJOR.MINOR
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__parse_version_string() {
|
|
|
|
VERSION_STRING="$1"
|
|
|
|
PARSED_VERSION=$(
|
|
|
|
echo $VERSION_STRING |
|
|
|
|
sed -e 's/^/#/' \
|
|
|
|
-e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1/' \
|
|
|
|
-e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
|
|
|
|
-e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
|
|
|
|
-e 's/^#.*$//'
|
|
|
|
)
|
|
|
|
echo $PARSED_VERSION
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __gather_linux_system_info
|
2012-10-18 22:30:20 +01:00
|
|
|
# DESCRIPTION: Discover Linux system information
|
2012-10-18 22:18:07 +01:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__gather_linux_system_info() {
|
2012-10-19 12:07:14 +01:00
|
|
|
DISTRO_NAME=""
|
|
|
|
DISTRO_VERSION=""
|
|
|
|
|
|
|
|
if [ -f /etc/lsb-release ]; then
|
|
|
|
DISTRO_NAME=$(grep DISTRIB_ID /etc/lsb-release | sed -e 's/.*=//')
|
2012-10-24 01:32:48 +01:00
|
|
|
DISTRO_VERSION=$(__parse_version_string $(grep DISTRIB_RELEASE /etc/lsb-release | sed -e 's/.*=//'))
|
2012-10-19 12:07:14 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$DISTRO_NAME" != "x" -a "x$DISTRO_VERSION" != "x" ]; then
|
|
|
|
# We already have the distribution name and version
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
for rsource in $(
|
2012-10-18 22:27:38 +01:00
|
|
|
cd /etc && /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
|
|
|
|
sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
|
|
|
|
echo redhat-release lsb-release
|
2012-10-18 23:54:58 +01:00
|
|
|
); do
|
2012-10-18 22:27:38 +01:00
|
|
|
|
|
|
|
[ ! -f "/etc/${rsource}" ] && continue
|
2012-10-18 23:54:58 +01:00
|
|
|
|
2012-10-18 22:27:38 +01:00
|
|
|
n=$(echo ${rsource} | sed -e 's/[_-]release$//' -e 's/[_-]version$//')
|
2012-10-27 04:51:54 +01:00
|
|
|
v=$(__parse_version_string "$((grep VERSION /etc/${rsource}; cat /etc/${rsource}) | grep '[0-9]' | sed -e 'q')")
|
2012-10-18 22:27:38 +01:00
|
|
|
case $(echo ${n} | tr '[:upper:]' '[:lower:]') in
|
|
|
|
redhat )
|
|
|
|
if [ ".$(egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${rsource})" != . ]; then
|
|
|
|
n="<R>ed <H>at <E>nterprise <L>inux"
|
|
|
|
else
|
|
|
|
n="<R>ed <H>at <L>inux"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
arch ) n="Arch" ;;
|
|
|
|
centos ) n="CentOS" ;;
|
|
|
|
debian ) n="Debian" ;;
|
|
|
|
ubuntu ) n="Ubuntu" ;;
|
|
|
|
fedora ) n="Fedora" ;;
|
|
|
|
suse ) n="SUSE" ;;
|
|
|
|
mandrake*|mandriva ) n="Mandriva" ;;
|
|
|
|
gentoo ) n="Gentoo" ;;
|
|
|
|
slackware ) n="Slackware" ;;
|
|
|
|
turbolinux ) n="TurboLinux" ;;
|
|
|
|
unitedlinux ) n="UnitedLinux" ;;
|
|
|
|
* ) n="${n}" ;
|
|
|
|
esac
|
|
|
|
DISTRO_NAME=$n
|
|
|
|
DISTRO_VERSION=$v
|
|
|
|
break
|
2012-10-18 22:18:07 +01:00
|
|
|
done
|
|
|
|
}
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
|
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __gather_sunos_system_info
|
|
|
|
# DESCRIPTION: Discover SunOS system info
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__gather_sunos_system_info() {
|
|
|
|
DISTRO_NAME="Solaris"
|
|
|
|
DISTRO_VERSION=$(
|
|
|
|
echo "${OS_VERSION}" |
|
|
|
|
sed -e 's;^4\.;1.;' \
|
|
|
|
-e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
|
|
|
|
-e 's;^5\.\([0-9][0-9]*\).*;\1;'
|
|
|
|
)
|
2012-10-17 14:02:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __gather_bsd_system_info
|
2012-10-18 22:30:20 +01:00
|
|
|
# DESCRIPTION: Discover OpenBSD, NetBSD and FreeBSD systems information
|
2012-10-18 22:18:07 +01:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__gather_bsd_system_info() {
|
|
|
|
DISTRO_NAME=${OS_NAME}
|
|
|
|
DISTRO_VERSION=$(echo "${OS_VERSION}" | sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/')
|
|
|
|
}
|
2012-10-17 14:02:09 +01:00
|
|
|
|
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __gather_system_info
|
2012-10-18 22:30:20 +01:00
|
|
|
# DESCRIPTION: Discover which system and distribution we are running.
|
2012-10-18 22:18:07 +01:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__gather_system_info() {
|
|
|
|
case ${OS_NAME_L} in
|
|
|
|
linux )
|
|
|
|
__gather_linux_system_info
|
|
|
|
;;
|
|
|
|
sunos )
|
|
|
|
__gather_sunos_system_info
|
|
|
|
;;
|
|
|
|
openbsd|freebsd|netbsd )
|
|
|
|
__gather_bsd_system_info
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo " * ERROR: $OS_NAME not supported.";
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
}
|
2012-10-17 14:02:09 +01:00
|
|
|
|
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __function_defined
|
|
|
|
# DESCRIPTION: Checks if a function is defined within this scripts scope
|
|
|
|
# PARAMETERS: function name
|
|
|
|
# RETURNS: 0 or 1 as in defined or not defined
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__function_defined() {
|
|
|
|
FUNC_NAME=$1
|
|
|
|
if [ ${DISTRO_NAME} = "centos" ]; then
|
|
|
|
if typeset -f $FUNC_NAME &>/dev/null ; then
|
|
|
|
echo " * INFO: Found function $FUNC_NAME"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
elif [ ${DISTRO_NAME} = "ubuntu" ]; then
|
|
|
|
if $( type ${FUNC_NAME} | grep -q 'shell function' ); then
|
|
|
|
echo " * INFO: Found function $FUNC_NAME"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
# Last resorts try POSIXLY_CORRECT or not
|
|
|
|
elif test -n "${POSIXLY_CORRECT+yes}"; then
|
|
|
|
if typeset -f $FUNC_NAME &>/dev/null ; then
|
|
|
|
echo " * INFO: Found function $FUNC_NAME"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Arch linux seems to fall here
|
|
|
|
if $( type ${FUNC_NAME} &>/dev/null ) ; then
|
|
|
|
echo " * INFO: Found function $FUNC_NAME"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo " * INFO: $FUNC_NAME not found...."
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
__gather_system_info
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-27 07:31:14 +01:00
|
|
|
|
|
|
|
#--- FUNCTION ----------------------------------------------------------------
|
|
|
|
# NAME: __git_clone_and_checkout
|
|
|
|
# DESCRIPTION: (DRY) Helper function to clone and checkout salt to a
|
|
|
|
# specific revision.
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
__git_clone_and_checkout() {
|
|
|
|
SALT_GIT_CHECKOUT_DIR=/tmp/git/salt
|
|
|
|
[ -d /tmp/git ] || mkdir /tmp/git
|
|
|
|
cd /tmp/git
|
|
|
|
[ -d $SALT_GIT_CHECKOUT_DIR ] || git clone git://github.com/saltstack/salt.git salt
|
|
|
|
cd salt
|
|
|
|
git checkout $GIT_REV
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-19 12:22:59 +01:00
|
|
|
echo " * System Information:"
|
2012-10-21 16:04:57 +01:00
|
|
|
echo " CPU: ${CPU_VENDOR_ID} ${CPU_ARCH}"
|
2012-10-19 12:22:59 +01:00
|
|
|
echo " OS Name: ${OS_NAME}"
|
|
|
|
echo " OS Version: ${OS_VERSION}"
|
|
|
|
echo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}"
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
|
2012-10-18 23:54:58 +01:00
|
|
|
# Simplify version naming on functions
|
|
|
|
if [ "x${DISTRO_VERSION}" = "x" ]; then
|
|
|
|
DISTRO_VERSION_NO_DOTS=""
|
|
|
|
else
|
|
|
|
DISTRO_VERSION_NO_DOTS="_$(echo $DISTRO_VERSION | tr -d '.')"
|
|
|
|
fi
|
|
|
|
# Simplify distro name naming on functions
|
|
|
|
DISTRO_NAME_L=$(echo $DISTRO_NAME | tr '[:upper:]' '[:lower:]')
|
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
##############################################################################
|
2012-10-17 14:02:09 +01:00
|
|
|
#
|
|
|
|
# Distribution install functions
|
|
|
|
#
|
|
|
|
# In order to install salt for a distribution you need to define:
|
|
|
|
#
|
|
|
|
# To Install Dependencies, which is required, one of:
|
|
|
|
# 1. install_<distro>_<distro_version>_<install_type>_deps
|
|
|
|
# 2. install_<distro>_<distro_version>_deps
|
2012-10-18 17:28:00 +01:00
|
|
|
# 3. install_<distro>_<install_type>_deps
|
2012-10-19 13:12:22 +01:00
|
|
|
# 4. install_<distro>_deps
|
2012-10-17 14:02:09 +01:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# To install salt, which, of course, is required, one of:
|
|
|
|
# 1. install_<distro>_<distro_version>_<install_type>
|
|
|
|
# 1. install_<distro>_<install_type>
|
|
|
|
#
|
2012-10-18 17:28:00 +01:00
|
|
|
#
|
2012-10-17 14:02:09 +01:00
|
|
|
# And optionally, define a post install function, one of:
|
|
|
|
# 1. install_<distro>_<distro_versions>_<install_type>_post
|
|
|
|
# 2. install_<distro>_<distro_versions>_post
|
2012-10-18 17:28:00 +01:00
|
|
|
# 3. install_<distro>_<install_type>_post
|
|
|
|
# 4. install_<distro>_post
|
2012-10-17 14:02:09 +01:00
|
|
|
#
|
2012-10-18 22:18:07 +01:00
|
|
|
##############################################################################
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
##############################################################################
|
2012-10-17 14:02:09 +01:00
|
|
|
#
|
|
|
|
# Ubuntu Install Functions
|
|
|
|
#
|
|
|
|
install_ubuntu_deps() {
|
|
|
|
apt-get update
|
|
|
|
apt-get -y install python-software-properties
|
|
|
|
add-apt-repository -y ppa:saltstack/salt
|
|
|
|
apt-get update
|
|
|
|
}
|
|
|
|
|
|
|
|
install_ubuntu_1004_deps() {
|
|
|
|
apt-get update
|
|
|
|
apt-get -y install python-software-properties
|
|
|
|
add-apt-repository ppa:saltstack/salt
|
|
|
|
apt-get update
|
|
|
|
apt-get -y install salt-minion
|
|
|
|
}
|
|
|
|
|
|
|
|
install_ubuntu_1110_deps() {
|
|
|
|
apt-get update
|
|
|
|
apt-get -y install python-software-properties
|
|
|
|
add-apt-repository -y 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe'
|
|
|
|
add-apt-repository -y ppa:saltstack/salt
|
|
|
|
}
|
|
|
|
|
2012-10-19 11:08:37 -07:00
|
|
|
install_ubuntu_daily_deps() {
|
|
|
|
apt-get update
|
|
|
|
apt-get -y install python-software-properties
|
|
|
|
add-apt-repository -y ppa:saltstack/salt-daily
|
|
|
|
apt-get update
|
|
|
|
}
|
|
|
|
|
2012-10-19 21:16:00 -07:00
|
|
|
install_ubuntu_git_deps() {
|
|
|
|
apt-get update
|
|
|
|
apt-get install -y python-software-properties
|
|
|
|
add-apt-repository ppa:saltstack/salt
|
|
|
|
apt-get update
|
2012-10-27 07:37:16 +01:00
|
|
|
apt-get install -y git-core python-yaml python-m2crypto python-crypto msgpack-python python-zmq python-jinja2
|
2012-10-19 21:16:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-17 14:02:09 +01:00
|
|
|
install_ubuntu_1110_post() {
|
|
|
|
add-apt-repository -y --remove 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe'
|
|
|
|
}
|
|
|
|
|
|
|
|
install_ubuntu_stable() {
|
|
|
|
apt-get -y install salt-minion
|
|
|
|
}
|
2012-10-19 11:08:37 -07:00
|
|
|
|
|
|
|
install_ubuntu_daily() {
|
|
|
|
apt-get -y install salt-minion
|
|
|
|
}
|
2012-10-19 21:16:00 -07:00
|
|
|
|
|
|
|
install_ubuntu_git() {
|
2012-10-27 07:31:14 +01:00
|
|
|
__git_clone_and_checkout
|
2012-10-19 21:16:00 -07:00
|
|
|
python setup.py install --install-layout=deb
|
|
|
|
}
|
|
|
|
|
|
|
|
install_ubuntu_git_post() {
|
2012-10-27 04:51:54 +01:00
|
|
|
for fname in $(echo "minion master syndic"); do
|
2012-10-27 07:31:14 +01:00
|
|
|
if [ $fname != "minion" ]; then
|
|
|
|
# Guess we should only enable and start the minion service. Right??
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init /etc/init.d/salt-$fname
|
|
|
|
cp ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.upstart /etc/init/salt-$fname.conf
|
2012-10-27 04:51:54 +01:00
|
|
|
chmod +x /etc/init.d/salt-$fname
|
2012-10-27 07:31:14 +01:00
|
|
|
service salt-$fname start
|
2012-10-27 04:51:54 +01:00
|
|
|
done
|
2012-10-19 21:16:00 -07:00
|
|
|
}
|
2012-10-17 14:02:09 +01:00
|
|
|
#
|
|
|
|
# End of Ubuntu Install Functions
|
|
|
|
#
|
2012-10-18 22:18:07 +01:00
|
|
|
##############################################################################
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
##############################################################################
|
2012-10-17 14:02:09 +01:00
|
|
|
#
|
|
|
|
# Debian Install Functions
|
|
|
|
#
|
|
|
|
install_debian_60_stable_deps() {
|
2012-10-18 17:28:00 +01:00
|
|
|
echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> \
|
|
|
|
/etc/apt/sources.list.d/backports.list
|
2012-10-17 14:02:09 +01:00
|
|
|
apt-get update
|
|
|
|
}
|
|
|
|
|
|
|
|
install_debian_60_stable() {
|
|
|
|
apt-get -t squeeze-backports -y install salt-minion
|
|
|
|
}
|
2012-10-18 19:54:05 -07:00
|
|
|
|
|
|
|
install_debian_60_git_deps() {
|
|
|
|
install_debian_60_stable_deps
|
|
|
|
install_debian_60_stable
|
|
|
|
}
|
|
|
|
|
|
|
|
install_debian_60_git() {
|
|
|
|
apt-get -y install git
|
|
|
|
apt-get -y purge salt-minion
|
|
|
|
|
2012-10-27 07:31:14 +01:00
|
|
|
__git_clone_and_checkout
|
|
|
|
|
2012-10-18 19:54:05 -07:00
|
|
|
python setup.py install --install-layout=deb
|
|
|
|
mkdir -p /etc/salt
|
|
|
|
cp conf/minion.template /etc/salt/minion
|
|
|
|
}
|
2012-10-17 14:02:09 +01:00
|
|
|
#
|
|
|
|
# Ended Debian Install Functions
|
|
|
|
#
|
2012-10-18 22:18:07 +01:00
|
|
|
##############################################################################
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-19 21:16:00 -07:00
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Fedora Install Functions
|
|
|
|
#
|
2012-10-27 07:31:14 +01:00
|
|
|
install_fedora_deps() {
|
|
|
|
yum install -y PyYAML libyaml m2crypto python-crypto python-jinja2 python-msgpack python-zmq
|
|
|
|
}
|
|
|
|
|
2012-10-19 21:16:00 -07:00
|
|
|
install_fedora_stable() {
|
|
|
|
yum install -y salt-minion
|
|
|
|
}
|
|
|
|
|
2012-10-27 07:31:14 +01:00
|
|
|
|
|
|
|
install_fedora_git_deps() {
|
|
|
|
install_fedora_deps
|
|
|
|
yum install -y git
|
|
|
|
}
|
|
|
|
|
|
|
|
install_fedora_git() {
|
|
|
|
__git_clone_and_checkout
|
|
|
|
python setup.py install
|
|
|
|
}
|
|
|
|
|
|
|
|
install_fedora_git_post() {
|
|
|
|
for fname in $(echo "minion master syndic"); do
|
|
|
|
if [ $fname != "minion" ]; then
|
|
|
|
# Guess we should only enable and start the minion service. Right??
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
#cp ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname /etc/rc.d/init.d/salt-$fname
|
|
|
|
cp ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname.service /lib/systemd/system/salt-$fname.service
|
|
|
|
#chmod +x /etc/rc.d/init.d/salt-$fname
|
|
|
|
|
|
|
|
# Switch from forking to simple, dunny why I can't make it work
|
|
|
|
sed -i 's/Type=forking/Type=simple/g' /lib/systemd/system/salt-$fname.service
|
|
|
|
# Remove the daemon flag because of the above
|
|
|
|
sed -ie 's;ExecStart=\(.*\) -d;ExecStart=\1;' /lib/systemd/system/salt-$fname.service
|
|
|
|
systemctl preset salt-$fname.service
|
|
|
|
systemctl enable salt-$fname.service
|
|
|
|
sleep 0.2
|
|
|
|
systemctl daemon-reload
|
|
|
|
sleep 0.2
|
|
|
|
systemctl start salt-$fname.service
|
|
|
|
done
|
|
|
|
}
|
2012-10-19 21:16:00 -07:00
|
|
|
#
|
|
|
|
# Ended Fedora Install Functions
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
##############################################################################
|
2012-10-17 16:07:33 +01:00
|
|
|
#
|
|
|
|
# CentOS Install Functions
|
|
|
|
#
|
|
|
|
install_centos_63_stable_deps() {
|
2012-10-21 16:05:29 +01:00
|
|
|
if [ $CPU_ARCH_L = "i686" ]; then
|
|
|
|
local ARCH="i386"
|
|
|
|
else
|
|
|
|
local ARCH=$CPU_ARCH_L
|
|
|
|
fi
|
|
|
|
rpm -Uvh --force http://mirrors.kernel.org/fedora-epel/6/${ARCH}/epel-release-6-7.noarch.rpm
|
2012-10-17 16:07:33 +01:00
|
|
|
yum -y update
|
|
|
|
}
|
|
|
|
|
|
|
|
install_centos_63_stable() {
|
|
|
|
yum -y install salt-minion --enablerepo=epel-testing
|
|
|
|
}
|
|
|
|
|
|
|
|
install_centos_63_stable_post() {
|
|
|
|
/sbin/chkconfig salt-minion on
|
2012-10-23 04:16:03 +01:00
|
|
|
/etc/init.d/salt-minion start
|
2012-10-17 16:07:33 +01:00
|
|
|
}
|
2012-10-22 03:39:33 +01:00
|
|
|
|
|
|
|
install_centos_63_git_deps() {
|
|
|
|
install_centos_63_stable_deps
|
|
|
|
yum -y install git PyYAML m2crypto python-crypto python-msgpack python-zmq python-jinja2 --enablerepo=epel-testing
|
|
|
|
}
|
|
|
|
|
|
|
|
install_centos_63_git() {
|
|
|
|
rm -rf /usr/lib/python*/site-packages/salt
|
|
|
|
rm -rf /usr/bin/salt*
|
2012-10-27 07:31:14 +01:00
|
|
|
|
|
|
|
__git_clone_and_checkout
|
2012-10-22 03:39:33 +01:00
|
|
|
python2 setup.py install
|
|
|
|
mkdir -p /etc/salt/
|
|
|
|
}
|
|
|
|
|
|
|
|
install_centos_63_git_post() {
|
|
|
|
cp pkg/rpm/salt-{master,minion} /etc/init.d/
|
|
|
|
chmod +x /etc/init.d/salt-{master,minion}
|
|
|
|
/sbin/chkconfig salt-minion on
|
2012-10-23 04:16:03 +01:00
|
|
|
/etc/init.d/salt-minion start
|
2012-10-17 16:07:33 +01:00
|
|
|
}
|
|
|
|
#
|
|
|
|
# Ended CentOS Install Functions
|
|
|
|
#
|
2012-10-18 22:18:07 +01:00
|
|
|
##############################################################################
|
2012-10-17 14:02:09 +01:00
|
|
|
|
2012-10-19 21:16:00 -07:00
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Arch Install Functions
|
|
|
|
#
|
|
|
|
install_arch_stable_deps() {
|
|
|
|
echo '[salt]
|
|
|
|
Server = http://red45.org/archlinux
|
|
|
|
' >> /etc/pacman.conf
|
|
|
|
}
|
|
|
|
|
|
|
|
install_arch_git_deps() {
|
|
|
|
echo '[salt]
|
|
|
|
Server = http://red45.org/archlinux
|
|
|
|
' >> /etc/pacman.conf
|
|
|
|
}
|
|
|
|
|
|
|
|
install_arch_stable() {
|
|
|
|
pacman -Sy --noconfirm pacman
|
|
|
|
pacman -Syu --noconfirm salt
|
|
|
|
}
|
|
|
|
|
|
|
|
install_arch_git() {
|
|
|
|
pacman -Sy --noconfirm pacman
|
|
|
|
pacman -Syu --noconfirm salt git
|
|
|
|
rm -rf /usr/lib/python2.7/site-packages/salt*
|
|
|
|
rm -rf /usr/bin/salt-*
|
2012-10-27 07:31:14 +01:00
|
|
|
|
|
|
|
__git_clone_and_checkout
|
|
|
|
|
2012-10-19 21:16:00 -07:00
|
|
|
python2 setup.py install
|
|
|
|
}
|
|
|
|
|
|
|
|
install_arch_post() {
|
|
|
|
/etc/rc.d/salt-minion start
|
|
|
|
}
|
|
|
|
#
|
|
|
|
# Ended Arch Install Functions
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# FreeBSD Install Functions
|
|
|
|
#
|
2012-10-23 08:09:12 +01:00
|
|
|
install_freebsd_9_stable_deps() {
|
|
|
|
if [ $CPU_VENDOR_ID_L = "AuthenticAMD" -a $CPU_ARCH_L = "x86_64" ]; then
|
|
|
|
local ARCH="amd64"
|
|
|
|
elif [ $CPU_VENDOR_ID_L = "GenuineIntel" -a $CPU_ARCH_L = "x86_64" ]; then
|
|
|
|
local ARCH="x86:64"
|
|
|
|
elif [ $CPU_VENDOR_ID_L = "GenuineIntel" -a $CPU_ARCH_L = "i386" ]; then
|
|
|
|
local ARCH="i386"
|
|
|
|
elif [ $CPU_VENDOR_ID_L = "GenuineIntel" -a $CPU_ARCH_L = "i686" ]; then
|
|
|
|
local ARCH="x86:32"
|
|
|
|
fi
|
|
|
|
|
2012-10-19 21:16:00 -07:00
|
|
|
portsnap fetch extract update
|
|
|
|
cd /usr/ports/ports-mgmt/pkg
|
|
|
|
make install clean
|
|
|
|
cd
|
|
|
|
/usr/local/sbin/pkg2ng
|
2012-10-23 08:09:12 +01:00
|
|
|
echo 'PACKAGESITE: http://pkgbeta.freebsd.org/freebsd-9-${ARCH}/latest' > /usr/local/etc/pkg.conf
|
2012-10-19 21:16:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
install_freebsd_git_deps() {
|
2012-10-23 08:09:12 +01:00
|
|
|
if [ $CPU_VENDOR_ID_L = "AuthenticAMD" -a $CPU_ARCH_L = "x86_64" ]; then
|
|
|
|
local ARCH="amd64"
|
|
|
|
elif [ $CPU_VENDOR_ID_L = "GenuineIntel" -a $CPU_ARCH_L = "x86_64" ]; then
|
|
|
|
local ARCH="x86:64"
|
|
|
|
elif [ $CPU_VENDOR_ID_L = "GenuineIntel" -a $CPU_ARCH_L = "i386" ]; then
|
|
|
|
local ARCH="i386"
|
|
|
|
elif [ $CPU_VENDOR_ID_L = "GenuineIntel" -a $CPU_ARCH_L = "i686" ]; then
|
|
|
|
local ARCH="x86:32"
|
|
|
|
fi
|
|
|
|
|
2012-10-19 21:16:00 -07:00
|
|
|
portsnap fetch extract update
|
|
|
|
cd /usr/ports/ports-mgmt/pkg
|
|
|
|
make install clean
|
|
|
|
cd
|
|
|
|
/usr/local/sbin/pkg2ng
|
2012-10-23 08:09:12 +01:00
|
|
|
echo 'PACKAGESITE: http://pkgbeta.freebsd.org/freebsd-9-${ARCH}/latest' > /usr/local/etc/pkg.conf
|
2012-10-19 21:16:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-23 08:09:12 +01:00
|
|
|
install_freebsd_9_stable() {
|
2012-10-19 21:16:00 -07:00
|
|
|
pkg install -y salt
|
|
|
|
}
|
|
|
|
|
|
|
|
install_freebsd_git() {
|
|
|
|
/usr/local/sbin/pkg install -y git salt
|
|
|
|
/usr/local/sbin/pkg delete -y salt
|
2012-10-27 07:31:14 +01:00
|
|
|
|
|
|
|
__git_clone_and_checkout
|
|
|
|
|
2012-10-19 21:16:00 -07:00
|
|
|
/usr/local/bin/python setup.py install
|
|
|
|
}
|
|
|
|
|
2012-10-23 08:09:12 +01:00
|
|
|
install_freebsd_9_stable_post() {
|
2012-10-19 21:16:00 -07:00
|
|
|
salt-minion -d
|
|
|
|
}
|
|
|
|
|
|
|
|
install_freebsd_git_post() {
|
|
|
|
salt-minion -d
|
|
|
|
}
|
|
|
|
#
|
|
|
|
# Ended FreeBSD Install Functions
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-10-23 08:09:12 +01:00
|
|
|
|
2012-10-18 22:18:07 +01:00
|
|
|
#=============================================================================
|
|
|
|
# LET'S PROCEED WITH OUR INSTALLATION
|
|
|
|
#=============================================================================
|
2012-10-18 17:28:00 +01:00
|
|
|
# Let's get the dependencies install function
|
2012-10-18 23:54:58 +01:00
|
|
|
DEP_FUNC_NAMES="install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_${ITYPE}_deps"
|
|
|
|
DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_deps"
|
|
|
|
DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_deps"
|
|
|
|
DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_deps"
|
2012-10-18 17:28:00 +01:00
|
|
|
|
|
|
|
DEPS_INSTALL_FUNC="null"
|
|
|
|
for DEP_FUNC_NAME in $DEP_FUNC_NAMES; do
|
|
|
|
if __function_defined $DEP_FUNC_NAME; then
|
|
|
|
DEPS_INSTALL_FUNC=$DEP_FUNC_NAME
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2012-10-17 14:02:09 +01:00
|
|
|
|
|
|
|
# Let's get the install function
|
2012-10-18 23:54:58 +01:00
|
|
|
INSTALL_FUNC_NAMES="install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_${ITYPE}"
|
|
|
|
INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}"
|
2012-10-18 17:28:00 +01:00
|
|
|
|
|
|
|
INSTALL_FUNC="null"
|
|
|
|
for FUNC_NAME in $INSTALL_FUNC_NAMES; do
|
|
|
|
if __function_defined $FUNC_NAME; then
|
|
|
|
INSTALL_FUNC=$FUNC_NAME
|
|
|
|
break
|
2012-09-06 23:17:02 +10:00
|
|
|
fi
|
2012-10-18 17:28:00 +01:00
|
|
|
done
|
2012-09-06 23:17:02 +10:00
|
|
|
|
2012-10-18 17:28:00 +01:00
|
|
|
|
|
|
|
# Let's get the dependencies install function
|
2012-10-18 23:54:58 +01:00
|
|
|
POST_FUNC_NAMES="install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_${ITYPE}_post"
|
2012-10-22 01:51:59 +01:00
|
|
|
POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${DISTRO_VERSION_NO_DOTS}_post"
|
|
|
|
POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_post"
|
|
|
|
POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_post"
|
2012-10-18 17:28:00 +01:00
|
|
|
|
|
|
|
POST_INSTALL_FUNC="null"
|
|
|
|
for FUNC_NAME in $POST_FUNC_NAMES; do
|
|
|
|
if __function_defined $FUNC_NAME; then
|
2012-10-22 02:01:01 +01:00
|
|
|
POST_INSTALL_FUNC=$FUNC_NAME
|
2012-10-18 17:28:00 +01:00
|
|
|
break
|
2012-10-17 14:02:09 +01:00
|
|
|
fi
|
2012-10-18 17:28:00 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
if [ $DEPS_INSTALL_FUNC = "null" ]; then
|
|
|
|
echo " * ERROR: No dependencies installation function found. Exiting..."
|
|
|
|
exit 1
|
2012-10-17 14:02:09 +01:00
|
|
|
fi
|
|
|
|
|
2012-10-18 17:28:00 +01:00
|
|
|
if [ $DEPS_INSTALL_FUNC = "null" ]; then
|
|
|
|
echo " * ERROR: No installation function found. Exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2012-10-17 14:02:09 +01:00
|
|
|
# Install dependencies
|
2012-10-18 11:41:35 +01:00
|
|
|
echo " * Running ${DEPS_INSTALL_FUNC}()"
|
2012-10-17 14:02:09 +01:00
|
|
|
$DEPS_INSTALL_FUNC
|
2012-10-27 07:31:14 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo " * Failed to run ${DEPS_INSTALL_FUNC}()!!!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2012-10-17 14:02:09 +01:00
|
|
|
|
|
|
|
# Install Salt
|
2012-10-18 11:41:35 +01:00
|
|
|
echo " * Running ${INSTALL_FUNC}()"
|
2012-10-17 14:02:09 +01:00
|
|
|
$INSTALL_FUNC
|
2012-10-27 07:31:14 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo " * Failed to run ${INSTALL_FUNC}()!!!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2012-10-17 14:02:09 +01:00
|
|
|
|
|
|
|
# Run any post install function
|
2012-10-18 17:28:00 +01:00
|
|
|
if [ "$POST_INSTALL_FUNC" != "null" ]; then
|
2012-10-18 11:41:35 +01:00
|
|
|
echo " * Running ${POST_INSTALL_FUNC}()"
|
2012-10-17 14:02:09 +01:00
|
|
|
$POST_INSTALL_FUNC
|
2012-10-27 07:31:14 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo " * Failed to run ${POST_INSTALL_FUNC}()!!!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2012-10-17 14:02:09 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Done!
|
2012-10-18 11:41:35 +01:00
|
|
|
echo " * Salt installed!"
|
2012-10-22 03:39:33 +01:00
|
|
|
exit 0
|