From c44fc54b7ab69fec3293fc1098557b186d78df90 Mon Sep 17 00:00:00 2001 From: Elijah Lazkani Date: Tue, 10 Jan 2017 19:19:19 -0500 Subject: [PATCH] Adding the bootstrap script. --- bootstrap.sh | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 bootstrap.sh diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..1f62fe9 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +# This script will bootstrap the machine using SaltStack +# Copyright (C) 2017 Elijah Lazkani + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +function _main () { + case "$(uname -s)" in + + Darwin) + _mac_os_x + ;; + + Linux) + _linux + ;; + + CYGWIN*|MINGW32*|MSYS*) + _windows + ;; + + *) + _unknown_os + ;; + esac +} + +function _mac_os_x () { + echo "Operating System identified as Mac OS X" + + # Check for Homebrew + command brew > /dev/null 2>&1 + if [ $? -ne 0 ]; + then + echo "Homebrew not installed, installing..." + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + fi + + # Check SaltStack + command salt-call > /dev/null 2>&1 + if [ $? -ne 0 ]; + then + echo "SaltStack not installed, installing..." + #brew install saltstack + fi + + _saltstack +} + +function _linux () { + echo "Operating System identified as Linux" + + # Check Saltstack + command salt-call > /dev/null 2>&1 + if [ $? -ne 0 ]; + then + echo "SaltStack not installed, installing..." + curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com + sudo sh bootstrap-salt.sh git develop + echo "Cleaning installation script" + rm bootstrap-salt.sh + fi + + _saltstack +} + +function _windows () { + echo "Operating System identified as... what?" + echo "Get a real OS..." + exit 1 +} + +function _unknown_os () { + echo "Operating System was not identified" + exit 1 +} + +function _saltstack () { + echo "Bootstrapping SaltStack" + sudo salt-call --local --config=./ --state-output=changes grains.setvals "{ \"user\": \"$(whoami)\", \"homedir\": \"$HOME\" }" + + if [[ $1 ]]; + then + sudo salt-call --local --config=./ --state-output=changes --log-level=quiet state.sls $1 + else + sudo salt-call --local --config=./ --state-output=changes --log-level=quiet state.sls state.apply + fi +} + +_main