|
#!/bin/sh
|
|
# Useful because the emulator seems to pick the same number on every system when it needs to generate its own account_steamid.
|
|
# Dependencies:
|
|
# dep-devuan: moreutils
|
|
# Env vars: APPLY VERBOSE
|
|
if test -z "${INFILE}" ;
|
|
then
|
|
scriptdir="$( dirname "$( readlink -f "${0}" )" )"
|
|
# find first one. IGNORE the saves/settings/configs.user.ini which is the auto-generated one.
|
|
INFILE="$( find "${scriptdir}" "${scriptdir}/.." "${scriptdir}/../.." -ipath '*/steam_settings/configs.user.ini' -print -quit )"
|
|
fi
|
|
|
|
# Steam id is 17 digits long, decimal, and starts with 765611982
|
|
new_steamid="765611982$( </dev/random tr -dc '0-9' | head -c8 )"
|
|
|
|
# modconf.py breaks on set account_steamid because of the underscore. I will have to do this with awk or sed or similar 2026-06-30-3 23:55
|
|
#if test -n "${VERBOSE}" ; then echo "/usr/libexec/bgscripts/py/modconf.py ${APPLY:+-a} ${VERBOSE:+-v} -s '[user::general]' \"${INFILE}\" set account_steamid \"${new_steamid}\"" ; fi
|
|
#/usr/libexec/bgscripts/py/modconf.py ${APPLY:+-a} ${VERBOSE:+-v} -s '[user::general]' "${INFILE}" set account_steamid "${new_steamid}"
|
|
|
|
# So use basic awk instead
|
|
if test -n "${VERBOSE}" ;
|
|
then
|
|
echo "awk -v \"b=${new_steamid}\" -F'=' 'BEGIN{OFS=\"=\"} \$1~/account_steamid/{\$2=b} {print}' \"${INFILE}\" | sponge \"${INFILE}\""
|
|
fi
|
|
if test -n "${APPLY}" ;
|
|
then
|
|
awk -v "b=${new_steamid}" -F'=' 'BEGIN{OFS="="} $1~/account_steamid/{$2=b} {print}' "${INFILE}" | sponge "${INFILE}"
|
|
# Regardless if it worked, read the value and show it.
|
|
final_steamid="$( awk -F'=' '$1~/account_steamid/{print $NF}' "${INFILE}" )"
|
|
echo "account_steamid = ${final_steamid}"
|
|
fi
|
|
|
|
# modconf.py has a bug where it adds an additional newline after that updated line, so
|
|
# collapse multiple empty lines into a single empty line: ref https://unix.stackexchange.com/a/72749
|
|
awk '!NF {if (++n <= 1) print; next}; {n=0;print}' "${INFILE}" | sponge "${INFILE}"
|
|
if test -z "${APPLY}" ; then echo "Dry run only! Use APPLY=1" 1>&2 ; fi
|