Skip to content

Commit

Permalink
refactor: polish startup script
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyphysgun committed Feb 7, 2024
1 parent af011cc commit c5f4ca1
Showing 1 changed file with 44 additions and 62 deletions.
106 changes: 44 additions & 62 deletions games/rust/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,86 +1,68 @@
#!/bin/bash
cd /home/container

export INTERNAL_IP=`ip route get 1 | awk '{print $(NF-2);exit}'`
# Custom logging function with color output
log() {
echo -e "\u001b[34m[PhysgunEntry] \u001b[36m$1"
}

export INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}')

if [ -z ${AUTO_UPDATE} ] || [ "${AUTO_UPDATE}" == "1" ]; then
./steamcmd/steamcmd.sh +force_install_dir /home/container +login anonymous +app_update 258550 +quit
# Handle auto-update logic
if [ -z "${AUTO_UPDATE}" ] || [ "${AUTO_UPDATE}" == "1" ]; then
./steamcmd/steamcmd.sh +force_install_dir /home/container +login anonymous +app_update 258550 +quit
else
echo -e "Not updating game server as auto update was set to 0. Starting Server"
log "Auto-update disabled. Starting Server without updating."
fi

MODIFIED_STARTUP=`eval echo $(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')`
# Process the startup command with dynamic variables
MODIFIED_STARTUP=$(eval echo $(echo "${STARTUP}" | sed -e 's/{{/${/g' -e 's/}}/}/g'))

echo "Starting Physgun Rust Server"
echo "Startup Command - ${MODIFIED_STARTUP}"
log "Starting Physgun Rust Server with Command - ${MODIFIED_STARTUP}"

# Framework specific operations
if [[ "${FRAMEWORK}" == "carbon" ]]; then
echo "Updating Carbon..."
log "Updating Carbon..."
curl -sSL "https://github.com/CarbonCommunity/Carbon.Core/releases/download/production_build/Carbon.Linux.Release.tar.gz" | tar zx
echo "Done updating Carbon!"

log "Carbon update complete!"
export DOORSTOP_ENABLED=1
export DOORSTOP_TARGET_ASSEMBLY="$(pwd)/carbon/managed/Carbon.Preloader.dll"
MODIFIED_STARTUP="LD_PRELOAD=$(pwd)/libdoorstop.so ${MODIFIED_STARTUP}"

elif [[ "$OXIDE" == "1" ]] || [[ "${FRAMEWORK}" == "oxide" ]]; then
echo "Installing Oxide..."
MODIFIED_STARTUP="LD_PRELOAD=$(pwd)/libdoorstop.so $MODIFIED_STARTUP"
elif [[ "${FRAMEWORK}" == "oxide" ]] || [[ "$OXIDE" == "1" ]]; then
log "Installing Oxide..."
curl -sSL "https://github.com/OxideMod/Oxide.Rust/releases/latest/download/Oxide.Rust-linux.zip" > umod.zip
unzip -o -q umod.zip
rm umod.zip
echo "Done Installing Oxide!"
unzip -o -q umod.zip && rm umod.zip
log "Oxide installation complete!"
fi

OLD_DIR=$(pwd)
cd /tmp

download_extension() {
local url=$1
local file=$2
local name=$3
if [ "${!name}" == "1" ]; then
curl -SSL -o "${file}" "${url}"
mv "${file}" /home/container/RustDedicated_Data/Managed
echo -e "Updated ${file}\n"
fi
if [ "${!3}" == "1" ]; then
curl -sSL -o "/home/container/RustDedicated_Data/Managed/$2" "$1"
log "Updated $2"
fi
}

if [ "${DISCORD_EXT}" == "1" ]; then
download_extension "https://umod.org/extensions/discord/download" "Oxide.Ext.Discord.dll" "DISCORD_EXT"
fi

if [ "${RUST_EDIT}" == "1" ]; then
download_extension "https://umod.org/extensions/rustedit/download" "Oxide.Ext.RustEdit.dll" "RUST_EDIT"
fi

if [ "${CHAOS_EXT}" == "1" ]; then
download_extension "https://chaoscode.io/oxide/Oxide.Ext.Chaos.dll" "Oxide.Ext.Chaos.dll" "CHAOS_EXT"
fi

if [ "${CHAOS_NPC}" == "1" ]; then
download_extension "https://chaoscode.io/oxide/Oxide.Ext.ChaosNPC.dll" "Oxide.Ext.ChaosNPC.dll" "CHAOS_NPC"
fi

cd "$OLD_DIR"

if [ -z ${OWNERID} ] || [ "${OWNERID}" == "null" ]; then
echo "OwnerID not set - Not writing to users.cfg"
# Download extensions if enabled
download_extension "https://umod.org/extensions/discord/download" "Oxide.Ext.Discord.dll" "DISCORD_EXT"
download_extension "https://umod.org/extensions/rustedit/download" "Oxide.Ext.RustEdit.dll" "RUST_EDIT"
download_extension "https://chaoscode.io/oxide/Oxide.Ext.Chaos.dll" "Oxide.Ext.Chaos.dll" "CHAOS_EXT"
download_extension "https://chaoscode.io/oxide/Oxide.Ext.ChaosNPC.dll" "Oxide.Ext.ChaosNPC.dll" "CHAOS_NPC"

# Handle server owner configuration
if [ ! -z "${OWNERID}" ] && [ "${OWNERID}" != "null" ]; then
mkdir -p /home/container/server/rust/cfg
file_path="/home/container/server/rust/cfg/users.cfg"
content="ownerid ${OWNERID} \"rustadmin\" \"rustadmin\""
if ! grep -qF "$content" "$file_path"; then
echo "$content" >> "$file_path"
log "OwnerID set in users.cfg"
fi
else
mkdir -p /home/container/server/rust/cfg
file_path="/home/container/server/rust/cfg/users.cfg"
content="ownerid ${OWNERID} \"rustadmin\" \"rustadmin\""

if [ ! -f "$file_path" ]; then
echo "$content" > "$file_path"
else
if ! grep -qF "$content" "$file_path"; then
echo "$content" >> "$file_path"
fi
fi
log "OwnerID not set or null. Skipping users.cfg update."
fi

# Fix for Rust not starting
# Fix for Rust not starting due to missing library path
export LD_LIBRARY_PATH=$(pwd)/RustDedicated_Data/Plugins/x86_64:$(pwd)

# Run the Server
node /wrapper.js "${MODIFIED_STARTUP}"
# Execute the server startup command
node /wrapper.js "$MODIFIED_STARTUP"

0 comments on commit c5f4ca1

Please sign in to comment.