From 01b825920046731d9aa2355d45ce2dd1af510190 Mon Sep 17 00:00:00 2001 From: ota Date: Sat, 16 Dec 2023 09:53:41 +0200 Subject: [PATCH] update generate_emu_config scripts to support Linux, it worked! --- scripts/rebuild_linux.sh | 29 +++++++ scripts/{rebuild.bat => rebuild_win.bat} | 81 ++++++++++--------- scripts/recreate_venv_linux.sh | 29 +++++++ ...ecreate_venv.bat => recreate_venv_win.bat} | 34 ++++---- 4 files changed, 121 insertions(+), 52 deletions(-) create mode 100644 scripts/rebuild_linux.sh rename scripts/{rebuild.bat => rebuild_win.bat} (65%) create mode 100644 scripts/recreate_venv_linux.sh rename scripts/{recreate_venv.bat => recreate_venv_win.bat} (54%) diff --git a/scripts/rebuild_linux.sh b/scripts/rebuild_linux.sh new file mode 100644 index 00000000..22744a14 --- /dev/null +++ b/scripts/rebuild_linux.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + + +venv=".env-linux" +out_dir="bin/linux" +build_temp_dir="build_tmp-linux" +tool_name="generate_emu_config" +main_file="generate_emu_config.py" + +[[ -d "$out_dir" ]] && rm -r -f "$out_dir" +mkdir -p "$out_dir" + +[[ -d "$build_temp_dir" ]] && rm -r -f "$build_temp_dir" + +rm -f *.spec + +chmod 777 "./$venv/bin/activate" +source "./$venv/bin/activate" + +pyinstaller "$main_file" --distpath "$out_dir" -y --clean --onedir --name "$tool_name" --noupx --console -i "NONE" --workpath "$build_temp_dir" --collect-submodules "steam" || exit 1 + +cp -f "steam_default_icon_locked.jpg" "$out_dir/$tool_name" +cp -f "steam_default_icon_unlocked.jpg" "$out_dir/$tool_name" + +echo; +echo ============= +echo Built inside: "$out_dir/" + +deactivate diff --git a/scripts/rebuild.bat b/scripts/rebuild_win.bat similarity index 65% rename from scripts/rebuild.bat rename to scripts/rebuild_win.bat index a8396e2b..1a3fe589 100644 --- a/scripts/rebuild.bat +++ b/scripts/rebuild_win.bat @@ -1,37 +1,44 @@ -@echo off - -setlocal -pushd "%~dp0" - -set "venv=.env" -set "out_dir=bin" -set "build_temp_dir=build_tmp" -set "tool_name=generate_emu_config" -set "icon_file=icon\Froyoshark-Enkel-Steam.ico" -set "main_file=generate_emu_config.py" - -if exist "%out_dir%" ( - rmdir /s /q "%out_dir%" -) - -if exist "%build_temp_dir%" ( - rmdir /s /q "%build_temp_dir%" -) - -del /f /q "*.spec" - -call "%venv%\Scripts\activate.bat" - -pyinstaller "%main_file%" --distpath "%out_dir%" -y --clean --onedir --name "%tool_name%" --noupx --console -i "%icon_file%" --workpath "%build_temp_dir%" --collect-submodules "steam" - -copy /y "steam_default_icon_locked.jpg" "%out_dir%\%tool_name%\" -copy /y "steam_default_icon_unlocked.jpg" "%out_dir%\%tool_name%\" - -echo: -echo ============= -echo Built inside : "%out_dir%\" - -:script_end -popd -endlocal - +@echo off + +setlocal +pushd "%~dp0" + +set "venv=.env-win" +set "out_dir=bin\win" +set "build_temp_dir=build_tmp-win" +set "tool_name=generate_emu_config" +set "icon_file=icon\Froyoshark-Enkel-Steam.ico" +set "main_file=generate_emu_config.py" + +set /a last_code=0 + +if exist "%out_dir%" ( + rmdir /s /q "%out_dir%" +) +mkdir "%out_dir%" + +if exist "%build_temp_dir%" ( + rmdir /s /q "%build_temp_dir%" +) + +del /f /q "*.spec" + +call "%venv%\Scripts\activate.bat" + +pyinstaller "%main_file%" --distpath "%out_dir%" -y --clean --onedir --name "%tool_name%" --noupx --console -i "%icon_file%" --workpath "%build_temp_dir%" --collect-submodules "steam" || ( + set /a last_code=1 + goto :script_end +) + +copy /y "steam_default_icon_locked.jpg" "%out_dir%\%tool_name%\" +copy /y "steam_default_icon_unlocked.jpg" "%out_dir%\%tool_name%\" + +echo: +echo ============= +echo Built inside: "%out_dir%\" + +:script_end +popd +endlocal & ( + exit /b %last_code% +) diff --git a/scripts/recreate_venv_linux.sh b/scripts/recreate_venv_linux.sh new file mode 100644 index 00000000..42ec8176 --- /dev/null +++ b/scripts/recreate_venv_linux.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + + +if [ "$(id -u)" -ne 0 ]; then + echo "Please run as root" >&2 + exit 1 +fi + +venv=".env-linux" +reqs_file="requirements.txt" +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +apt update || exit 1 +apt install "python3.10" -y || exit 1 +apt install "python3.10-venv" -y || exit 1 + +[[ -d "$script_dir/$venv" ]] && rm -r -f "$script_dir/$venv" + +python3.10 -m venv "$script_dir/$venv" || exit 1 +sleep 1 + +chmod 777 "$script_dir/$venv/bin/activate" +source "$script_dir/$venv/bin/activate" + +pip install -r "$script_dir/$reqs_file" +exit_code=$? + +deactivate +exit $exit_code diff --git a/scripts/recreate_venv.bat b/scripts/recreate_venv_win.bat similarity index 54% rename from scripts/recreate_venv.bat rename to scripts/recreate_venv_win.bat index 6b4397d9..4b4a7494 100644 --- a/scripts/recreate_venv.bat +++ b/scripts/recreate_venv_win.bat @@ -1,15 +1,19 @@ -@echo off - -cd /d "%~dp0" - -set "venv=.env" -set "reqs_file=requirements.txt" - -if exist "%venv%" ( - rmdir /s /q "%venv%" -) - -python -m venv "%venv%" -timeout /t 1 /nobreak -call "%venv%\Scripts\activate.bat" -pip install -r "%reqs_file%" +@echo off + +cd /d "%~dp0" + +set "venv=.env-win" +set "reqs_file=requirements.txt" + +if exist "%venv%" ( + rmdir /s /q "%venv%" +) + +python -m venv "%venv%" || exit /b 1 +timeout /t 1 /nobreak +call "%venv%\Scripts\activate.bat" +pip install -r "%reqs_file%" +set /a exit_code=errorlevel + +call "%venv%\Scripts\deactivate.bat" +exit /b %exit_code%