-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
115 lines (95 loc) · 3.48 KB
/
setup.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# setup.sh
#!/bin/bash
# Function to check if command exists
check_command() {
if ! command -v $1 &> /dev/null; then
echo -e "[!]\t$1 could not be found"
return 1
else
echo -e "[✓]\t$1 is installed"
return 0
fi
}
install_debian() {
echo -e "[i]\tUpdating package lists..."
sudo apt-get update || { echo -e "[!]\tFailed to update package lists"; exit 1; }
echo -e "[i]\tInstalling Python3-OpenCV, venv..."
sudo apt-get install -y python3-opencv python3-venv || { echo -e "[!]\tFailed to install required packages"; exit 1; }
check_command python3
check_command pip3
}
install_rhel() {
echo -e "[i]\tChecking for updates..."
sudo dnf check-update
local check_update_status=$?
if [ $check_update_status -eq 1 ]; then
echo -e "[!]\tFailed to check for updates"
exit 1
fi
check_command python3
check_command pip3
}
install_opensuse() {
echo -e "[i]\tUpdating package lists..."
sudo zypper refresh || { echo -e "[!]\tFailed to update package lists"; exit 1; }
echo -e "[i]\tInstalling Python3-OpenCV, python3"
sudo zypper install -y python3-opencv python3 python3-pip || { echo -e "[!]\tFailed to install required packages"; exit 1; }
check_command python3
check_command pip3
}
install_macos() {
if ! check_command brew; then
echo -e "[!]\tHomebrew is required for macOS. Please install it first."
exit 1
fi
echo -e "[i]\tUpdating Homebrew..."
brew update || { echo -e "[!]\tFailed to update Homebrew"; exit 1; }
echo -e "[i]\tInstalling OpenCV, Python"
brew install opencv python || { echo -e "[!]\tFailed to install required packages"; exit 1; }
check_command python3
check_command pip3
}
# Detect system type and run appropriate function
if [ -f /etc/debian_version ]; then
echo -e "[i]\tDetected Debian-based system."
install_debian
elif [ -f /etc/redhat-release ]; then
echo -e "[i]\tDetected RHEL-based system."
install_rhel
elif [ -f /etc/SuSE-release ] || [ -f /etc/SUSE-brand ]; then
echo -e "[i]\tDetected openSUSE system."
install_opensuse
elif [ "$(uname)" == "Darwin" ]; then
echo -e "[i]\tDetected macOS."
install_macos
else
echo -e "[!]\tYour system is not supported by this script."
exit 1
fi
# Check if venv exists, if not create it
VENV_DIR="./venv"
if [ ! -d "$VENV_DIR" ]; then
echo -e "[i]\tCreating virtual environment..."
python3 -m venv $VENV_DIR || { echo -e "[!]\tFailed to create virtual environment"; exit 1; }
fi
# Activate virtual environment
echo -e "[i]\tActivating virtual environment..."
source $VENV_DIR/bin/activate || { echo -e "[!]\tFailed to activate virtual environment"; exit 1; }
# Upgrade pip
echo -e "[i]\tUpgrading pip..."
pip install --upgrade pip || { echo -e "[!]\tFailed to upgrade pip"; exit 1; }
# Install packages from requirements.txt
if [ -f "requirements.txt" ]; then
echo -e "[i]\tInstalling packages from requirements.txt..."
pip install -r requirements.txt || { echo -e "[!]\tFailed to install packages from requirements.txt"; exit 1; }
else
echo -e "[!]\trequirements.txt not found. Skipping package installation."
fi
echo -e "[i]\tVerifying OpenCV installation..."
if python -c "import cv2; print(cv2.__version__)" 2>/dev/null; then
echo -e "[✓]\tOpenCV installed successfully"
else
echo -e "[!]\tOpenCV installation verification failed"
exit 1
fi
echo -e "[i]\tInstallation complete. Virtual environment and packages are installed."