redo salt setup
This commit is contained in:
114
setup.sh
114
setup.sh
@@ -1,8 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
SALT_VERSION='3007.1'
|
||||
SALT_VERSION='3007.13'
|
||||
|
||||
CYAN='\033[1;36m'
|
||||
RED='\033[0;31m'
|
||||
@@ -13,90 +12,53 @@ if [ $UID -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f /etc/debian_version ]; then
|
||||
PKG_CHECK='dpkg -l'
|
||||
PKG_INSTALL='apt-get -y install'
|
||||
elif [ -f /etc/redhat-release ]; then
|
||||
PKG_CHECK='rpm -q'
|
||||
PKG_INSTALL='yum -y install'
|
||||
else
|
||||
echo -e "${RED}Unrecognized OS${NC}"
|
||||
exit 1
|
||||
if [ -f /usr/bin/dnf ]; then
|
||||
dnf -d0 -y install pciutils-libs || :
|
||||
fi
|
||||
|
||||
TO_INSTALL=""
|
||||
for PKG in jq curl python3-distro; do
|
||||
if ! $PKG_CHECK $PKG &>/dev/null; then
|
||||
TO_INSTALL="$TO_INSTALL $PKG"
|
||||
fi
|
||||
done
|
||||
if [ -n "$TO_INSTALL" ]; then
|
||||
echo -e "${CYAN}Installing ${TO_INSTALL}${NC}"
|
||||
$PKG_INSTALL $TO_INSTALL
|
||||
fi
|
||||
|
||||
DISTRO="$(python3 -m distro --json | jq -r .id)"
|
||||
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 -e -n "${CYAN}Ensure $PUBLIC_IPV4 is whitelisted on the salt master, then press enter${NC}"
|
||||
echo -e -n "${CYAN}Add $PUBLIC_IPV4 to the firewall on on the salt master, then press enter${NC}"
|
||||
read
|
||||
|
||||
if ! [ -e /usr/bin/salt-call ]; then
|
||||
if [[ "$DISTRO" == "fedora" ]]; then
|
||||
mkdir -p /etc/salt/pki/minion
|
||||
echo -e "${CYAN}Fedora detected - installing Python3.10 if not present, then using a venv${NC}"
|
||||
if ! which python3.10 &>/dev/null; then
|
||||
wget -O /usr/local/bin/python3.10 https://github.com/niess/python-appimage/releases/download/python3.10/python3.10.13-cp310-cp310-manylinux_2_28_x86_64.AppImage
|
||||
chmod +x /usr/local/bin/python3.10
|
||||
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
|
||||
[ -e /opt/saltstack/salt ] ||
|
||||
/usr/local/bin/python3.10 -m venv /opt/saltstack/salt
|
||||
/opt/saltstack/salt/bin/pip3 freeze | grep -q ^salt== ||
|
||||
/opt/saltstack/salt/bin/pip3 install "salt==$SALT_VERSION"
|
||||
ln -sfT /opt/saltstack/salt/bin/salt-call /usr/bin/salt-call
|
||||
elif [[ "$(uname -m)" =~ arm* ]]; then
|
||||
echo -e "${CYAN}Arm CPU detected. Using venv install method${NC}"
|
||||
[ -e /opt/saltstack/salt ] ||
|
||||
python3 -m venv /opt/saltstack/salt
|
||||
/opt/saltstack/salt/bin/pip3 freeze | grep -q ^salt== ||
|
||||
/opt/saltstack/salt/bin/pip3 install "salt==$SALT_VERSION"
|
||||
ln -sfT /opt/saltstack/salt/bin/salt-call /usr/bin/salt-call
|
||||
elif [[ "$DISTRO" == "centos" ]] || [[ "$DISTRO" == "almalinux" ]]; then
|
||||
if [[ "$DISTRO" == "almalinux" ]]; then
|
||||
OS_VERSION="$(python3 -m distro --json | jq -r .version_parts.major)"
|
||||
if ! [ -f /root/.local/bin/uv ]; then
|
||||
echo -e "${RED}Failed to install uv${NC}"
|
||||
exit 1
|
||||
fi
|
||||
rpm --import https://repo.saltproject.io/salt/py3/redhat/$OS_VERSION/x86_64/SALT-PROJECT-GPG-PUBKEY-2023.pub
|
||||
[ -f /etc/yum.repos.d/salt.repo ] ||
|
||||
curl -fsSL -o /etc/yum.repos.d/salt.repo https://repo.saltproject.io/salt/py3/redhat/$OS_VERSION/x86_64/minor/$SALT_VERSION.repo
|
||||
yum clean all
|
||||
yum install -y salt-minion
|
||||
elif [[ "$DISTRO" == "ubuntu" ]]; then
|
||||
mkdir -p /etc/apt/keyrings
|
||||
KEYPATH=/etc/apt/keyrings/salt-archive-keyring-2023.gpg
|
||||
curl -fsSL -o $KEYPATH https://repo.saltproject.io/salt/py3/ubuntu/$OS_VERSION/amd64/SALT-PROJECT-GPG-PUBKEY-2023.gpg
|
||||
[ -f /etc/apt/sources.list.d/salt.list ] ||
|
||||
echo "deb [signed-by=$KEYPATH arch=amd64] https://repo.saltproject.io/salt/py3/ubuntu/$OS_VERSION/amd64/minor/$SALT_VERSION $CODENAME main" > /etc/apt/sources.list.d/salt.list
|
||||
apt-get update
|
||||
apt-get -y install salt-minion
|
||||
elif [[ "$DISTRO" == "debian" ]]; then
|
||||
if [ $OS_VERSION -gt 11 ]; then
|
||||
OS_VERSION=11
|
||||
CODENAME=bullseye
|
||||
fi
|
||||
mkdir -p /etc/apt/keyrings
|
||||
KEYPATH=/etc/apt/keyrings/salt-archive-keyring-2023.gpg
|
||||
[ -f $KEYPATH ] ||
|
||||
curl -fsSL -o $KEYPATH https://repo.saltproject.io/salt/py3/debian/$OS_VERSION/amd64/SALT-PROJECT-GPG-PUBKEY-2023.gpg
|
||||
[ -f /etc/apt/sources.list.d/salt.list ] ||
|
||||
echo "deb [signed-by=$KEYPATH arch=amd64] https://repo.saltproject.io/salt/py3/debian/$OS_VERSION/amd64/minor/$SALT_VERSION $CODENAME main" > /etc/apt/sources.list.d/salt.list
|
||||
apt-get update
|
||||
apt-get -y install salt-minion
|
||||
else
|
||||
echo -e "${RED}Unrecognized OS${NC}"
|
||||
/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'
|
||||
|
||||
Reference in New Issue
Block a user