pinch-dotfiles/bootstrap.sh
2017-01-11 17:35:00 -05:00

103 lines
2.6 KiB
Bash
Executable file

#!/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.apply
fi
}
_main