2022-02-05 14:23:32 +00:00
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2019-present Shanti Gilbert (https://github.com/shantigilbert)
# Copyright (C) 2020-present Fewtarius
. /etc/os-release
2022-09-14 00:29:29 +00:00
export PATH="/usr/bin:/usr/local/bin:/storage/bin:${PATH}"
2022-02-05 14:23:32 +00:00
export SDL_GAMECONTROLLERCONFIG_FILE="/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt"
2022-02-27 02:40:30 +00:00
J_DIR="/storage/.config/system"
J_CONF="${J_DIR}/configs/system.cfg"
2022-02-05 14:23:32 +00:00
ES_CONF="/storage/.emulationstation/es_settings.cfg"
2022-09-14 00:29:29 +00:00
JSLISTENCONF="${J_DIR}/configs/jslisten.cfg"
2022-02-05 14:23:32 +00:00
get_setting() {
2022-04-02 13:13:04 +00:00
if [ ! -z "${3}" ]
then
2022-04-09 00:08:14 +00:00
### Test to see if we have a game setting.
2022-04-27 10:33:45 +00:00
VAR="$2\[\"$(echo ${3} | sed 's/[\(\)]/\\&/g')\"\]\.$1"
2022-08-14 23:00:26 +00:00
OUTPUT=$(awk 'BEGIN {FS="="} /^'"${VAR}"'/ {print $NF}' ${J_CONF})
2022-04-09 00:08:14 +00:00
if [ ! -z "${OUTPUT}" ]
then
echo ${OUTPUT}
return
else
### If not, check to see if we have a system setting.
2022-08-14 23:00:26 +00:00
awk -F: '/^'"${2}.${1}"'=/ { st = index($0,"=");print substr($0,st+1);exit}' ${J_CONF}
2022-04-09 00:08:14 +00:00
return
fi
elif [ -z "${3}" ] && [ ! -z "${2}" ]
then
### Check to see if we have a system setting.
2022-08-14 23:00:26 +00:00
awk -F: '/^'"${2}.${1}"'=/ { st = index($0,"=");print substr($0,st+1);exit}' ${J_CONF}
2022-04-09 00:08:14 +00:00
return
2022-04-02 13:13:04 +00:00
else
2022-04-09 00:08:14 +00:00
### Check to see if we have a global setting
2022-08-14 23:00:26 +00:00
awk -F: '/^'"${1}"='/ { st = index($0,"=");print substr($0,st+1);exit}' ${J_CONF}
return
2022-04-02 13:13:04 +00:00
fi
2022-02-05 14:23:32 +00:00
}
set_setting() {
2022-08-06 11:29:53 +00:00
if [[ "${1}" =~ ^[[:alnum:]] ]]
2022-03-20 19:57:43 +00:00
then
2022-08-06 11:29:53 +00:00
sed -i "/^${1}=/d" "${J_CONF}"
2022-03-20 19:57:43 +00:00
echo "${1}=${2}" >> "${J_CONF}"
fi
2022-02-05 14:23:32 +00:00
}
set_audio() {
case ${1} in
"default")
AUDIO="alsa"
;;
*)
AUDIO=${1}
;;
esac
/usr/bin/rr_audio.sh ${AUDIO}
}
get_es_setting() {
2022-09-14 00:29:29 +00:00
echo $(sed -n "s|\s*<${1} name=\"${2}\" value=\"\(.*\)\" />|\1|p" ${ES_CONF})
2022-02-05 14:23:32 +00:00
}
check_bios() {
2022-09-14 00:29:29 +00:00
PLATFORM="${1}"
CORE="${2}"
EMULATOR="${3}"
ROMNAME="${4}"
LOG="${5}"
if [[ -z "$LOG" ]]; then
LOG="/var/log/exec.log"
cat /etc/motd > "$LOG"
fi
2022-02-05 14:23:32 +00:00
2022-09-14 00:29:29 +00:00
MISSINGBIOS="$(batocera-systems --strictfilter ${PLATFORM})"
if [ "$?" == "2" ]; then
# formating so it looks nice :)
PLATFORMNAME="${MISSINGBIOS##*>}" # read from -P onwards
PLATFORMNAME="${PLATFORMNAME%%MISSING*}" # until a space is found
PLATFORMNAME=$(echo $PLATFORMNAME | sed -e 's/\\n//g')
if [[ -f "${LOG}" ]]; then
echo "${CORE} ${EMULATOR} ${ROMNAME}" >> $LOG
echo "${PLATFORMNAME} missing BIOS - Could not find all BIOS: " >> $LOG
echo "please make sure you copied the files into the corresponding folder " >> $LOG
echo "${MISSINGBIOS}" >> $LOG
fi
MISSINGBIOS=$(echo "$MISSINGBIOS" | sed -e 's/$/\\n/g')
2022-02-05 14:23:32 +00:00
2022-09-14 00:29:29 +00:00
/usr/bin/error.sh "${PLATFORMNAME} missing BIOS" "Could not find all BIOS/files in /storage/roms, the game may not work:\n\n ${MISSINGBIOS}\n\nPlease make sure you copied the files into the corresponding folder."
error_process="$!"
pkill -P $error_process
fi
2022-02-05 14:23:32 +00:00
}
# read config files from /storage/.config/profile.d
for config in /storage/.config/profile.d/*; do
if [ -f "$config" ] ; then
. $config
fi
done
2022-09-14 00:29:29 +00:00
stop_ui() {
if [ "${UI_SERVICE}" = "weston.service" ]
then
chvt 2
else
systemctl stop ${UI_SERVICE}
fi
}
start_ui() {
if [ "${UI_SERVICE}" = "weston.service" ]
then
chvt 1
else
systemctl start ${UI_SERVICE}
fi
}