-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_setup.sh
More file actions
94 lines (75 loc) · 2.52 KB
/
Copy pathenv_setup.sh
File metadata and controls
94 lines (75 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
set -e # exit on error
### CONFIG ###
VENV_DIR=".venv"
echo "=== environment setup ==="
### 1. Check and install SUMO ###
if ! command -v sumo >/dev/null 2>&1; then
echo "[INFO] SUMO not found. Installing..."
sudo add-apt-repository -y ppa:sumo/stable
sudo apt-get update
sudo apt-get install -y sumo sumo-tools sumo-doc
else
echo "[OK] SUMO is already installed."
fi
### 2. Check and install pip ###
if ! command -v pip3 >/dev/null 2>&1; then
echo "[INFO] pip not found. Installing..."
sudo apt-get update
sudo apt-get install -y python3-pip
else
echo "[OK] pip is already installed."
fi
### 3. Check and install python venv ###
if ! dpkg -s python3-venv >/dev/null 2>&1; then
echo "[INFO] python3-venv not found. Installing..."
sudo apt-get install -y python3-venv
else
echo "[OK] python3-venv is already installed."
fi
### 6. Set permanent environment variables ###
BASHRC="$HOME/.bashrc"
if ! grep -q "SUMO_HOME" "$BASHRC"; then
echo "[INFO] Setting SUMO_HOME permanently..."
echo 'export SUMO_HOME="/usr/share/sumo"' >> "$BASHRC"
fi
if ! grep -q "PROJECT_FOLDER" "$BASHRC"; then
echo "[INFO] Setting PROJECT_FOLDER permanently..."
echo "export PROJECT_FOLDER=\"$(pwd)\"" >> "$BASHRC"
fi
if ! grep -q "SIM_FOLD" "$BASHRC"; then
echo "[INFO] Setting SIM_FOLD permanently..."
echo "export SIM_FOLD=\"$(pwd)/simulations\"" >> "$BASHRC"
fi
# Apply variables for current session
export SUMO_HOME="/usr/share/sumo"
export PROJECT_FOLDER="$(pwd)"
export SIM_FOLD="$PROJECT_FOLDER/simulations"
SIM_RESULTS_FOLDER="$SIM_FOLDER/simulation_results"
LOG_FOLDER="$PROJECT_FOLDER/logs"
if [ ! -d "$SIM_RESULTS_FOLDER" ]; then
echo "[INFO] Creating simulation_results directory..."
mkdir -p "$SIM_RESULTS_FOLDER"
fi
if [ ! -d "$LOG_FOLDER" ]; then
echo "[INFO] Creating log directory..."
mkdir -p "$LOG_FOLDER"
fi
### 7. Create Python virtual environment ###
if [ ! -d "$VENV_DIR" ]; then
echo "[INFO] Creating virtual environment..."
python3 -m venv "$VENV_DIR"
else
echo "[OK] Virtual environment already exists."
fi
### 8. Activate venv and install requirements ###
echo "[INFO] Activating virtual environment and installing requirements..."
source "$VENV_DIR/bin/activate"
pip install --upgrade pip
if [ -f requirements.txt ]; then
pip install -r requirements.txt
else
echo "[WARN] requirements.txt not found."
fi
echo "=== Setup complete ==="
echo "Please run 'source ~/.bashrc' or open a new terminal to apply environment variables."