#!/bin/bash if [ ! -z "$1" ]; then ferium add $1 if [ $? -ne 0 ]; then exit $? fi fi SERVER_DATA_PATH="./data/" CONTAINER_NAME="minecraft" LOG_LINES_CHECK=20 #echo "Stopping container..." if podman ps --filter "name=minecraft" --format "{{.Names}}" | grep -q "minecraft"; then podman-compose --podman-stop-args="-t 15" down # just in case "$CONTAINER_NAME" wasn't the container name... if [ $? -ne 0 ]; then exit $? fi echo "Container stopped" else echo "Container '$CONTAINER_NAME' not found, continuing." fi THIS_DIR="$PWD" cd $SERVER_DATA_PATH echo "Performing upgrade..." sleep 2 # Function to upgrade ferium and copy mods upgrade_mods() { #rm -f mods/staging/*.jar && ferium upgrade && echo "Cleaning mod directories..." && rm -f mods/server/*.jar && rm -f mods/client/*.jar && echo "Copying new mod files..." cp mods/staging/*.jar mods/server/ && cp mods/staging/*.jar mods/client/ && #echo "Adjusting ownership..." chown -R $USER:$USER mods/* chmod -R 755 mods/* } remove_clientside_mod() { local mod_name="$1" find $SERVER_DATA_PATH/mods/server/ -maxdepth 1 -iname "*${mod_name}*.jar" -exec rm {} \; if [ $? -eq 0 ]; then echo "Removed non-server mod: $mod_name" else echo "Client-side mod '$mod_name' not found (OK)" fi } # Call the functions upgrade_mods # Loop through clientside mods and remove them serverside cd $THIS_DIR # Go back to compose dir while IFS= read -r mod; do remove_clientside_mod "$mod" done < "./client-only-mods.list" echo "Starting container" podman-compose up -d echo "" echo "Monitoring startup for 10 seconds..." start_time=$(date +%s) timeout=8 crashed=0 sleep 2 while true; do if podman logs $CONTAINER_NAME | tail -n $LOG_LINES_CHECK | grep "server failed"; then crashed=1 break fi # Check if 5 seconds have passed current_time=$(date +%s) if [[ $(($current_time - $start_time)) -ge $timeout ]]; then break fi # Sleep briefly to avoid tight loop sleep 1 done if [ $crashed == 1 ]; then echo "--------------------------------------------------------------------" podman logs $CONTAINER_NAME | tail -n $LOG_LINES_CHECK else echo "All seems OK for now." fi