Skip to content

Commit

Permalink
fix: invalid INTERNAL_IP environment value
Browse files Browse the repository at this point in the history
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
  • Loading branch information
trenutoo committed Apr 24, 2022
1 parent 9f02fe1 commit cd6b949
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 48 deletions.
5 changes: 3 additions & 2 deletions bot/bastion/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
cd /home/container

# Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'`
# Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP

# Replace Startup Variables
MODIFIED_STARTUP=$(echo -e $(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g'))
Expand Down
5 changes: 3 additions & 2 deletions bot/parkertron/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/ash
cd /home/container

# Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'`
# Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP

# Replace Startup Variables
MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')`
Expand Down
7 changes: 4 additions & 3 deletions bot/red/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
cd /home/container

# Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'`
# Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP

# Replace Startup Variables
MODIFIED_STARTUP=$(echo -e $(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g'))
echo -e ":/home/container$ ${MODIFIED_STARTUP}"

# Run the Server
eval ${MODIFIED_STARTUP}
eval ${MODIFIED_STARTUP}
5 changes: 3 additions & 2 deletions bot/sinusbot/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
cd /home/container

# Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'`
# Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP

# Replace Startup Variables
MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')`
Expand Down
2 changes: 1 addition & 1 deletion cassandra/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TZ=${TZ:-UTC}
export TZ

# 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

# Switch to the container's working directory
Expand Down
5 changes: 3 additions & 2 deletions dotnet/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
cd /home/container

# Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'`
# Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP

# Replace Startup Variables
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
Expand Down
2 changes: 1 addition & 1 deletion erlang/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TZ=${TZ:-UTC}
export TZ

# 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

# Switch to the container's working directory
Expand Down
7 changes: 4 additions & 3 deletions games/altv/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
cd /home/container

# Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'`
# Set environment variable that holds the Internal Docker IP
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP

# Replace Startup Variables
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
echo -e ":/home/container$ ${MODIFIED_STARTUP}"

# Run the Server
eval ${MODIFIED_STARTUP}
eval ${MODIFIED_STARTUP}
27 changes: 16 additions & 11 deletions games/arma3/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ function RunSteamCMD { #[Input: int server=0 mod=1 optional_mod=2; int id]
if [[ -f "${STEAMCMD_LOG}" ]]; then
rm -f "${STEAMCMD_LOG:?}"
fi

updateAttempt=0
while (( $updateAttempt < $STEAMCMD_ATTEMPTS )); do # Loop for specified number of attempts
# Increment attempt counter
updateAttempt=$((updateAttempt+1))

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"
sleep 3
fi

# Check if updating server or mod
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}"
else # Mod
${STEAMCMD_DIR}/steamcmd.sh "+login \"${STEAM_USER}\" \"${STEAM_PASS}\"" +workshop_download_item $GAME_ID $2 +quit | tee -a "${STEAMCMD_LOG}"
fi

# Error checking for SteamCMD
steamcmdExitCode=${PIPESTATUS[0]}
if [[ -n $(grep -i "error\|failed" "${STEAMCMD_LOG}" | grep -iv "setlocal\|SDL") ]]; then # Catch errors (ignore setlocale and SDL warnings)
Expand Down Expand Up @@ -166,6 +166,11 @@ function RemoveDuplicates { #[Input: str - Output: printf of new str]
}

# === 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
sleep 1

Expand Down Expand Up @@ -213,17 +218,17 @@ allMods=$(echo $allMods | sed -e 's/;/ /g') # Convert from string to array
if [[ ${UPDATE_SERVER} == 1 ]]; then
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"

## Update game server
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
echo -e "\t${CYAN}File validation enabled.${NC} (This may take extra time to complete)"
validateServer="validate"
else
validateServer=""
fi

# Determine what extra flags should be set
if [[ -n ${STEAMCMD_EXTRA_FLAGS} ]]; then
echo -e "\t(${YELLOW}Advanced${NC}) Extra SteamCMD flags specified: ${CYAN}${STEAMCMD_EXTRA_FLAGS}${NC}\n"
Expand All @@ -235,9 +240,9 @@ if [[ ${UPDATE_SERVER} == 1 ]]; then
echo -e ""
extraFlags=""
fi

RunSteamCMD 0 ${STEAMCMD_APPID}

## Update mods
if [[ -n $allMods ]] && [[ ${DISABLE_MOD_UPDATES} != 1 ]]; then
echo -e "\n${GREEN}[UPDATE]:${NC} Checking all ${CYAN}Steam Workshop mods${NC} for updates..."
Expand Down Expand Up @@ -274,7 +279,7 @@ if [[ ${UPDATE_SERVER} == 1 ]]; then
echo -e "\tMod was last updated: ${CYAN}$(date -d @${latestUpdate})${NC}"
fi
echo -e "\tAttempting mod update/download via SteamCMD...\n"

RunSteamCMD $modType $modID
fi
fi
Expand All @@ -298,7 +303,7 @@ if [[ ${UPDATE_SERVER} == 1 ]]; then
if [[ "${CLIENT_MODS}" != *"@${modID};"* ]]; then
echo -e "\tKey file and directory for unconfigured optional mod ${CYAN}${modID}${NC} is being deleted..."
fi

# Delete the optional mod .bikey file and directory
rm ${keyFile}
rmdir ./@${modID}_optional 2> /dev/null
Expand Down
2 changes: 1 addition & 1 deletion games/source/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TZ=${TZ:-UTC}
export TZ

# 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

# Switch to the container's working directory
Expand Down
4 changes: 2 additions & 2 deletions go/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
# 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
# SOFTWARE.
#
#

# Default the TZ environment variable to UTC.
TZ=${TZ:-UTC}
export TZ

# 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

# Switch to the container's working directory
Expand Down
2 changes: 1 addition & 1 deletion java/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TZ=${TZ:-UTC}
export TZ

# 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

# Switch to the container's working directory
Expand Down
3 changes: 2 additions & 1 deletion mariadb/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
cd /home/container

# 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
MODIFIED_STARTUP=$(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
Expand Down
3 changes: 2 additions & 1 deletion mongodb/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
cd /home/container

# 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
MODIFIED_STARTUP=$(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
Expand Down
3 changes: 2 additions & 1 deletion mono/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
cd /home/container

# 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
MODIFIED_STARTUP="eval $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')"
Expand Down
3 changes: 2 additions & 1 deletion nodejs/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
cd /home/container

# 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
node -v
Expand Down
4 changes: 2 additions & 2 deletions oses/alpine/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
# 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
# SOFTWARE.
#
#

# Default the TZ environment variable to UTC.
TZ=${TZ:-UTC}
export TZ

# 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

# Switch to the container's working directory
Expand Down
7 changes: 4 additions & 3 deletions oses/debian/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
cd /home/container

# Make internal Docker IP address available to processes.
export INTERNAL_IP=`ip route get 1 | awk '{print $NF;exit}'`
# Make internal Docker IP address available to processes.
INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')
export INTERNAL_IP

# Replace Startup Variables
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
echo -e ":/home/container$ ${MODIFIED_STARTUP}"

# Run the Server
eval ${MODIFIED_STARTUP}
eval ${MODIFIED_STARTUP}
5 changes: 3 additions & 2 deletions oses/ubuntu/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
cd /home/container

# 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
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
echo -e ":/home/container$ ${MODIFIED_STARTUP}"

# Run the Server
eval ${MODIFIED_STARTUP}
eval ${MODIFIED_STARTUP}
3 changes: 2 additions & 1 deletion postgres/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ cd /home/container
postgres --version

# 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
MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')`
Expand Down
3 changes: 2 additions & 1 deletion python/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
cd /home/container

# 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
python --version
Expand Down
3 changes: 2 additions & 1 deletion redis/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
cd /home/container

# 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
MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
Expand Down
3 changes: 2 additions & 1 deletion rust/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
cd /home/container

# 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
cargo --version
Expand Down
2 changes: 1 addition & 1 deletion voice/teaspeak/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TZ=${TZ:-UTC}
export TZ

# 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

# Switch to the container's working directory
Expand Down
3 changes: 2 additions & 1 deletion wine/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ echo "Current timezone: $(cat /etc/timezone)"
wine --version

# 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.
if [ "${STEAM_USER}" == "" ]; then
Expand Down

0 comments on commit cd6b949

Please sign in to comment.