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)
|
2023-10-24 16:00:57 +00:00
|
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
2022-02-05 14:23:32 +00:00
|
|
|
|
|
|
|
. /etc/os-release
|
|
|
|
|
2023-08-08 12:13:09 +00:00
|
|
|
export XDG_RUNTIME_DIR=/var/run/0-runtime-dir
|
2022-09-14 21:35:38 +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"
|
2023-08-03 13:30:56 +00:00
|
|
|
J_CONF_LOCK="/tmp/.system.cfg.lock"
|
2022-02-05 14:23:32 +00:00
|
|
|
ES_CONF="/storage/.emulationstation/es_settings.cfg"
|
2022-09-14 21:35:38 +00:00
|
|
|
JSLISTENCONF="${J_DIR}/configs/jslisten.cfg"
|
2022-02-05 14:23:32 +00:00
|
|
|
|
2023-08-03 13:30:56 +00:00
|
|
|
function tocon() {
|
|
|
|
echo -ne "\033[1000H\033[2K==> ${*}" >/dev/console
|
|
|
|
}
|
|
|
|
|
|
|
|
function log() {
|
|
|
|
SOURCE=${1//\/*\//}
|
|
|
|
MESSAGE=${*#${1}}
|
|
|
|
MESSAGE=${MESSAGE# }
|
|
|
|
logger -t ${SOURCE} "${MESSAGE}"
|
|
|
|
echo "$(date) ${SOURCE}: ${MESSAGE}" >>/var/log/messages
|
|
|
|
}
|
|
|
|
|
2023-07-22 23:56:23 +00:00
|
|
|
function get_setting() {
|
2023-09-15 00:05:15 +00:00
|
|
|
if [ -n "${3}" ]
|
2022-04-02 13:13:04 +00:00
|
|
|
then
|
2022-04-09 00:08:14 +00:00
|
|
|
### Test to see if we have a game setting.
|
2023-12-29 17:55:37 +00:00
|
|
|
VAR="$2\[\"$(echo ${3} | sed -E "s~'~\\\x27~g"';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.
|
2023-07-11 21:03:02 +00:00
|
|
|
LOCAL=$(awk -F: '/^'"${2}.${1}"'=/ { st = index($0,"=");print substr($0,st+1);exit}' ${J_CONF})
|
|
|
|
if [ ! -z "${LOCAL}" ]
|
|
|
|
then
|
|
|
|
echo ${LOCAL}
|
|
|
|
return
|
|
|
|
fi
|
2022-04-09 00:08:14 +00:00
|
|
|
fi
|
2023-07-11 21:03:02 +00:00
|
|
|
fi
|
|
|
|
|
2023-09-15 00:05:15 +00:00
|
|
|
if [ -z "${3}" ] && [ -n "${2}" ]
|
2022-04-09 00:08:14 +00:00
|
|
|
then
|
2023-09-15 00:05:15 +00:00
|
|
|
### Check to see if we have a global setting.
|
2023-07-11 21:03:02 +00:00
|
|
|
LOCAL=$(awk -F: '/^'"${2}.${1}"'=/ { st = index($0,"=");print substr($0,st+1);exit}' ${J_CONF})
|
|
|
|
if [ ! -z "${LOCAL}" ]
|
|
|
|
then
|
|
|
|
echo ${LOCAL}
|
2022-04-09 00:08:14 +00:00
|
|
|
return
|
2023-07-11 21:03:02 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-09-15 00:05:15 +00:00
|
|
|
### Check to see if we have a "system." global setting.
|
|
|
|
SYSTEM=$(awk -F: '/^system.'"${1}"='/ { st = index($0,"=");print substr($0,st+1);exit}' ${J_CONF})
|
|
|
|
if [ -n "${SYSTEM}" ]
|
|
|
|
then
|
|
|
|
echo ${SYSTEM}
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
### Check to see if we have a "global." global setting."
|
2023-07-11 21:03:02 +00:00
|
|
|
LOCAL=$(awk -F: '/^'"${1}"='/ { st = index($0,"=");print substr($0,st+1);exit}' ${J_CONF})
|
|
|
|
if [ -z "${LOCAL}" ]
|
|
|
|
then
|
|
|
|
awk -F: '/^global.'"${1}"='/ { st = index($0,"=");print substr($0,st+1);exit}' ${J_CONF}
|
2023-09-15 00:05:15 +00:00
|
|
|
return
|
2022-04-02 13:13:04 +00:00
|
|
|
else
|
2023-07-11 21:03:02 +00:00
|
|
|
echo ${LOCAL}
|
2022-04-02 13:13:04 +00:00
|
|
|
fi
|
2023-07-11 21:03:02 +00:00
|
|
|
return
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 14:47:27 +00:00
|
|
|
function wait_lock() {
|
|
|
|
while true
|
2023-08-03 13:35:26 +00:00
|
|
|
do
|
2023-08-03 14:47:27 +00:00
|
|
|
if (set -o noclobber; echo "$$" > "${J_CONF_LOCK}") 2>/dev/null
|
|
|
|
then
|
|
|
|
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
|
|
|
|
break
|
|
|
|
else
|
|
|
|
sleep 1
|
|
|
|
fi
|
2023-08-03 13:35:26 +00:00
|
|
|
done
|
2023-08-03 14:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function del_setting() {
|
|
|
|
wait_lock
|
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}"
|
2023-02-05 22:42:47 +00:00
|
|
|
fi
|
2023-08-03 13:35:26 +00:00
|
|
|
rm -f "${J_CONF_LOCK}"
|
2023-02-05 22:42:47 +00:00
|
|
|
}
|
|
|
|
|
2023-07-25 21:06:19 +00:00
|
|
|
function sort_settings() {
|
2023-08-03 14:47:27 +00:00
|
|
|
wait_lock
|
2023-07-25 21:06:19 +00:00
|
|
|
cat "${J_CONF}" | grep ^[a-z0-9] | sort >"${J_CONF}.tmp"
|
|
|
|
mv "${J_CONF}.tmp" "${J_CONF}"
|
2023-08-03 13:35:26 +00:00
|
|
|
rm -f "${J_CONF_LOCK}"
|
2023-07-25 21:06:19 +00:00
|
|
|
}
|
|
|
|
|
2023-07-22 23:56:23 +00:00
|
|
|
function set_setting() {
|
2024-01-16 12:38:18 +00:00
|
|
|
|
|
|
|
if [ ! -d "/storage/.config/system/configs" ]
|
|
|
|
then
|
|
|
|
mkdir -p /storage/.config/system/configs
|
|
|
|
fi
|
|
|
|
if [ ! -e "/storage/.config/system/configs/system.cfg" ]
|
|
|
|
then
|
|
|
|
cp -f /usr/config/system/configs/system.cfg /storage/.config/system/configs/system.cfg
|
|
|
|
fi
|
|
|
|
|
2023-02-05 22:42:47 +00:00
|
|
|
if [[ "${1}" =~ ^[[:alnum:]] ]]
|
|
|
|
then
|
|
|
|
del_setting "${1}"
|
2023-07-17 11:55:58 +00:00
|
|
|
if [ ! "${2}" = "default" ]
|
2023-07-17 11:54:46 +00:00
|
|
|
then
|
2023-08-03 14:47:27 +00:00
|
|
|
wait_lock
|
2023-07-17 11:54:46 +00:00
|
|
|
echo "${1}=${2}" >> "${J_CONF}"
|
2023-08-03 14:47:27 +00:00
|
|
|
rm -f "${J_CONF_LOCK}"
|
2023-07-17 11:54:46 +00:00
|
|
|
fi
|
2022-03-20 19:57:43 +00:00
|
|
|
fi
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
2023-07-22 23:56:23 +00:00
|
|
|
function battery_percent() {
|
2023-06-27 00:13:51 +00:00
|
|
|
awk 'BEGIN {FS="="} /POWER_SUPPLY_CAPACITY=/ {print $2}' /sys/class/power_supply/[Bb][Aa][Tt]*/uevent 2>/dev/null
|
2023-06-26 22:07:10 +00:00
|
|
|
}
|
|
|
|
|
2023-07-22 23:56:23 +00:00
|
|
|
function get_es_setting() {
|
2022-09-14 21:35:38 +00:00
|
|
|
echo $(sed -n "s|\s*<${1} name=\"${2}\" value=\"\(.*\)\" />|\1|p" ${ES_CONF})
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
2023-07-29 00:44:10 +00:00
|
|
|
function fbwidth() {
|
|
|
|
local ORIENTATION=$(</sys/devices/virtual/graphics/fbcon/rotate)
|
|
|
|
if [ "${ORIENTATION}" = "0" ]
|
|
|
|
then
|
|
|
|
fbset | awk '/geometry/ {print $2}'
|
|
|
|
else
|
|
|
|
fbset | awk '/geometry/ {print $3}'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function fbheight() {
|
|
|
|
local ORIENTATION=$(</sys/devices/virtual/graphics/fbcon/rotate)
|
|
|
|
if [ "${ORIENTATION}" = "0" ]
|
|
|
|
then
|
|
|
|
fbset | awk '/geometry/ {print $3}'
|
|
|
|
else
|
|
|
|
fbset | awk '/geometry/ {print $2}'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-08-05 01:31:57 +00:00
|
|
|
function cpu_vendor() {
|
|
|
|
awk '/vendor_id/ {print $3;exit}' /proc/cpuinfo
|
|
|
|
}
|
|
|
|
|
2023-07-22 23:56:23 +00:00
|
|
|
function get_aspect_ratio() {
|
2023-07-29 00:44:10 +00:00
|
|
|
FBWIDTH=$(fbwidth)
|
|
|
|
FBHEIGHT=$(fbheight)
|
2023-07-22 23:56:23 +00:00
|
|
|
|
|
|
|
ASPECT=$(printf "%.2f" $(echo "(${FBWIDTH} / ${FBHEIGHT})" | bc -l))
|
|
|
|
|
|
|
|
case ${ASPECT} in
|
2023-08-19 15:22:04 +00:00
|
|
|
1.00)
|
|
|
|
ASPECT="1:1"
|
|
|
|
;;
|
2023-07-22 23:56:23 +00:00
|
|
|
1.50|0.67)
|
|
|
|
ASPECT="3:2"
|
|
|
|
;;
|
|
|
|
1.33|0.75)
|
|
|
|
ASPECT="4:3"
|
|
|
|
;;
|
|
|
|
1.67|0.60)
|
|
|
|
ASPECT="5:3"
|
|
|
|
;;
|
2023-07-23 20:53:30 +00:00
|
|
|
1.7*|0.56)
|
2023-07-22 23:56:23 +00:00
|
|
|
ASPECT="16:9"
|
|
|
|
;;
|
|
|
|
1.60|0.62)
|
|
|
|
ASPECT="16:10"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo ${ASPECT}
|
|
|
|
}
|