Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 804a989

Browse files
authored
Merge pull request #7 from Unity-Lab-AI/codex/2025-08-08-fix-missing-virtual-environment-activation
Ensure setup scripts run from their own directory
2 parents fcd1088 + 2faacfb commit 804a989

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

setup.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
@echo off
22
setlocal enabledelayedexpansion
33

4+
REM Ensure the script runs from its own directory
5+
set "SCRIPT_DIR=%~dp0"
6+
cd /d "%SCRIPT_DIR%"
7+
48
REM Ensure Python is available without compiling
59
where python >nul 2>&1
610
if errorlevel 1 (

setup.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
# Setup script for UnityBotV4 on Linux
44
set -e
55

6-
read -p "Use .env file for configuration? (y/n): " use_env
6+
# Ensure the script runs from its own directory
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
cd "$SCRIPT_DIR"
9+
10+
read -r -p "Use .env file for configuration? (y/n): " use_env
711

812
if [[ "$use_env" =~ ^[Yy]$ ]]; then
913
TARGET="env"
@@ -43,11 +47,11 @@ else
4347
fi
4448

4549
# Verify Python version
46-
python3 - <<'PYTHON'
50+
if ! python3 - <<'PYTHON'
4751
import sys
4852
sys.exit(0 if sys.version_info >= (3, 8) else 1)
4953
PYTHON
50-
if [ $? -ne 0 ]; then
54+
then
5155
echo "Python 3.8+ is required. Please install a supported version." >&2
5256
exit 1
5357
fi
@@ -56,19 +60,21 @@ fi
5660
if [ ! -d .venv ]; then
5761
python3 -m venv .venv || { echo "Failed to create virtual environment" >&2; exit 1; }
5862
fi
63+
# shellcheck source=/dev/null
5964
source .venv/bin/activate
6065

6166
prompt_var() {
6267
local var_name=$1
63-
local env_val=$(printenv "$var_name")
68+
local env_val
69+
env_val=$(printenv "$var_name")
6470
local file_val=""
6571
[[ -f .env ]] && file_val=$(grep -E "^${var_name}=" .env | cut -d'=' -f2-)
6672

6773
if [[ "$TARGET" == "env" ]]; then
6874
if [[ -n "$file_val" ]]; then
6975
echo "$var_name already set in .env. Skipping prompt."
7076
else
71-
read -p "Enter value for $var_name${env_val:+ [$env_val]}: " value
77+
read -r -p "Enter value for $var_name${env_val:+ [$env_val]}: " value
7278
value=${value:-$env_val}
7379
[[ -f .env ]] && grep -v "^$var_name=" .env > .env.tmp && mv .env.tmp .env
7480
echo "$var_name=$value" >> .env
@@ -77,7 +83,7 @@ prompt_var() {
7783
if [[ -n "$env_val" ]]; then
7884
echo "$var_name already set. Skipping prompt."
7985
else
80-
read -p "Enter value for $var_name: " value
86+
read -r -p "Enter value for $var_name: " value
8187
if grep -q "^$var_name=" /etc/environment 2>/dev/null; then
8288
sudo sed -i "s/^$var_name=.*/$var_name=\"${value}\"/" /etc/environment
8389
else

0 commit comments

Comments
 (0)