colored output & handle exit from initial run
This commit is contained in:
27
setup.sh
27
setup.sh
@@ -4,8 +4,12 @@ set -e
|
|||||||
|
|
||||||
SALT_VERSION='3006.4'
|
SALT_VERSION='3006.4'
|
||||||
|
|
||||||
|
CYAN='\033[1;36m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
if [ $UID -ne 0 ]; then
|
if [ $UID -ne 0 ]; then
|
||||||
echo This script must run as root.
|
echo -e "${RED}This script must run as root.${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -16,7 +20,7 @@ elif [ -f /etc/redhat-release ]; then
|
|||||||
PKG_CHECK='rpm -q'
|
PKG_CHECK='rpm -q'
|
||||||
PKG_INSTALL='yum -y install'
|
PKG_INSTALL='yum -y install'
|
||||||
else
|
else
|
||||||
echo Unrecognized OS
|
echo -e "${RED}Unrecognized OS${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -27,7 +31,7 @@ for PKG in jq curl python3-distro; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ -n "$TO_INSTALL" ]; then
|
if [ -n "$TO_INSTALL" ]; then
|
||||||
echo "Installing $TO_INSTALL"
|
echo -e "${CYAN}Installing ${TO_INSTALL}${NC}"
|
||||||
$PKG_INSTALL $TO_INSTALL
|
$PKG_INSTALL $TO_INSTALL
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -36,13 +40,13 @@ CODENAME="$(python3 -m distro --json | jq -r .codename)"
|
|||||||
OS_VERSION="$(python3 -m distro --json | jq -r .version)"
|
OS_VERSION="$(python3 -m distro --json | jq -r .version)"
|
||||||
PUBLIC_IPV4="$(curl -s -4 ifconfig.me)"
|
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
|
read
|
||||||
|
|
||||||
if ! [ -e /usr/bin/salt-call ]; then
|
if ! [ -e /usr/bin/salt-call ]; then
|
||||||
set -x
|
set -x
|
||||||
if [[ "$(uname -m)" =~ arm* ]]; then
|
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 ] ||
|
[ -e /opt/saltstack/salt ] ||
|
||||||
python3 -m venv /opt/saltstack/salt
|
python3 -m venv /opt/saltstack/salt
|
||||||
/opt/saltstack/salt/bin/pip3 freeze | grep -q ^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 update
|
||||||
apt-get -y install salt-minion
|
apt-get -y install salt-minion
|
||||||
else
|
else
|
||||||
echo Unrecognized OS
|
echo -e "${RED}Unrecognized OS${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
set +x
|
set +x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
APPLY='salt-call state.apply --master=kpi.keiran.us salt'
|
APPLY='salt-call state.apply --master=kpi.keiran.us salt'
|
||||||
echo "Setup will now run:"
|
echo -e "${CYAN}Setup will now run:${NC}"
|
||||||
echo "$APPLY"
|
echo -e "$APPLY"
|
||||||
echo "The first run should send a key request to the master, then fail because it is not signed yet"
|
echo -e "${CYAN}The first run should send a key request to the master, then fail because it's not signed yet${NC}"
|
||||||
$APPLY
|
echo "Running..."
|
||||||
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)"
|
$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
|
read
|
||||||
$APPLY
|
$APPLY
|
||||||
|
|||||||
Reference in New Issue
Block a user