7_Days_to_Die/install.bash

67 lines
2.5 KiB
Bash
Raw Permalink Normal View History

2021-12-25 21:58:02 -06:00
#!/bin/bash
# Exit on any unhandled error
set -e
GIT_DIR="${HOME}/7-Days-To-Die-Temp"
GENERAL_MODULE_PATH="${GIT_DIR}/Scripts/general"
SDTD_USER_NAME="sdtd"
SDTD_USER_HOME="/home/${SDTD_USER_NAME}/"
SDTD_BIN_DIR="${SDTD_USER_HOME}/.bin"
# Get the repo as this script SHOULD be a copy paste into a terminal, so we have to pull this down
git clone --recurse-submodules https://gitlab.orion-technologies.io/game-servers/7-days-to-die.git "${GIT_DIR}"
# Run general installation from the general submodule
2021-12-25 23:50:50 -06:00
sudo /bin/bash "${GENERAL_MODULE_PATH}/install.bash" "${GENERAL_MODULE_PATH}" || exit
# Create the user
if id -u "${SDTD_USER_NAME}" > /dev/null 2>&1; then
mkdir -p "${SDTD_USER_HOME}"
else
echo "Creating user ${SDTD_USER_NAME}"
sudo useradd -m -s /bin/bash "${SDTD_USER_NAME}" 2>/dev/null
fi
# Create the user .bin directory, I prefer .bin in scenarios in which I need
# significant user segmentation, e.g. I have some users running a different game
# and only this user managing 7 Days to Die; considering that these scripts are
# VERY opinionated this exists.
mkdir -p "${SDTD_BIN_DIR}"
# Deploy the scipts, removing .bash from the end of them
for script in "${GIT_DIR}/Scripts/"*.bash; do
if [[ -f "${script}" ]]; then
script_name="$(basename "${script}")"
script_suffixless="${script_name%.bash}"
cat "${script}" > "${SDTD_BIN_DIR}/${script_suffixless}"
chmod 740 "${SDTD_BIN_DIR}/${script_suffixless}"
fi
done
2021-12-26 00:32:38 -06:00
chown -R "${SDTD_USER_NAME}:${SDTD_USER_NAME}" "${SDTD_BIN_DIR}"
### bash_profile modification ###
# Yes this all could be one brace expansion, but that makes it more difficult
# to parse at a cursory glance
# Ensure the path for .bin is in the user's bash_profile
echo "export PATH=\${PATH}:~/.bin" >> "${SDTD_USER_HOME}/.bash_profile"
# Ensure the path for steamcmd is in the user's bash profile, typically installed to /usr/local/bin
# for some reason this isn't in the path in certain situations by default...
echo "export PATH=\${PATH}:/usr/local/bin" >> "${SDTD_USER_HOME}/.bash_profile"
# Ensure the completions are being sourced
echo "source ~/.bin/7D2D-Manage-Completion" >> "${SDTD_USER_HOME}/.bash_profile"
echo "Cleaning up ${GIT_DIR}"
rm -rf "${GIT_DIR}"
echo "Finished with installation."
2021-12-26 00:38:01 -06:00
echo "You should open the default ports for the server, default starts at 50000. Considering opening 50000 - 50010, that will allow up to 10 7D2D servers without telnet"
echo "To try it out as the user paste the following:"
echo "su ${SDTD_USER_NAME} && source ~/.bash_profile && 7D2D-Manage -h"