Files
salt-states/setup.sh
2026-04-03 20:06:21 +01:00

73 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
set -e
SALT_VERSION='3007.13'
CYAN='\033[1;36m'
RED='\033[0;31m'
NC='\033[0m'
if [ $UID -ne 0 ]; then
echo -e "${RED}This script must run as root.${NC}"
exit 1
fi
if [ -f /usr/bin/dnf ]; then
dnf -d0 -y install pciutils-libs || :
fi
PUBLIC_IPV4="$(curl -s -4 ifconfig.me)"
echo -e -n "${CYAN}Add $PUBLIC_IPV4 to the firewall on on the salt master, then press enter${NC}"
read
mkdir -p /etc/salt/pki/minion \
/etc/salt/minion.d \
/var/cache/salt/minion \
/var/log/salt \
/var/run/salt
if [ -e /opt/saltstack/salt/bin/salt-call ]; then
echo "/opt/saltstack/salt/bin/salt-call already exists"
else
if ! [ -f /root/.local/bin/python3.10 ]; then
if ! [ -f /root/.local/bin/uv ]; then
echo -e "${CYAN}Installing uv${NC}"
curl -LsSf https://astral.sh/uv/install.sh | sh
fi
if ! [ -f /root/.local/bin/uv ]; then
echo -e "${RED}Failed to install uv${NC}"
exit 1
fi
/root/.local/bin/uv python update-shell || true
export PATH="/root/.local/bin:$PATH"
echo -e "${CYAN}Installing Python 3.10 with uv${NC}"
uv python install 3.10
fi
if ! [ -f /root/.local/bin/python3.10 ]; then
echo -e "${RED}Failed to install python 3.10${NC}"
exit 1
fi
if ! [ -e /opt/saltstack/salt ]; then
echo -e "${CYAN}Setting up venv in /opt/saltstack/salt${NC}"
/root/.local/bin/python3.10 -m venv /opt/saltstack/salt
/opt/saltstack/salt/bin/pip install -U pip
fi
if ! /opt/saltstack/salt/bin/pip freeze | grep -q ^salt== ; then
echo -e "${CYAN}Installing salt $SALT_VERSION${NC}"
/opt/saltstack/salt/bin/pip install "salt==$SALT_VERSION"
/opt/saltstack/salt/bin/pip install -r "https://raw.githubusercontent.com/saltstack/salt/refs/tags/v$SALT_VERSION/requirements/zeromq.txt"
fi
ln -svfT /opt/saltstack/salt/bin/salt-call /usr/bin/salt-call
fi
APPLY='salt-call state.apply --master=kpi.keiran.us salt'
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