fix: invalid INTERNAL_IP environment value

New IP route output appends UID to the result, causing the value to be set to that instead of the IP. Fix it by ignoring the last two appended UID results
This commit is contained in:
Alex
2022-04-24 18:10:20 +03:00
parent 9f02fe140f
commit cd6b949868
25 changed files with 70 additions and 48 deletions

View File

@@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Set environment variable that holds the Internal Docker IP
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo -e $(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')) MODIFIED_STARTUP=$(echo -e $(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g'))

View File

@@ -1,8 +1,9 @@
#!/bin/ash #!/bin/ash
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Set environment variable that holds the Internal Docker IP
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')` MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')`

View File

@@ -1,12 +1,13 @@
#!/bin/bash #!/bin/bash
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Set environment variable that holds the Internal Docker IP
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo -e $(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')) MODIFIED_STARTUP=$(echo -e $(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g'))
echo -e ":/home/container$ ${MODIFIED_STARTUP}" echo -e ":/home/container$ ${MODIFIED_STARTUP}"
# Run the Server # Run the Server
eval ${MODIFIED_STARTUP} eval ${MODIFIED_STARTUP}

View File

@@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Set environment variable that holds the Internal Docker IP
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')` MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')`

View File

@@ -5,7 +5,7 @@ TZ=${TZ:-UTC}
export TZ export TZ
# Set environment variable that holds the Internal Docker IP # Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $NF;exit}') INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP export INTERNAL_IP
# Switch to the container's working directory # Switch to the container's working directory

View File

@@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Set environment variable that holds the Internal Docker IP
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g') MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')

View File

@@ -3,7 +3,7 @@ TZ=${TZ:-UTC}
export TZ export TZ
# Set environment variable that holds the Internal Docker IP # Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $NF;exit}') INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP export INTERNAL_IP
# Switch to the container's working directory # Switch to the container's working directory

View File

@@ -1,12 +1,13 @@
#!/bin/bash #!/bin/bash
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Set environment variable that holds the Internal Docker IP
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g') MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
echo -e ":/home/container$ ${MODIFIED_STARTUP}" echo -e ":/home/container$ ${MODIFIED_STARTUP}"
# Run the Server # Run the Server
eval ${MODIFIED_STARTUP} eval ${MODIFIED_STARTUP}

View File

