#!/bin/bash

# Path to the SteamCMD executable
STEAMCMD_PATH="/home/steam/.steam/steamcmd.sh"

# SteamCMD login details (replace with your own)
STEAM_USERNAME="user"
STEAM_PASSWORD="password"

# Path to the text file containing workshop IDs (one ID per line)
WORKSHOP_IDS_FILE="/path/to/workshop_ids.txt"

# Path to the directory where you want to install the workshop items
#mods will be in $INSTALL_DIR/steamapps/workshop/content/$APP_ID/$workshop_id/
INSTALL_DIR="/home/steam/.steam/"

# AppID for the game (replace with the appropriate AppID)
APP_ID="730"  # 730 is the AppID for Counter-Strike: Global Offensive

# Ensure the SteamCMD executable exists
if [ ! -f "$STEAMCMD_PATH" ]; then
    echo "Error: SteamCMD not found at $STEAMCMD_PATH. Please provide the correct path."
    exit 1
fi

# Loop through each workshop ID in the file
while IFS= read -r workshop_id || [ -n "$workshop_id" ]; do
    # Run SteamCMD to install the workshop item
    # Uncomment for user login
    #"$STEAMCMD_PATH" +force_install_dir "$INSTALL_DIR" +login "$STEAM_USERNAME" "$STEAM_PASSWORD" +workshop_download_item "$APP_ID" "$workshop_id" +quit
    #Anon login
    "$STEAMCMD_PATH" +force_install_dir "$INSTALL_DIR" +login anonymous +workshop_download_item "$APP_ID" "$workshop_id" +quit
    
    # Move the downloaded item to the desired installation directory
    # Don't do this, link to the mod dir with ln -s instead'
    # It's easier to keep mods updated this way'
    # mv -f "$INSTALL_DIR/steamapps/workshop/content/$APP_ID/$workshop_id/" "$INSTALL_DIR"
    


    echo
    echo
    echo
    echo "Installed workshop item with ID $workshop_id"
    echo
    
    #Rate Limit fix
    sleep 5
done < "$WORKSHOP_IDS_FILE"



echo "Installation complete."


exit