From d6a7d29e1fa6b3e3e4e9caf772c5b5decef0a2bf Mon Sep 17 00:00:00 2001 From: Angus Peart Date: Thu, 6 Sep 2012 23:17:02 +1000 Subject: [PATCH] Initial multi-os support, see saltstack/salty-vagrant/#1 A sh bootstrapping script is copied to the target VM and used to determine the correct method of installing the Salt binaries. Any operating system supported by Salt with a sh shell can be added to the bootstrapping script. --- bootstrap-salt-minion.sh | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 bootstrap-salt-minion.sh diff --git a/bootstrap-salt-minion.sh b/bootstrap-salt-minion.sh new file mode 100644 index 0000000..7dc136e --- /dev/null +++ b/bootstrap-salt-minion.sh @@ -0,0 +1,86 @@ +#!/bin/sh +LOGFILE=/var/log/bootstrap-salt-minion.log + +log() { + message="$@" + echo $message + echo $message >>$LOGFILE +} + +UNAME=`uname` +if [ "$UNAME" != "Linux" ] ; then + log "Sorry, this OS is not supported." + exit 1 +fi + +set -e +trap "echo Installation failed." EXIT + +if [ "$UNAME" = "Linux" ] ; then + do_with_root() { + if [ `whoami` = 'root' ] ; then + RESULT=$($*) + log $RESULT + else + log "Salt requires root privileges to install. Please re-run this script as root." + exit 1 + fi + } + + if [ -f /etc/lsb-release ] ; then + OS=$(lsb_release -si) + CODENAME=$(lsb_release -sc) + + if [ $OS = 'Ubuntu' ]; then + if [ $CODENAME = 'oneiric' ]; then + log "Installing for Ubuntu Oneiric." + do_with_root apt-get update + do_with_root apt-get -y install python-software-properties + do_with_root add-apt-repository -y 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe' + do_with_root add-apt-repository -y ppa:saltstack/salt + do_with_root apt-get update + do_with_root apt-get -y install msgpack-python salt-minion + do_with_root add-apt-repository -y --remove 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe' + elif [ $CODENAME = 'lucid' -o $CODENAME = 'precise' ]; then + log "Installing for Ubuntu Lucid/Precise." + do_with_root apt-get update + do_with_root apt-get -y install python-software-properties + do_with_root add-apt-repository -y ppa:saltstack/salt + do_with_root apt-get update + do_with_root apt-get -y install salt-minion + else + log "Ubuntu $CODENAME is not supported." + exit 1 + fi + elif [ $OS = 'Debian' ]; then + if [ $CODENAME = 'wheezy' -o $CODENAME = 'jessie' ]; then + log "Installing for Debian Weezy/Jessie." + do_with_root apt-get -y install salt-minion + else + log "Debian $CODENAME is not supported." + exit 1 + fi + else + log "Debian variant $OS not supported." + exit 1 + fi + elif [ -f /etc/debian_version ] ; then + DVER=$(cat /etc/debian_version) + if [ $DVER = '6.0' ]; then + log "Installing for Debian Squeeze." + do_with_root echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> /etc/apt/sources.list.d/backports.list + do_with_root apt-get update + do_with_root apt-get -t squeeze-backports -y install salt-minion + else + log "Debian version $VER not supported." + exit 1 + fi + else + log "Unable to install. Bootstrapping only supported on Debian/Ubuntu." + exit 1 + fi +fi + +log "Salt has been installed!" +trap - EXIT +