@@ -33,24 +33,24 @@ function RunSteamCMD { #[Input: int server=0 mod=1 optional_mod=2; int id]
if [[ -f "${STEAMCMD_LOG}" ]]; then if [[ -f "${STEAMCMD_LOG}" ]]; then
rm -f "${STEAMCMD_LOG:?}" rm -f "${STEAMCMD_LOG:?}"
fi fi
updateAttempt=0 updateAttempt=0
while (( $updateAttempt < $STEAMCMD_ATTEMPTS )); do # Loop for specified number of attempts while (( $updateAttempt < $STEAMCMD_ATTEMPTS )); do # Loop for specified number of attempts
# Increment attempt counter # Increment attempt counter
updateAttempt=$((updateAttempt+1)) updateAttempt=$((updateAttempt+1))
if (( $updateAttempt > 1 )); then # Notify if not first attempt if (( $updateAttempt > 1 )); then # Notify if not first attempt
echo -e "\t${YELLOW}Re-Attempting download/update in 3 seconds...${NC} (Attempt ${CYAN}${updateAttempt}${NC} of ${CYAN}${STEAMCMD_ATTEMPTS}${NC})\n" echo -e "\t${YELLOW}Re-Attempting download/update in 3 seconds...${NC} (Attempt ${CYAN}${updateAttempt}${NC} of ${CYAN}${STEAMCMD_ATTEMPTS}${NC})\n"
sleep 3 sleep 3
fi fi
# Check if updating server or mod # Check if updating server or mod
if [[ $1 == 0 ]]; then # Server if [[ $1 == 0 ]]; then # Server
${STEAMCMD_DIR}/steamcmd.sh +force_install_dir /home/container "+login \"${STEAM_USER}\" \"${STEAM_PASS}\"" +app_update $2 $extraFlags $validateServer +quit | tee -a "${STEAMCMD_LOG}" ${STEAMCMD_DIR}/steamcmd.sh +force_install_dir /home/container "+login \"${STEAM_USER}\" \"${STEAM_PASS}\"" +app_update $2 $extraFlags $validateServer +quit | tee -a "${STEAMCMD_LOG}"
else # Mod else # Mod
${STEAMCMD_DIR}/steamcmd.sh "+login \"${STEAM_USER}\" \"${STEAM_PASS}\"" +workshop_download_item $GAME_ID $2 +quit | tee -a "${STEAMCMD_LOG}" ${STEAMCMD_DIR}/steamcmd.sh "+login \"${STEAM_USER}\" \"${STEAM_PASS}\"" +workshop_download_item $GAME_ID $2 +quit | tee -a "${STEAMCMD_LOG}"
fi fi
# Error checking for SteamCMD # Error checking for SteamCMD
steamcmdExitCode=${PIPESTATUS[0]} steamcmdExitCode=${PIPESTATUS[0]}
if [[ -n $(grep -i "error\|failed" "${STEAMCMD_LOG}" | grep -iv "setlocal\|SDL") ]]; then # Catch errors (ignore setlocale and SDL warnings) if [[ -n $(grep -i "error\|failed" "${STEAMCMD_LOG}" | grep -iv "setlocal\|SDL") ]]; then # Catch errors (ignore setlocale and SDL warnings)
@@ -166,6 +166,11 @@ function RemoveDuplicates { #[Input: str - Output: printf of new str]
} }
# === ENTRYPOINT START === # === ENTRYPOINT START ===
# Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
cd /home/container cd /home/container
sleep 1 sleep 1
@@ -213,17 +218,17 @@ allMods=$(echo $allMods | sed -e 's/;/ /g') # Convert from string to array
if [[ ${UPDATE_SERVER} == 1 ]]; then if [[ ${UPDATE_SERVER} == 1 ]]; then
echo -e "\n${GREEN}[STARTUP]: ${CYAN}Starting checks for all updates...${NC}" echo -e "\n${GREEN}[STARTUP]: ${CYAN}Starting checks for all updates...${NC}"
echo -e "(It is okay to ignore any \"SDL\" errors during this process)\n" echo -e "(It is okay to ignore any \"SDL\" errors during this process)\n"
## Update game server ## Update game server
echo -e "${GREEN}[UPDATE]:${NC} Checking for game server updates with App ID: ${CYAN}${STEAMCMD_APPID}${NC}..." echo -e "${GREEN}[UPDATE]:${NC} Checking for game server updates with App ID: ${CYAN}${STEAMCMD_APPID}${NC}..."
if [[ ${VALIDATE_SERVER} == 1 ]]; then # Validate will be added as a parameter if specified if [[ ${VALIDATE_SERVER} == 1 ]]; then # Validate will be added as a parameter if specified
echo -e "\t${CYAN}File validation enabled.${NC} (This may take extra time to complete)" echo -e "\t${CYAN}File validation enabled.${NC} (This may take extra time to complete)"
validateServer="validate" validateServer="validate"
else else
validateServer="" validateServer=""
fi fi
# Determine what extra flags should be set # Determine what extra flags should be set
if [[ -n ${STEAMCMD_EXTRA_FLAGS} ]]; then if [[ -n ${STEAMCMD_EXTRA_FLAGS} ]]; then
echo -e "\t(${YELLOW}Advanced${NC}) Extra SteamCMD flags specified: ${CYAN}${STEAMCMD_EXTRA_FLAGS}${NC}\n" echo -e "\t(${YELLOW}Advanced${NC}) Extra SteamCMD flags specified: ${CYAN}${STEAMCMD_EXTRA_FLAGS}${NC}\n"
@@ -235,9 +240,9 @@ if [[ ${UPDATE_SERVER} == 1 ]]; then
echo -e "" echo -e ""
extraFlags="" extraFlags=""
fi fi
RunSteamCMD 0 ${STEAMCMD_APPID} RunSteamCMD 0 ${STEAMCMD_APPID}
## Update mods ## Update mods
if [[ -n $allMods ]] && [[ ${DISABLE_MOD_UPDATES} != 1 ]]; then if [[ -n $allMods ]] && [[ ${DISABLE_MOD_UPDATES} != 1 ]]; then
echo -e "\n${GREEN}[UPDATE]:${NC} Checking all ${CYAN}Steam Workshop mods${NC} for updates..." echo -e "\n${GREEN}[UPDATE]:${NC} Checking all ${CYAN}Steam Workshop mods${NC} for updates..."
@@ -274,7 +279,7 @@ if [[ ${UPDATE_SERVER} == 1 ]]; then
echo -e "\tMod was last updated: ${CYAN}$(date -d @${latestUpdate})${NC}" echo -e "\tMod was last updated: ${CYAN}$(date -d @${latestUpdate})${NC}"
fi fi
echo -e "\tAttempting mod update/download via SteamCMD...\n" echo -e "\tAttempting mod update/download via SteamCMD...\n"
RunSteamCMD $modType $modID RunSteamCMD $modType $modID
fi fi
fi fi
@@ -298,7 +303,7 @@ if [[ ${UPDATE_SERVER} == 1 ]]; then
if [[ "${CLIENT_MODS}" != *"@${modID};"* ]]; then if [[ "${CLIENT_MODS}" != *"@${modID};"* ]]; then
echo -e "\tKey file and directory for unconfigured optional mod ${CYAN}${modID}${NC} is being deleted..." echo -e "\tKey file and directory for unconfigured optional mod ${CYAN}${modID}${NC} is being deleted..."
fi fi
# Delete the optional mod .bikey file and directory # Delete the optional mod .bikey file and directory
rm ${keyFile} rm ${keyFile}
rmdir ./@${modID}_optional 2> /dev/null rmdir ./@${modID}_optional 2> /dev/null

