Bash_Scripts/CentOS/Steam-Add-User.bash
2021-07-28 09:32:08 -05:00

72 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -e
usage() {
printf "%s\n" "Usage: $(basename "${0}") -u <steam username> -p <steam password>
--username <steam username> | -u <steam username>
Example:
--username Sbinalla"
}
error() {
printf "\n%s\n" "$1" >&2
exit 1
}
confirmation() {
while true; do
read -p "${1}" -n 1 -r choice
case "$choice" in
y|Y ) return 1;;
n|N ) return 0;;
* ) echo -e "\nInput must be either y, Y, n, or N";;
esac
done
}
while :; do
case $1 in
-h | -\? | --help)
usage # Display a usage synopsis.
exit
;;
--) # End of all options.
shift
break
;;
-u | --username)
shift
STEAMUSERNAME="${1}"
;;
-?*)
printf 'Unknown option: %s\n' "$1" >&2
usage
error
;;
*) # Default case: No more options, so break out of the loop.
break ;;
esac
shift
done
[[ "${STEAMUSERNAME}" == "" ]] && error "A steam username must be passed"
# Securely read password without echoing
stty -echo
printf "Enter the password for %s: " "${STEAMUSERNAME}"
read -r STEAMPASSWORD
stty echo
printf "\n"
[[ "${STEAMPASSWORD}" == "" ]] && error "A password for the steam account must be passed"
# Used to ensure a Steam directory is generated for userdata saving of account data
steamcmd +quit
# The below FEELS and LOOKS like bullshit, but steam does have output for the operation below.
# SteamCMD fails to return any exit code via the commands below and as such scripting it is a PITA and thus it
# stays like this.
steamcmd +login "${STEAMUSERNAME}" "${STEAMPASSWORD}" +quit