diff --git a/Dockerfile b/Dockerfile index 71e8887..c7d2f90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,10 @@ LABEL maintainer="LinuxGSM " ENV DEBIAN_FRONTEND noninteractive ENV TERM=xterm +ENV LGSM_GITHUBUSER=GameServerManagers +ENV LGSM_GITHUBREPO=LinuxGSM +ENV LGSM_GITHUBBRANCH=develop SHELL ["/bin/bash", "-o", "pipefail", "-c"] -USER root ## Install Base LinuxGSM Requirements RUN echo "**** Install Base LinuxGSM Requirements ****" \ @@ -57,8 +59,8 @@ RUN echo "**** Install Base LinuxGSM Requirements ****" \ && rm -rf /tmp/* \ && rm -rf /var/tmp/* -# Install NodeJS -RUN echo "**** Install NodeJS ****" \ +# Install Node.js +RUN echo "**** Install Node.js ****" \ && curl -sL https://deb.nodesource.com/setup_16.x | bash - \ && apt-get update \ && apt-get install -y nodejs \ @@ -72,55 +74,39 @@ RUN echo "**** Install NodeJS ****" \ RUN echo "**** Install GameDig ****" \ && npm install -g gamedig -ARG USERNAME=linuxgsm -ARG UID=1000 -ARG GID=1000 - -## Add linuxgsm user -RUN echo "**** Add linuxgsm user ****" \ - # Create the user - && groupadd --gid ${GID} ${USERNAME} \ - && useradd --uid ${UID} --gid ${GID} -m ${USERNAME} \ - && usermod --shell /bin/bash ${USERNAME} \ - && echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \ - && chmod 0440 /etc/sudoers.d/${USERNAME} \ - && chown ${USERNAME}:${USERNAME} /home/${USERNAME} +WORKDIR /linuxgsm ## Download linuxgsm.sh RUN echo "**** Download linuxgsm.sh ****" \ && set -ex \ - && wget -O linuxgsm.sh https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/master/linuxgsm.sh \ - && chmod +x /linuxgsm.sh + && mkdir -p /linuxgsm/lgsm \ + && wget -O linuxgsm.sh "https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/${LGSM_GITHUBBRANCH}/linuxgsm.sh" \ + && chmod +x linuxgsm.sh # Create linuxgsm symlinks RUN echo "**** Create Symlinks ****" \ - ln -sn /home/linuxgsm/serverfiles /serverfiles; \ - ln -sn /home/linuxgsm/lgsm/config-lgsm /config-lgsm; \ - ln -sn /home/linuxgsm/lgsm/logs /logs - -WORKDIR /home/linuxgsm -ENV PATH=$PATH:/home/linuxgsm -USER linuxgsm - -# Run SteamCMD as LinuxGSM user -RUN echo "**** Prepare SteamCMD ****" \ - mkdir -pv /home/linuxgsm/.steam/root \ - mkdir -pv /home/linuxgsm/.steam/steam \ - steamcmd +quit + && ln -sn /serverfiles /linuxgsm/serverfiles \ + && ln -sn /config-lgsm /linuxgsm/lgsm/config-lgsm \ + && ln -sn /logs /linuxgsm/lgsm/logs RUN echo "**** Get LinuxGSM Modules ****" \ - git clone --filter=blob:none --no-checkout --depth 1 --sparse https://github.com/GameServerManagers/LinuxGSM.git; \ - cd LinuxGSM; \ - git sparse-checkout set lgsm/functions; \ - git checkout; \ - mkdir -p /home/linuxgsm/lgsm/functions; \ - mv lgsm/functions/* /home/linuxgsm/lgsm/functions; \ - chmod +x /home/linuxgsm/lgsm/functions/*; \ - rm -rf /home/linuxgsm/LinuxGSM + && git clone --filter=blob:none --no-checkout --sparse https://github.com/GameServerManagers/LinuxGSM.git \ + && cd LinuxGSM \ + && git sparse-checkout set --cone \ + && git sparse-checkout set lgsm/functions \ + && git checkout ${LGSM_GITHUBBRANCH} \ + && mkdir -p /linuxgsm/lgsm/functions \ + && mv lgsm/functions/* /linuxgsm/lgsm/functions \ + && chmod +x /linuxgsm/lgsm/functions/* \ + && rm -rf /linuxgsm/LinuxGSM # Add LinuxGSM cronjobs RUN echo "**** Create Cronjobs ****" -RUN (crontab -l 2>/dev/null; echo "*/1 * * * * /home/linuxgsm/*server monitor > /dev/null 2>&1") | crontab - -RUN (crontab -l 2>/dev/null; echo "*/30 * * * * /home/linuxgsm/*server update > /dev/null 2>&1") | crontab - +RUN (crontab -l 2>/dev/null; echo "*/1 * * * * /linuxgsm/*server monitor > /dev/null 2>&1") | crontab - +RUN (crontab -l 2>/dev/null; echo "*/30 * * * * /linuxgsm/*server update > /dev/null 2>&1") | crontab - -COPY entrypoint.sh /home/linuxgsm/entrypoint.sh +RUN rm -f /linuxgsm/entrypoint.sh +COPY entrypoint.sh /linuxgsm/entrypoint.sh +RUN date > /time.txt +ENTRYPOINT [ "/usr/bin/tini", "--" ] +CMD [ "bash","./entrypoint.sh" ] diff --git a/entrypoint.sh b/entrypoint.sh index ff374aa..d820868 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,20 +11,11 @@ exit_handler() { echo "loading exit trap" trap exit_handler SIGTERM -echo "update permissions for linuxgsm" -if [ -z "${UID}" ]; then - UID=1000 -fi -if [ -z "${GID}" ]; then - GID=1000 -fi -sudo usermod -u ${UID} linuxgsm -sudo groupmod -g ${GID} linuxgsm -sudo chown -R ${UID}:${GID} /home/linuxgsm -reset - -echo -e "Welcome to the LinuxGSM Docker" +echo -e "" +echo -e "Welcome to the DockerGSM" echo -e "================================================================================" +echo -e "TIME: $(date)" +echo -e "SCRIPT TIME: $(cat /time.txt)" echo -e "GAMESERVER: ${GAMESERVER}" echo -e "" echo -e "USER: ${USERNAME}" @@ -39,11 +30,11 @@ echo -e "" echo -e "Initalising" echo -e "================================================================================" -# Copy linuxgsm.sh into homedir -if [ ! -e ~/linuxgsm.sh ]; then - echo "copying linuxgsm.sh to /home/linuxgsm" - cp /linuxgsm.sh ~/linuxgsm.sh -fi +export LGSM_GITHUBUSER=${LGSM_GITHUBUSER} +export LGSM_GITHUBREPO=${LGSM_GITHUBREPO} +export LGSM_GITHUBBRANCH=${LGSM_GITHUBBRANCH} + +cd /linuxgsm || exit # Setup game server if [ ! -f "${GAMESERVER}" ]; then @@ -51,14 +42,19 @@ if [ ! -f "${GAMESERVER}" ]; then ./linuxgsm.sh ${GAMESERVER} fi +# Clear functions directory if not master +if [ "${LGSM_GITHUBBRANCH}" != "master" ]; then + rm -rf /linuxgsm/lgsm/functions/* +fi + # Install game server if [ -z "$(ls -A -- "serverfiles")" ]; then echo "installing ${GAMESERVER}" ./${GAMESERVER} auto-install fi -echo "starting cron" -sudo cron +echo "Starting cron" +cron # Update game server echo ""