Files
autorun-steam-game/run.sh
2026-02-11 13:32:09 +00:00

34 lines
1.0 KiB
Bash

#!/bin/bash
if [ -f .env ]; then
set -a
source .env
set +a
fi
FULL_URL=https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2
if pgrep -fa "AppId=$STEAM_RUNGAMEID" > /dev/null; then
echo "[automate steam] detected playing: $STEAM_RUNGAMEID on this device. skipping"
exit 0
fi
RESPONSE=$(curl -s "$FULL_URL/?key=$STEAM_KEY&steamids=$STEAM_USERID64")
if ! echo "$RESPONSE" | jq empty 2>/dev/null; then
echo "Error response from API: $RESPONSE"
exit 1
fi
APPID=$(echo $RESPONSE | jq -r '.response.players[0].gameid')
if [ "$APPID" != "null" ] && [ -n "$APPID" ]; then
if pgrep -f steam > /dev/null && ! pgrep -fa "AppId=$APPID" > /dev/null; then
# If not playing on CURRENT DEVICE but DETECTED PLAYING ON ACCOUNT
echo "[automate steam] detected playing: $APPID ON OTHER DEVICE. quitting"
steam steam://exit &
fi
else
echo "[automate steam] not playing anything on any device, running game..."
steam -cef-disable-gpu steam://rungameid/$STEAM_RUNGAMEID &
fi