Teh Pizza Lady Posted January 12, 2025 Report Posted January 12, 2025 installMod.sh #!/bin/bash # Function to download a file function download_file() { read -p "Enter the URL of the mod to install: " url # Extract the filename from the URL using curl filename=$(curl -sI "$url" | grep -o -E 'filename="?([^";]+)"?' | sed 's/filename=\"\?//' | sed 's/\"$//') # If the filename is not extracted, fallback to the URL's last component if [ -z "$filename" ]; then filename=$(basename "$url") fi # Create the mods directory if it doesn't exist mkdir -p ./Mods # Download the file to the mods directory echo "Downloading $filename . . ." curl -L -o "./Mods/$filename" "$url" if [ $? -eq 0 ]; then echo "Download of $filename is complete!" else echo "Download failed. Please check the URL and try again." fi } # Main script loop while true; do # Prompt for downloading a file download_file # Prompt for next action echo "What would you like to do next?" echo "1. Restart the process" echo "2. Download another file" echo "3. Exit" read -p "Enter your choice (1/2/3): " choice case $choice in 1) echo "Restarting the Vintage Story server..." ./server.sh restart echo "Server successfully restarted! Exiting the script. Goodbye!" break ;; 2) echo "Preparing to download another file..." ;; 3) echo "Exiting the script. Goodbye!" break ;; *) echo "Invalid choice. Please enter 1, 2, or 3." ;; esac done updateServer.sh #!/bin/bash # Check if a URL was provided if [ -z "$1" ]; then echo "Usage: $0 <URL>" exit 1 fi URL="$1" OUTPUT_FILE="vs.tar.gz" ASSETS_DIR="assets" # First backup server.sh file mv server.sh server.sh.old # Download the contents of the URL into vs.tar.gz curl -o "$OUTPUT_FILE" "$URL" # Check if the download was successful if [ $? -ne 0 ]; then echo "Error: Failed to download $URL" exit 1 fi # Remove the local assets folder if it exists if [ -d "$ASSETS_DIR" ]; then rm -rf "$ASSETS_DIR" echo "Deleted existing $ASSETS_DIR folder." fi # Unpack vs.tar.gz into the current directory # Overwriting all contents if necessary tar -xzf "$OUTPUT_FILE" --overwrite # Check if the extraction was successful if [ $? -ne 0 ]; then echo "Error: Failed to extract $OUTPUT_FILE" exit 1 fi # Restore server.sh file rm server.sh mv server.sh.old server.sh # Notify completion echo "Successfully downloaded and updated Vintage Story."
Teh Pizza Lady Posted January 13, 2025 Author Report Posted January 13, 2025 These are scripts I've created to make managing my server easier. I hope everyone can make use of them and provide the Windows versions that do the same thing?
Teh Pizza Lady Posted January 14, 2025 Author Report Posted January 14, 2025 Also if anyone knows how to improve the update script to automatically pull the latest (stable or unstable) version, that would be cool.
Recommended Posts