277 lines
7.0 KiB
Bash
277 lines
7.0 KiB
Bash
#!/bin/bash
|
|
## Copyright © 2018 Bret Human
|
|
## https://cynicaloptimist.me/
|
|
##
|
|
## Documentation at:
|
|
## https://mage.cynicaloptimist.me/en/st34m
|
|
## https://psi.cynicaloptimist.me/Caffarius/st34m/
|
|
##
|
|
## For questions or comments write:
|
|
## info@cynicaloptimist.me
|
|
#####################################################################
|
|
# st34m-run
|
|
script_ver="1.0.1"
|
|
# https://mage.cynicaloptimist.me/en/st34m
|
|
# author: Bret Human
|
|
# date: Dec 10, 2018
|
|
#
|
|
#####################################################################
|
|
#
|
|
# A wrapper for wrappers, used to manage/own a Steam installation in
|
|
# a Linux environment.
|
|
#
|
|
# This is the second script in the line, fired off by st34m. This
|
|
# script handles conditionals for safely running Steam or
|
|
# most of its apps. The syntax makes it easily modular.
|
|
#
|
|
# If you want to add a game, search for "function game_on".
|
|
#
|
|
#####################################################################
|
|
#
|
|
# This is free software; you are free to change and redistribute it.
|
|
# There is NO WARRANTY of any kind.
|
|
#
|
|
#####################################################################
|
|
|
|
runas_user="`whoami`"
|
|
app_name="Steam"
|
|
app_dir="/usr/bin/"
|
|
app_cmd="steam-native"
|
|
console="bash"
|
|
usage="st34m-run, version ${script_ver}
|
|
Usage: ./`basename ${0}` -g (game) -dvptch
|
|
-g | Launches the game of your choice
|
|
-d | Debug messages on (turns verbose on)
|
|
-v | Verbose messages on
|
|
-p | Runs protontricks
|
|
-t | Attempts to launch to the system tray
|
|
-c | Launch a console session as specified user (can launch Xapps)
|
|
-r | Use steam-runtime instead of steam-native
|
|
-h | Help (this message)"
|
|
|
|
# Catch CTRL+C and cleanup
|
|
trap "echo '' && inform '---------------------------------' && inform 'Caught CTRL+C' && warp 2" 2
|
|
|
|
## Set default environment
|
|
cd /home/"${runas_user}"
|
|
export HOME="/home/${runas_user}"
|
|
export USER="${runas_user}"
|
|
export USERNAME="${runas_user}"
|
|
export LOGNAME="${runas_user}"
|
|
export WINEDEBUG=-all
|
|
export XAUTHORITY="/home/${runas_user}/.Xauthority"
|
|
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin"
|
|
unset OLDPWD
|
|
unset SUDO_GID
|
|
unset SUDO_COMMAND
|
|
unset SUDO_USER
|
|
unset SUDO_UID
|
|
STEAM_FRAME_FORCE_CLOSE=1
|
|
|
|
## Define our functions
|
|
function debug () {
|
|
if [ ! "${WINEDEBUG}" ]; then
|
|
echo "-d- ${1}"
|
|
fi
|
|
}
|
|
|
|
function inform () {
|
|
if [ "${app_verbose}" ]; then
|
|
echo "--- ${1}"
|
|
fi
|
|
}
|
|
|
|
function clean {
|
|
debug "clean"
|
|
|
|
# Var
|
|
unset script_ver
|
|
unset runas_user
|
|
unset app_name
|
|
unset app_dir
|
|
unset app_cmd
|
|
unset app_verbose
|
|
unset app_proton
|
|
unset console
|
|
unset usage
|
|
unset WINEDEBUG
|
|
unset STEAM_FRAME_FORCE_CLOSE
|
|
unset game_launch
|
|
unset game_name
|
|
unset game_id
|
|
unset nobs_mode
|
|
unset to_tray
|
|
|
|
|
|
# Func
|
|
unset debug
|
|
unset inform
|
|
unset game_on
|
|
}
|
|
|
|
function warp () {
|
|
debug "warp" # exit the dungeon
|
|
inform "Cleaning up ${runas_user}-side..."
|
|
clean
|
|
unset clean
|
|
|
|
if [ "$1" ]; then
|
|
unset warp && exit $1
|
|
else
|
|
echo "...what...?"
|
|
unset warp && exit 5
|
|
fi
|
|
}
|
|
|
|
function game_on {
|
|
debug "game_on"
|
|
case "${game_launch}" in
|
|
test)
|
|
echo "glxgears!"
|
|
if [ "`which glxgears`" ]; then
|
|
glxgears
|
|
warp 0
|
|
else
|
|
echo "glxgears is not installed, or I can't find it in PATH"
|
|
warp 1
|
|
fi
|
|
;;
|
|
507490|ashes)
|
|
game_name="Ashes of the Singularity: Escalation"
|
|
game_id="507490"
|
|
;;
|
|
289070|civ6)
|
|
game_name="Civilization VI"
|
|
game_id="289070"
|
|
;;
|
|
65980|civbe)
|
|
game_name="Civilization: Beyond Earth"
|
|
game_id="65980"
|
|
;;
|
|
278080|dw8)
|
|
game_name="Dynasty Warriors 8"
|
|
game_id="278080"
|
|
;;
|
|
359320|elite)
|
|
game_name="Elite Dangerous"
|
|
game_id="359320"
|
|
;;
|
|
377160|fo4)
|
|
game_name="Fallout 4"
|
|
game_id="377160"
|
|
;;
|
|
244160|hw)
|
|
game_name="Homeworld Remastered"
|
|
game_id="244160"
|
|
;;
|
|
342200|mwo)
|
|
game_name="MechWarrior Online"
|
|
game_id="342200"
|
|
;;
|
|
204880|sins)
|
|
game_name="Sins of a Solar Empire"
|
|
game_id="204880"
|
|
;;
|
|
*) echo "Unrecognized game: ${game_launch} - trying anyways..."
|
|
game_id="${game_launch}"
|
|
;;
|
|
esac
|
|
|
|
if [ "${game_id}" ]; then
|
|
if [ "${app_proton}" ]; then
|
|
if [ "${WINEDEBUG}" ]; then
|
|
protontricks "${game_id}" --gui > /dev/null 2>&1
|
|
else
|
|
protontricks "${game_id}" --gui
|
|
fi
|
|
else
|
|
if [ ! "${game_name}" ]; then
|
|
game_name="${game_id}"
|
|
fi
|
|
echo "Attempting to run ${game_name}..."
|
|
${app_dir}${app_cmd} steam://rungameid/${game_id}
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
## Pick up any arguments provided
|
|
while getopts ":g:G:dDvVpPtTnNcCrRhH" option; do
|
|
case "${option}" in
|
|
"g"|"G") game_launch="${OPTARG}";;
|
|
"d"|"D")
|
|
if [ "${WINEDEBUG}" ]; then
|
|
unset WINEDEBUG
|
|
debug "Run debug enabled"
|
|
debug "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
|
|
app_verbose="y"
|
|
fi
|
|
;;
|
|
"p"|"P")
|
|
echo "Running protontricks..."
|
|
app_proton="y"
|
|
;;
|
|
"n"|"N")
|
|
inform "...with No BS..."
|
|
nobs_mode="y"
|
|
;;
|
|
"c"|"C")
|
|
echo "Running console..."
|
|
nobs_mode="y"
|
|
${console}
|
|
;;
|
|
"v"|"V")
|
|
if [ "${WINEDEBUG}" ]; then
|
|
if [ ! "${app_verbose}" ]; then
|
|
app_verbose="y"
|
|
#inform "Run verbose enabled"
|
|
inform "`realpath "${0}"` version ${script_ver} running as ${runas_user}"
|
|
fi
|
|
fi
|
|
;;
|
|
"t"|"T")
|
|
to_tray="-silent"
|
|
inform "Attempting hide to system tray"
|
|
;;
|
|
"r"|"R")
|
|
echo "Switching to steam-runtime..."
|
|
app_cmd="steam-runtime"
|
|
;;
|
|
"h"|"H")
|
|
echo "${usage}"
|
|
warp 0
|
|
;;
|
|
*) echo "Unknown option: -${OPTARG}"
|
|
echo "${usage}"
|
|
warp 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
|
|
|
|
## If a game was set for launch, give it a shot. Otherwise launcher.
|
|
if [ "${nobs_mode}" ]; then
|
|
debug "Skipping app launches"
|
|
else
|
|
debug "launch_select"
|
|
if [ "${game_launch}" ]; then
|
|
inform "game_launch argument: ${game_launch}"
|
|
game_on
|
|
else
|
|
echo "Running ${app_name}"
|
|
if [ "${WINEDEBUG}" ]; then
|
|
${app_dir}${app_cmd} "${to_tray}" > /dev/null 2>&1
|
|
else
|
|
${app_dir}${app_cmd} "${to_tray}"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
## If we still exist, clean up.
|
|
debug "final notice"
|
|
warp 0
|