Run salt-master as salt user

This commit is contained in:
Carlos Álvaro
2018-11-09 23:44:16 +01:00
parent 13f75f64ea
commit 886c85e1a3
6 changed files with 42 additions and 10 deletions

13
assets/build/functions.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
# Execute a command as SALT_USER
function exec_as_salt()
{
if [[ $(whoami) == ${SALT_USER} ]]; then
$@
else
sudo -HEu ${SALT_USER} "$@"
fi
}

View File

@@ -2,6 +2,8 @@
set -e
source ${SALT_BUILD_DIR}/functions.sh
# Install build dependencies
echo "Installing dependencies ..."
BUILD_DEPENDENCIES="gnupg git cmake gcc g++ make \
@@ -10,6 +12,15 @@ BUILD_DEPENDENCIES="gnupg git cmake gcc g++ make \
apt-get install --yes --quiet --no-install-recommends ${BUILD_DEPENDENCIES}
# Create salt user
echo "Creating ${SALT_USER} user ..."
useradd -d ${SALT_HOME} -ms /bin/bash -U -G root,sudo ${SALT_USER}
# Set PATH
exec_as_salt cat >> ${SALT_HOME}/.profile <<EOF
PATH=/usr/local/sbin:/usr/local/bin:\$PATH
EOF
# Compile libssh2
echo "Building libssh2 v${LIBSSH2_VERSION} ..."
wget https://github.com/libssh2/libssh2/archive/libssh2-${LIBSSH2_VERSION}.tar.gz
@@ -36,10 +47,6 @@ pip3 install "pygit2==v${PYGIT2_VERSION}" \
"libnacl==v${LIBNACL_VERSION}" \
"raet==v${RAET_VERSION}"
# Salt user
echo "Creating ${SALT_USER} user ..."
useradd -d ${SALT_HOME} -ms /bin/bash -U -G root,sudo ${SALT_USER}
# Bootstrap script options:
# https://docs.saltstack.com/en/latest/topics/tutorials/salt_bootstrap.html#command-line-options
## -M: install Salt Master by default