View File

@@ -30,7 +30,7 @@ TZ=${TZ:-UTC}
export TZ export TZ
# Set environment variable that holds the Internal Docker IP # Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $NF;exit}') INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP export INTERNAL_IP
# Switch to the container's working directory # Switch to the container's working directory

View File

@@ -20,14 +20,14 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
# #
# Default the TZ environment variable to UTC. # Default the TZ environment variable to UTC.
TZ=${TZ:-UTC} TZ=${TZ:-UTC}
export TZ export TZ
# Set environment variable that holds the Internal Docker IP # Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $NF;exit}') INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP export INTERNAL_IP
# Switch to the container's working directory # Switch to the container's working directory

View File

@@ -27,7 +27,7 @@ TZ=${TZ:-UTC}
export TZ export TZ
# Set environment variable that holds the Internal Docker IP # Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $NF;exit}') INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP export INTERNAL_IP
# Switch to the container's working directory # Switch to the container's working directory

View File

@@ -2,7 +2,8 @@
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g') MODIFIED_STARTUP=$(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')

View File

@@ -2,7 +2,8 @@
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g') MODIFIED_STARTUP=$(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')

View File

@@ -2,7 +2,8 @@
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP="eval $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')" MODIFIED_STARTUP="eval $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')"

View File

@@ -2,7 +2,8 @@
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Print Node.js Version # Print Node.js Version
node -v node -v

View File

@@ -18,14 +18,14 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
# #
# Default the TZ environment variable to UTC. # Default the TZ environment variable to UTC.
TZ=${TZ:-UTC} TZ=${TZ:-UTC}
export TZ export TZ
# Set environment variable that holds the Internal Docker IP # Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $NF;exit}') INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP export INTERNAL_IP
# Switch to the container's working directory # Switch to the container's working directory

View File

@@ -1,12 +1,13 @@
#!/bin/bash #!/bin/bash
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g') MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
echo -e ":/home/container$ ${MODIFIED_STARTUP}" echo -e ":/home/container$ ${MODIFIED_STARTUP}"
# Run the Server # Run the Server
eval ${MODIFIED_STARTUP} eval ${MODIFIED_STARTUP}

View File

@@ -2,11 +2,12 @@
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g') MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
echo -e ":/home/container$ ${MODIFIED_STARTUP}" echo -e ":/home/container$ ${MODIFIED_STARTUP}"
# Run the Server # Run the Server
eval ${MODIFIED_STARTUP} eval ${MODIFIED_STARTUP}

View File

@@ -5,7 +5,8 @@ cd /home/container
postgres --version postgres --version
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')` MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')`

View File

@@ -2,7 +2,8 @@
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Print current Python version # Print current Python version
python --version python --version

View File

@@ -2,7 +2,8 @@
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Replace Startup Variables # Replace Startup Variables
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g') MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')

View File

@@ -2,7 +2,8 @@
cd /home/container cd /home/container
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
# Print current Rust version # Print current Rust version
cargo --version cargo --version

View File

@@ -3,7 +3,7 @@ TZ=${TZ:-UTC}
export TZ export TZ
# Set environment variable that holds the Internal Docker IP # Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $NF;exit}') INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP export INTERNAL_IP
# Switch to the container's working directory # Switch to the container's working directory

View File

@@ -7,7 +7,8 @@ echo "Current timezone: $(cat /etc/timezone)"
wine --version wine --version
# Make internal Docker IP address available to processes. # Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'` INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP
## just in case someone removed the defaults. ## just in case someone removed the defaults.
if [ "${STEAM_USER}" == "" ]; then if [ "${STEAM_USER}" == "" ]; then