-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart_mac-linux.sh
84 lines (76 loc) · 2.96 KB
/
start_mac-linux.sh
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
#!/bin/bash
# Log file
LOGFILE="script_log.txt"
echo "Logging errors to $LOGFILE"
echo "If you run this script for the first time, it may take some time."
echo "------------------------------------------------------------------"
# Check if Python is installed
if ! command -v python3 &>/dev/null; then
echo "Python is not installed. Please install Python 3.6+ to continue."
echo "$(date) - Python not installed" >> $LOGFILE
read -n 1 -s -r -p "Press any key to exit..."
exit 1
fi
# Check if virtual environment exists
if [ -d "venv" ]; then
echo "Virtual environment already exists. Skipping creation."
else
echo "Creating virtual environment..."
python3 -m venv venv >> $LOGFILE 2>&1
if [ $? -ne 0 ]; then
echo "Failed to create virtual environment. Make sure Python 3.6+ is properly installed."
echo "$(date) - Failed to create virtual environment" >> $LOGFILE
read -n 1 -s -r -p "Press any key to exit..."
exit 1
fi
fi
# Activate the virtual environment
echo "Activating virtual environment..."
source venv/bin/activate >> $LOGFILE 2>&1
if [ $? -ne 0 ]; then
echo "Failed to activate the virtual environment."
echo "$(date) - Failed to activate the virtual environment" >> $LOGFILE
read -n 1 -s -r -p "Press any key to exit..."
exit 1
fi
# Check current pip version and upgrade if needed
CURRENT_PIP_VERSION=$(pip --version | awk '{print $2}')
LATEST_PIP_VERSION=$(pip install --upgrade pip 2>&1 | grep 'from version' | awk '{print $6}')
if [ "$CURRENT_PIP_VERSION" != "$LATEST_PIP_VERSION" ]; then
echo "Upgrading pip from $CURRENT_PIP_VERSION to $LATEST_PIP_VERSION..."
pip install --upgrade pip >> $LOGFILE 2>&1
if [ $? -ne 0 ]; then
echo "Failed to upgrade pip. Please check your Python and pip installation."
echo "$(date) - Failed to upgrade pip" >> $LOGFILE
read -n 1 -s -r -p "Press any key to exit..."
exit 1
fi
else
echo "Pip is already up-to-date."
fi
# Check and install requirements
echo "Checking and installing requirements..."
pip freeze > installed_packages.txt
comm -23 <(sort requirements.txt) <(sort installed_packages.txt) > missing_packages.txt
if [ -s missing_packages.txt ]; then
echo "Installing missing requirements... Please wait!"
pip install -r requirements.txt >> $LOGFILE 2>&1
if [ $? -ne 0 ]; then
echo "Failed to install dependencies. Please ensure requirements.txt exists and is correctly formatted."
echo "$(date) - Failed to install dependencies" >> $LOGFILE
read -n 1 -s -r -p "Press any key to exit..."
exit 1
fi
else
echo "All requirements are already installed."
fi
# Run the main script
echo "Running main.py..."
python main.py
if [ $? -ne 0 ]; then
echo "An error occurred while running main.py. Please check the script for errors."
echo "$(date) - Error running main.py" >> $LOGFILE
read -n 1 -s -r -p "Press any key to exit..."
exit 1
fi
echo "Script executed successfully!"