diff --git a/setup.sh b/setup.sh index d1790da..6858f25 100755 --- a/setup.sh +++ b/setup.sh @@ -4,8 +4,12 @@ set -e SALT_VERSION='3006.4' +CYAN='\033[1;36m' +RED='\033[0;31m' +NC='\033[0m' + if [ $UID -ne 0 ]; then - echo This script must run as root. + echo -e "${RED}This script must run as root.${NC}" exit 1 fi @@ -16,7 +20,7 @@ elif [ -f /etc/redhat-release ]; then PKG_CHECK='rpm -q' PKG_INSTALL='yum -y install' else - echo Unrecognized OS + echo -e "${RED}Unrecognized OS${NC}" exit 1 fi @@ -27,7 +31,7 @@ for PKG in jq curl python3-distro; do fi done if [ -n "$TO_INSTALL" ]; then - echo "Installing $TO_INSTALL" + echo -e "${CYAN}Installing ${TO_INSTALL}${NC}" $PKG_INSTALL $TO_INSTALL fi @@ -36,13 +40,13 @@ CODENAME="$(python3 -m distro --json | jq -r .codename)" OS_VERSION="$(python3 -m distro --json | jq -r .version)" PUBLIC_IPV4="$(curl -s -4 ifconfig.me)" -echo -n "Ensure $PUBLIC_IPV4 is whitelisted on the salt master, then press enter" +echo -e -n "${CYAN}Ensure $PUBLIC_IPV4 is whitelisted on the salt master, then press enter${NC}" read if ! [ -e /usr/bin/salt-call ]; then set -x if [[ "$(uname -m)" =~ arm* ]]; then - echo 'ARM processor detected - using pip/venv' + echo -e "${CYAN}ARM processor detected - using pip/venv${NC}" [ -e /opt/saltstack/salt ] || python3 -m venv /opt/saltstack/salt /opt/saltstack/salt/bin/pip3 freeze | grep -q ^salt== || @@ -76,17 +80,18 @@ if ! [ -e /usr/bin/salt-call ]; then apt-get update apt-get -y install salt-minion else - echo Unrecognized OS + echo -e "${RED}Unrecognized OS${NC}" exit 1 fi set +x fi APPLY='salt-call state.apply --master=kpi.keiran.us salt' -echo "Setup will now run:" -echo "$APPLY" -echo "The first run should send a key request to the master, then fail because it is not signed yet" -$APPLY -echo -n "Press enter once the salt-master has signed this key to re-run the command, (or ctrl+c and you can manually run it later)" +echo -e "${CYAN}Setup will now run:${NC}" +echo -e "$APPLY" +echo -e "${CYAN}The first run should send a key request to the master, then fail because it's not signed yet${NC}" +echo "Running..." +$APPLY || true +echo -e -n "${CYAN}Press enter once the salt-master has signed this key to re-run the command, (or ctrl+c and you can manually run it later)${NC}" read $APPLY