From 91bd883d1a895c584e2589381147c948e27f8b2c Mon Sep 17 00:00:00 2001 From: Vinanrra Date: Tue, 25 Jan 2022 18:05:08 +0100 Subject: [PATCH] Cleanup and fix update --- Dockerfile | 65 +++++----- README.md | 1 + install.sh | 5 +- lgsm/config-lgsm/sfserver/common.cfg | 172 --------------------------- scripts/check_space.sh | 16 ++- scripts/check_startMode.sh | 23 ++-- scripts/crontab/backup.sh | 8 +- scripts/crontab/monitor.sh | 8 +- scripts/first_install.sh | 101 +++++++--------- scripts/server_alerts.sh | 14 +-- scripts/server_backup.sh | 28 +---- scripts/server_start.sh | 11 +- scripts/server_update.sh | 50 ++++---- user.sh | 5 +- 14 files changed, 138 insertions(+), 369 deletions(-) delete mode 100644 lgsm/config-lgsm/sfserver/common.cfg diff --git a/Dockerfile b/Dockerfile index 2b0b03d..f5f6927 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,20 +4,13 @@ STOPSIGNAL SIGTERM ####Environments#### -ENV PUID=1000 -ENV PGID=1000 -ENV START_MODE=1 -ENV TEST_ALERT=no -ENV TimeZone=Europe/Madrid -ENV VERSION=public -ENV MONITOR=yes -ENV BACKUP=yes -ENV LANG=en_US.utf8 -ENV HOME=/home/sfserver - -##Need use xterm for LinuxGSM## -ENV TERM=xterm -ENV DEBIAN_FRONTEND noninteractive +ENV PUID=1000 PGID=1000 TimeZone=Europe/Madrid HOME=/home/sfserver LANG=en_US.utf8 TERM=xterm DEBIAN_FRONTEND=noninteractive \ + START_MODE=1 \ + TEST_ALERT=no \ + TimeZone=Europe/Madrid \ + VERSION=public \ + MONITOR=no \ + BACKUP=no ####Environments#### @@ -25,7 +18,7 @@ ENV DEBIAN_FRONTEND noninteractive ####Labels#### LABEL maintainer="vinanrra" -LABEL build_version="version: 0.0.6" +LABEL build_version="version: 0.0.7" #####Dependencies#### @@ -65,18 +58,18 @@ RUN dpkg --add-architecture i386 && \ # Install latest su-exec RUN set -ex; \ - \ - curl -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c; \ - \ - fetch_deps='gcc libc-dev'; \ - apt-get install -y --no-install-recommends $fetch_deps; \ - gcc -Wall \ - /usr/local/bin/su-exec.c -o/usr/local/bin/su-exec; \ - chown root:root /usr/local/bin/su-exec; \ - chmod 0755 /usr/local/bin/su-exec; \ - rm /usr/local/bin/su-exec.c; \ - \ - apt-get purge -y --auto-remove $fetch_deps + \ + curl -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c; \ + \ + fetch_deps='gcc libc-dev'; \ + apt-get install -y --no-install-recommends $fetch_deps; \ + gcc -Wall \ + /usr/local/bin/su-exec.c -o/usr/local/bin/su-exec; \ + chown root:root /usr/local/bin/su-exec; \ + chmod 0755 /usr/local/bin/su-exec; \ + rm /usr/local/bin/su-exec.c; \ + \ + apt-get purge -y --auto-remove $fetch_deps # Clear unused files RUN apt clean && \ @@ -93,19 +86,15 @@ RUN adduser --home /home/sfserver --disabled-password --shell /bin/bash --disabl # Base dir WORKDIR /home/sfserver +# Download linuxgsm script + perms RUN set -ex; \ -wget https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/master/linuxgsm.sh + wget https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/master/linuxgsm.sh && \ + chmod +x linuxgsm.sh && \ + su-exec sfserver bash linuxgsm.sh sfserver -RUN chmod +x linuxgsm.sh && su-exec sfserver bash linuxgsm.sh sfserver - -# Add files -ADD install.sh user.sh /home/sfserver/ -ADD scripts /home/sfserver/scripts -ADD lgsm/config-lgsm/sfserver/common.cfg /home/sfserver/ -ADD lgsm /home/sfserver/lgsm - -# Apply permissions -RUN chmod +x install.sh user.sh +# Add files with perms +COPY --chmod=755 install.sh user.sh /home/sfserver/ +COPY --chmod=755 scripts /home/sfserver/scripts ##############EXTRA CONFIG############## #Ports diff --git a/README.md b/README.md index b440892..124850c 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ LinuxGSM allows alerts to be received using various methods, multiple alerts can * Pushover * Telegram * Slack +* And more Alerts settings can be changed in */path/to/LGSM-Config/common.cfg* diff --git a/install.sh b/install.sh index 0a7f38e..fc2fb50 100644 --- a/install.sh +++ b/install.sh @@ -4,9 +4,8 @@ scriptsDir="${rootDir}/scripts" # Show log function show_log () { - i="0" - # -F = --follow=name --retry - tail -F /home/sfserver/log/console/sfserver-console.log + # -F = --follow=name --retry + tail -F /home/sfserver/log/console/sfserver-console.log } test_alert () { diff --git a/lgsm/config-lgsm/sfserver/common.cfg b/lgsm/config-lgsm/sfserver/common.cfg deleted file mode 100644 index d0600f7..0000000 --- a/lgsm/config-lgsm/sfserver/common.cfg +++ /dev/null @@ -1,172 +0,0 @@ -#### Game Server Settings #### - -## Predefined Parameters | https://docs.linuxgsm.com/configuration/start-parameters -ip="0.0.0.0" -queryport="15777" -beaconport="15000" -port="7777" - -## Server Parameters | https://docs.linuxgsm.com/configuration/start-parameters#additional-parameters -startparameters="FactoryGame -ServerQueryPort=${queryport} -BeaconPort=${beaconport} -Port=${port} -log -unattended" - -#### LinuxGSM Settings #### - -## LinuxGSM Stats -# Send useful stats to LinuxGSM developers. -# https://docs.linuxgsm.com/configuration/linuxgsm-stats -# (on|off) -stats="off" - -## Notification Alerts -# (on|off) - -# Display IP | https://docs.linuxgsm.com/alerts#display-ip -displayip="" - -# More info | https://docs.linuxgsm.com/alerts#more-info -postalert="off" - -# Discord Alerts | https://docs.linuxgsm.com/alerts/discord -discordalert="off" -discordwebhook="webhook" - -# Email Alerts | https://docs.linuxgsm.com/alerts/email -emailalert="off" -email="email@example.com" -emailfrom="" - -# Gotify Alerts | https://docs.linuxgsm.com/alerts/gotify -gotifyalert="off" -gotifytoken="token" -gotifywebhook="webhook" - -# IFTTT Alerts | https://docs.linuxgsm.com/alerts/ifttt -iftttalert="off" -ifttttoken="accesstoken" -iftttevent="linuxgsm_alert" - -# Mailgun Email Alerts | https://docs.linuxgsm.com/alerts/mailgun -mailgunalert="off" -mailgunapiregion="us" -mailguntoken="accesstoken" -mailgundomain="example.com" -mailgunemailfrom="alert@example.com" -mailgunemail="email@myemail.com" - -# Pushbullet Alerts | https://docs.linuxgsm.com/alerts/pushbullet -pushbulletalert="off" -pushbullettoken="accesstoken" -channeltag="" - -# Pushover Alerts | https://docs.linuxgsm.com/alerts/pushover -pushoveralert="off" -pushovertoken="accesstoken" -pushoveruserkey="userkey" - -# Rocket.Chat Alerts | https://docs.linuxgsm.com/alerts/rocket.chat -rocketchatalert="off" -rocketchatwebhook="webhook" -rocketchattoken="" - -# Slack Alerts | https://docs.linuxgsm.com/alerts/slack -slackalert="off" -slackwebhook="webhook" - -# Telegram Alerts | https://docs.linuxgsm.com/alerts/telegram -# You can add a custom cURL string eg proxy (useful in Russia) in "curlcustomstring". -# For example "--socks5 ipaddr:port" for socks5 proxy see more in "curl --help". -telegramapi="api.telegram.org" -telegramalert="off" -telegramtoken="accesstoken" -telegramchatid="" -curlcustomstring="" - -## Updating | https://docs.linuxgsm.com/commands/update -updateonstart="off" - -## Backup | https://docs.linuxgsm.com/commands/backup -maxbackups="4" -maxbackupdays="30" -stoponbackup="on" - -## Logging | https://docs.linuxgsm.com/features/logging -consolelogging="on" -logdays="7" - -## Monitor | https://docs.linuxgsm.com/commands/monitor -# Query delay time -querydelay="1" - -## ANSI Colors | https://docs.linuxgsm.com/features/ansi-colors -ansi="on" - -#### Advanced Settings #### - -## Message Display Time | https://docs.linuxgsm.com/features/message-display-time -sleeptime="0.5" - -## SteamCMD Settings | https://docs.linuxgsm.com/steamcmd -# Server appid -appid="1690800" -steamcmdforcewindows="no" -# SteamCMD Branch | https://docs.linuxgsm.com/steamcmd/branch -branch="" -betapassword="" -# Master Server | https://docs.linuxgsm.com/steamcmd/steam-master-server -steammaster="false" - -## Stop Mode | https://docs.linuxgsm.com/features/stop-mode -# 1: tmux kill -# 2: CTRL+c -# 3: quit -# 4: quit 120s -# 5: stop -# 6: q -# 7: exit -# 8: 7 Days to Die -# 9: GoldSrc -# 10: Avorion -# 11: end -stopmode="2" - -## Query mode -# 1: session only -# 2: gamedig (gsquery fallback) -# 3: gamedig -# 4: gsquery -# 5: tcp -querymode="1" -querytype="" - -## Console type -consoleverbose="yes" -consoleinteract="no" - -#### Directories #### -# Edit with care - -## Game Server Directories -systemdir="${serverfiles}/FactoryGame" -executabledir="${serverfiles}/Engine/Binaries/Linux" -executable="./UE4Server-Linux-Shipping" -servercfgdir="${systemdir}/Saved/Config/LinuxServer" -servercfg="GameUserSettings.ini" -servercfgdefault="GameUserSettings.ini" -servercfgfullpath="${servercfgdir}/${servercfg}" - -## Backup Directory -backupdir="${lgsmdir}/backup" - -## Logging Directories -logdir="${rootdir}/log" -gamelogdir="${systemdir}/Saved/Logs" -lgsmlogdir="${logdir}/script" -consolelogdir="${logdir}/console" -lgsmlog="${lgsmlogdir}/${selfname}-script.log" -consolelog="${consolelogdir}/${selfname}-console.log" -alertlog="${lgsmlogdir}/${selfname}-alert.log" -postdetailslog="${lgsmlogdir}/${selfname}-postdetails.log" - -## Logs Naming -lgsmlogdate="${lgsmlogdir}/${selfname}-script-$(date '+%Y-%m-%d-%H:%M:%S').log" -consolelogdate="${consolelogdir}/${selfname}-console-$(date '+%Y-%m-%d-%H:%M:%S').log" diff --git a/scripts/check_space.sh b/scripts/check_space.sh index 0dae067..d6b4225 100644 --- a/scripts/check_space.sh +++ b/scripts/check_space.sh @@ -1,7 +1,21 @@ #!/bin/bash mkdir -p /home/sfserver/serverfiles/FactoryGame -free=`df -k --output=avail /home/sfserver/serverfiles/FactoryGame | tail -n1` # df -k not df -h +free=$(df -k --output=avail /home/sfserver/serverfiles/FactoryGame | tail -n1) # df -k not df -h freeGB=$(expr $free / 1024 / 1024) if [[ $free -lt 12582912 ]]; then # 12G = 12*1024*1024k space=no fi + +if [ "${space,,}" == 'no' ]; then + echo "[ERROR] + ======================================================================= + + Not enough space. + + Needed: 12 GB + Available: $freeGB GB + + ======================================================================= + " + exit +fi \ No newline at end of file diff --git a/scripts/check_startMode.sh b/scripts/check_startMode.sh index de7ff07..48b3790 100644 --- a/scripts/check_startMode.sh +++ b/scripts/check_startMode.sh @@ -1,14 +1,13 @@ #!/bin/bash -echo " - ======================================================================= - IMPORTANT: - - START_MODE $START_MODE UNKNOWN - - Stopping container... - - Check your START_MODE, the number must be between 1 and 6 - More info: https://github.com/vinanrra/Docker-Satisfactory#start-modes - ======================================================================= - " +echo "[ERROR] + ======================================================================= + + START_MODE $START_MODE UNKNOWN + + Stopping container... + + Check your START_MODE, the number must be between 1 and 4 + More info: https://github.com/vinanrra/Docker-Satisfactory#start-modes + ======================================================================= +" diff --git a/scripts/crontab/backup.sh b/scripts/crontab/backup.sh index 05ae507..e79f5ce 100644 --- a/scripts/crontab/backup.sh +++ b/scripts/crontab/backup.sh @@ -1,10 +1,4 @@ #!/bin/bash echo "0 5 * * * /home/sfserver/sfserver backup > /dev/null 2>&1" >> crontab.txt -echo " - ======================================================================= - IMPORTANT: - - Activated automatic backup at 5AM - ======================================================================= - " +echo "[INFO] Activated automatic backup" diff --git a/scripts/crontab/monitor.sh b/scripts/crontab/monitor.sh index 2254391..a666626 100644 --- a/scripts/crontab/monitor.sh +++ b/scripts/crontab/monitor.sh @@ -1,10 +1,4 @@ #!/bin/bash echo "*/5 * * * * /home/sfserver/sfserver monitor > /dev/null 2>&1" >> crontab.txt -echo " - ======================================================================= - IMPORTANT: - - Activated server monitoring, automatic restart if crash - ======================================================================= - " +echo "[INFO] Activated server monitoring, automatic restart if crash" diff --git a/scripts/first_install.sh b/scripts/first_install.sh index 7e4abb3..302195a 100644 --- a/scripts/first_install.sh +++ b/scripts/first_install.sh @@ -1,61 +1,44 @@ #!/bin/bash -source $scriptsDir/check_space.sh - - - if [ "${space,,}" == 'no' ]; then - echo " - ======================================================================= - ERROR: - - Not enough space. - - Needed: 12 GB - Available: $freeGB GB - - ======================================================================= - " - exit - fi - - echo " - ======================================================================= - IMPORTANT: - - It seems to be the first installation, making preparations... - ======================================================================= - " - - # Start to create default files - ./sfserver - - echo " - ======================================================================= - IMPORTANT: - - PREPARATIONS COMPLETED - - Making first server installation. - ======================================================================= - " - - # Add alerts examples - - mv -f common.cfg /home/sfserver/lgsm/config-lgsm/sfserver/common.cfg - - sed -i "s/branch=".*"/branch="\"${VERSION,,}"\"/" /home/sfserver/lgsm/config-lgsm/sfserver/common.cfg - - # Install Satisfactory Server - - ./sfserver auto-install - - echo " - ======================================================================= - IMPORTANT: - - The server have been installed. - More info: https://github.com/vinanrra/Docker-Satisfactory#start-modes - ======================================================================= - " - - echo "If this file is missing, server will be re-installed" > serverfiles/DONT_REMOVE.txt +BASEPATH=/home/sfserver +LSGMSDTDSERVERCFG=${BASEPATH}/lgsm/config-lgsm/sdtdserver/sdtdserver.cfg + +source $scriptsDir/check_space.sh + +echo "[INFO] It seems to be the first installation, making preparations..." + +# Start to create default files +./sfserver + +# Check version + +echo "[INFO] Selection version ${VERSION} to install" + +if [ "${VERSION,,}" == 'stable' ] || [ "${VERSION,,}" == 'public' ] + then + if grep -R "branch" "$LSGMSDTDSERVERCFG" + then + sed -i "s/branch=.*/branch=\"\"/" "$LSGMSDTDSERVERCFG" + echo "[INFO] Version changed to ${VERSION,,}" + else + echo "[INFO] Already on ${VERSION,,}" + fi + else + if grep -R "branch" "$LSGMSDTDSERVERCFG" + then + sed -i 's/branch=.*/branch="$VERSION"/' "$LSGMSDTDSERVERCFG" + else + echo branch='"-beta $VERSION"' >> "$LSGMSDTDSERVERCFG" + echo "[INFO] Version changed to ${VERSION,,}" + fi +fi + +echo "[INFO] Starting server installation" + +# Install Satisfactory Server + +./sfserver auto-install + +echo "[INFO] The server have been installed." + +echo "If this file is missing, server will be re-installed" > serverfiles/DONT_REMOVE.txt diff --git a/scripts/server_alerts.sh b/scripts/server_alerts.sh index 5fc22b4..874cc2a 100644 --- a/scripts/server_alerts.sh +++ b/scripts/server_alerts.sh @@ -1,10 +1,6 @@ #!/bin/bash -echo " - ======================================================================= - IMPORTANT: - - Testing alerts... - Check your alerts method - ======================================================================= - " - ./sfserver test-alert +echo "[INFO] Testing alerts..." + +./sfserver test-alert + +echo "[INFO] Test alert send, check your alerts method" diff --git a/scripts/server_backup.sh b/scripts/server_backup.sh index 6df6c08..02b06c7 100644 --- a/scripts/server_backup.sh +++ b/scripts/server_backup.sh @@ -1,24 +1,6 @@ #!/bin/bash -echo " - ======================================================================= - IMPORTANT: - - This backup will create a complete tar bzip2 archive of the whole server. - - ======================================================================= - " - - sleep 3s - - ./sfserver backup - - sleep 3s - - echo " - ======================================================================= - IMPORTANT: - - Backup complete. - - ======================================================================= - " +echo "[INFO] This backup will create a complete tar bzip2 archive of the whole server." + +./sfserver backup + +echo "[INFO] Backup complete." diff --git a/scripts/server_start.sh b/scripts/server_start.sh index b9a91fd..4481bfd 100644 --- a/scripts/server_start.sh +++ b/scripts/server_start.sh @@ -2,13 +2,6 @@ ./sfserver start - echo " - ======================================================================= - IMPORTANT: - - Starting server... - Soon you will see all the info - ======================================================================= - " +echo "[INFO] Starting server, soon you will see all the info" - ./sfserver details +./sfserver details diff --git a/scripts/server_update.sh b/scripts/server_update.sh index 49e8520..9f247bd 100644 --- a/scripts/server_update.sh +++ b/scripts/server_update.sh @@ -1,31 +1,29 @@ #!/bin/bash -./sfserver update - if [ "${VERSION,,}" == 'public' ] - then - # Remove branch line - sed -i 's/branch=".*"/branch=""/' /home/sfserver/lgsm/config-lgsm/sfserver/common.cfg - else - # Remove branch line if exist to avoid multiple branch lines - sed -i "s/branch=".*"/branch="\"${VERSION,,}"\"/" /home/sfserver/lgsm/config-lgsm/sfserver/common.cfg - - echo " - ======================================================================= - IMPORTANT: - - Server version changed to: ${VERSION,,} - - ======================================================================= - " - fi +BASEPATH=/home/sfserver +LSGMSDTDSERVERCFG=${BASEPATH}/lgsm/config-lgsm/sdtdserver/sdtdserver.cfg + +echo "[INFO] Selection version ${VERSION} to install" - ./sfserver update +if [ "${VERSION,,}" == 'stable' ] || [ "${VERSION,,}" == 'public' ] + then + if grep -R "branch" "$LSGMSDTDSERVERCFG" + then + sed -i "s/branch=.*/branch=\"\"/" "$LSGMSDTDSERVERCFG" + echo "[INFO] Version changed to ${VERSION,,}" + else + echo "[INFO] Already on ${VERSION,,}" + fi + else + if grep -R "branch" "$LSGMSDTDSERVERCFG" + then + sed -i 's/branch=.*/branch="$VERSION"/' "$LSGMSDTDSERVERCFG" + else + echo branch='"-beta $VERSION"' >> "$LSGMSDTDSERVERCFG" + echo "[INFO] Version changed to ${VERSION,,}" + fi +fi - echo " - ======================================================================= - IMPORTANT: +./sfserver update - The server have been updated to latest ${VERSION,,} version - More info: https://github.com/vinanrra/Docker-Satisfactory#start-modes - ======================================================================= - " +echo "[INFO] The server have been updated to ${VERSION,,} version" diff --git a/user.sh b/user.sh index 06a9bbe..d9d7fbd 100644 --- a/user.sh +++ b/user.sh @@ -20,7 +20,7 @@ echo " GID: $PGID MORE INFO: If you have permission problems remember to use same user UID and GID. - Check it with "id" command + Check it with \"id\" command If problem persist check: https://github.com/vinanrra/Docker-Satisfactory/blob/master/README.md ======================================================================= @@ -31,8 +31,7 @@ groupmod -o -g "$PGID" sfserver > /dev/null 2>&1 usermod -o -u "$PUID" sfserver > /dev/null 2>&1 # Locale, Timezone and user -localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 && \ - ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone +ln -snf /usr/share/zoneinfo/"$TimeZone" /etc/localtime && echo "$TimeZone" > /etc/timezone # Apply owner to the folder to avoid errors chown -R sfserver:sfserver /home/sfserver