From bef8c7f45a6a9583fdd32ce2708ad93422cb3ede Mon Sep 17 00:00:00 2001 From: ATATC Date: Fri, 10 May 2024 17:06:47 -0400 Subject: [PATCH 1/3] Added xHost check. (#151) --- leads_vec/_bootloader/leads_vec.service.sh | 6 +++++- leads_vec/_bootloader/systemd.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/leads_vec/_bootloader/leads_vec.service.sh b/leads_vec/_bootloader/leads_vec.service.sh index 03f43d5d..2232394e 100644 --- a/leads_vec/_bootloader/leads_vec.service.sh +++ b/leads_vec/_bootloader/leads_vec.service.sh @@ -1,9 +1,13 @@ +#!/bin/bash + if [ ! -x "/usr/local/leads/config.json" ]; then echo "Error: Config file does not exist" exit 1 fi - +while ! xhost >& /dev/null; +do sleep 1 +done # change the interpreter or adjust the arguments according to your needs # do not remove `--xws` python-leads -m leads_vec -c /usr/local/leads/config.json --xws run \ No newline at end of file diff --git a/leads_vec/_bootloader/systemd.py b/leads_vec/_bootloader/systemd.py index 0dbd0441..65209d14 100644 --- a/leads_vec/_bootloader/systemd.py +++ b/leads_vec/_bootloader/systemd.py @@ -28,7 +28,7 @@ def create_service() -> None: f"User={(user := _get_login())}\n" "Environment=\"DISPLAY=:0\"\n" f"Environment=\"XAUTHORITY=/home/{user}/.Xauthority\"\n" - f"ExecStart=/bin/sh {script}\n" + f"ExecStart=/bin/bash {script}\n" "[Install]\n" "WantedBy=graphical.target" ) From ba8dd7db5b00d566541d31b5c16aaa443bdc871f Mon Sep 17 00:00:00 2001 From: ATATC Date: Fri, 10 May 2024 17:10:00 -0400 Subject: [PATCH 2/3] Replaced all /bin/sh with /bin/bash. --- README.md | 14 +++++++------- scripts/frp-config.sh | 2 +- scripts/frp-install.sh | 2 +- scripts/obs-install.sh | 2 +- scripts/obs-run.sh | 2 +- scripts/python-install.sh | 4 ++-- scripts/setup.sh | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4a0dc485..61d57202 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ You can simply run "[setup.sh](scripts/setup.sh)" and it will install everything dependencies of LEADS for you. ```shell -/bin/sh "setup.sh$(wget -O setup.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/setup.sh)" && rm setup.sh || rm setup.sh +bash "setup.sh$(wget -O setup.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/setup.sh)" && rm setup.sh || rm setup.sh ``` This will create a shortcut to save you from typing `python-leads -m leads_vec ...`, instead, you will just need to call @@ -263,7 +263,7 @@ This will create a shortcut to save you from typing `python-leads -m leads_vec . [python-install.sh](scripts/python-install.sh) will only install Python 3.12 and Tcl/Tk. ```shell -/bin/sh "python-install.sh$(wget -O python-install.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/python-install.sh)" && rm python-install.sh || rm python-install.sh +bash "python-install.sh$(wget -O python-install.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/python-install.sh)" && rm python-install.sh || rm python-install.sh ``` ### frp @@ -272,19 +272,19 @@ We use frp for reverse proxy. This is optional if you do not need public connect "[frp-install.sh](scripts/frp-install.sh)". ```shell -/bin/sh "frp-install.sh$(wget -O frp-install.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/frp-install.sh)" && rm frp-install.sh || rm frp-install.sh +bash "frp-install.sh$(wget -O frp-install.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/frp-install.sh)" && rm frp-install.sh || rm frp-install.sh ``` To configure frp, use "[frp-config.sh](scripts/frp-config.sh)". ```shell -/bin/sh "frp-config.sh$(wget -O frp-config.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/frp-config.sh)" && rm frp-config.sh || rm frp-config.sh +bash "frp-config.sh$(wget -O frp-config.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/frp-config.sh)" && rm frp-config.sh || rm frp-config.sh ``` There are 4 arguments for this script, of which the first 2 are required. ```shell -/bin/sh "frp-config.sh$(...)" {frp_server_ip} {frp_token} {frp_port} {comm_port} && rm frp-config.sh || rm frp-config.sh +bash "frp-config.sh$(...)" {frp_server_ip} {frp_token} {frp_port} {comm_port} && rm frp-config.sh || rm frp-config.sh ``` ### OBS Studio @@ -293,7 +293,7 @@ We also use OBS Studio for streaming, but it is not required. If you want to ins run "[obs-install.sh](scripts/obs-install.sh)". ```shell -/bin/sh "obs-install.sh$(wget -O obs-install.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/obs-install.sh)" && rm obs-install.sh || rm obs-install.sh +bash "obs-install.sh$(wget -O obs-install.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/obs-install.sh)" && rm obs-install.sh || rm obs-install.sh ``` Do not run the OBS Studio directly, instead, use "[obs-run.sh](scripts/obs-run.sh)". @@ -307,7 +307,7 @@ wget -O obs-run.sh https://raw.githubusercontent.com/ProjectNeura/LEADS/master/s Run the script as shown. ```shell -/bin/sh obs-run.sh +bash obs-run.sh ``` If you want the identical layout configuration, see the following. diff --git a/scripts/frp-config.sh b/scripts/frp-config.sh index 9b7cc12e..e39a8d31 100644 --- a/scripts/frp-config.sh +++ b/scripts/frp-config.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash abort() { printf "%s\n" "$@" >&2 diff --git a/scripts/frp-install.sh b/scripts/frp-install.sh index 68e030d6..2c5b6b25 100644 --- a/scripts/frp-install.sh +++ b/scripts/frp-install.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash abort() { printf "%s\n" "$@" >&2 diff --git a/scripts/obs-install.sh b/scripts/obs-install.sh index 7ac81fa6..10978c71 100644 --- a/scripts/obs-install.sh +++ b/scripts/obs-install.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash abort() { printf "%s\n" "$@" >&2 diff --git a/scripts/obs-run.sh b/scripts/obs-run.sh index 26adac26..87047950 100644 --- a/scripts/obs-run.sh +++ b/scripts/obs-run.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash abort() { printf "%s\n" "$@" >&2 diff --git a/scripts/python-install.sh b/scripts/python-install.sh index 824c10ff..6a50a07d 100644 --- a/scripts/python-install.sh +++ b/scripts/python-install.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash abort() { printf "%s\n" "$@" >&2 @@ -29,7 +29,7 @@ execute_root "apt" "install" "-y" "python3.12-tk" echo "Creating Virtual Environment..." execute_root "python3.12" "-m" "venv" "/usr/local/leads/venv" echo "Creating Soft Links..." -echo "#!/bin/sh" > "/bin/python-leads" +echo "#!/bin/bash" > "/bin/python-leads" echo '/usr/local/leads/venv/bin/python "$@"' >> "/bin/python-leads" execute_root "chmod" "+x" "/bin/python-leads" execute_root "ln" "-s" "/usr/local/leads/venv/bin/pip" "/bin/pip-leads" \ No newline at end of file diff --git a/scripts/setup.sh b/scripts/setup.sh index c0a7ae0e..6c7ea570 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash abort() { printf "%s\n" "$@" >&2 @@ -21,13 +21,13 @@ execute_root() { echo "Installing Python..." execute_root "wget" "-O" "python-install.sh" "https://raw.githubusercontent.com/ProjectNeura/LEADS/master/scripts/python-install.sh" -execute_root "/bin/sh" "python-install.sh" +execute_root "/bin/bash" "python-install.sh" echo "Cleaning up..." execute_root "rm" "python-install.sh" echo "Installing dependencies..." execute "pip-leads" "install" "Pillow" "PySDL2" "customtkinter" "gpiozero" "lgpio" "pynmea2" "pynput" "pysdl2-dll" "pyserial" "leads" echo "Creating Shortcut..." -echo "#!/bin/sh" > "/bin/leads-vec" +echo "#!/bin/bash" > "/bin/leads-vec" echo 'python-leads -m leads_vec "$@"' >> "/bin/leads-vec" execute_root "chmod" "+x" "/bin/leads-vec" echo "Verifying..." From c55b17d0f50728e8bdceda325a006105fd279791 Mon Sep 17 00:00:00 2001 From: ATATC Date: Fri, 10 May 2024 17:49:30 -0400 Subject: [PATCH 3/3] SDL initialization failure is no longer fatal. Supported auto-retry. (https://github.com/ProjectNeura/LEADS/issues/151#issuecomment-2105289961) --- leads_audio/prototype.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/leads_audio/prototype.py b/leads_audio/prototype.py index 96bc905b..7ef13360 100644 --- a/leads_audio/prototype.py +++ b/leads_audio/prototype.py @@ -1,10 +1,13 @@ from atexit import register as _register +from threading import Thread as _Thread +from time import sleep as _sleep from sdl2 import AUDIO_S16 as _AUDIO_S16 from sdl2.sdlmixer import Mix_Init as _init, Mix_OpenAudioDevice as _open_audio_device, MIX_INIT_MP3 as _MIX_INIT_MP3, \ Mix_LoadMUS as _load_music, Mix_PlayMusic as _play_music, Mix_Music as _Music, \ Mix_GetError as _get_error, Mix_FreeMusic as _free_music, Mix_CloseAudio as _close_audio +from leads import L as _L from leads_audio.system import _ASSETS_PATH @@ -14,7 +17,19 @@ def _ensure(flag: int) -> None: _init(_MIX_INIT_MP3) -_ensure(_open_audio_device(44100, _AUDIO_S16, 2, 2048, None, 1)) + + +def _try_open_audio_device() -> None: + flag = -1 + while flag < 0: + try: + _ensure(flag := _open_audio_device(44100, _AUDIO_S16, 2, 2048, None, 1)) + except RuntimeError as e: + _L.error(repr(e)) + _sleep(10) + + +_Thread(name="sdl initializer", target=_try_open_audio_device, daemon=True).start() @_register