-
Notifications
You must be signed in to change notification settings - Fork 42
/
setup.sh
executable file
·294 lines (263 loc) · 9.03 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/bin/bash
confirm() {
# Function to prompt user for confirmation
while true; do
read -p "$1 (y/n): " yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer yes (y) or no (n).";;
esac
done
}
install_nvm() {
# Load nvm if it's already installed
if [ -s "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh"
elif [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"
fi
if ! command -v nvm &> /dev/null; then
echo "📦 nvm is not installed."
if confirm "Would you like to install nvm?"; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# Load nvm to current shell session
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
echo "✅ nvm has been successfully installed!"
else
echo "⏭️ Skipping nvm installation."
fi
else
echo "✅ nvm is already installed."
fi
}
install_node_with_nvm() {
# Ensure nvm is loaded
if [ -s "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh"
elif [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"
fi
if ! command -v nvm &> /dev/null; then
echo "❌ nvm is not installed. Please install nvm first."
return 1
fi
# Determine the Node.js version to install
if [ -z "$1" ]; then
# Default to latest LTS version if no version is provided
node_version=$(nvm ls-remote --lts | tail -1 | awk '{print $1}')
else
# Use the provided version
node_version="$1"
fi
installed_node=$(nvm ls --no-colors | grep -w "v$node_version")
if [ -n "$installed_node" ]; then
echo "✅ Node.js version $node_version is already installed."
nvm use $node_version
else
if confirm "Would you like to install Node.js version $node_version using nvm?"; then
nvm install $node_version
nvm use $node_version
echo "✅ Node.js $node_version and npm have been successfully installed with nvm!"
else
echo "⏭️ Skipping Node.js installation."
fi
fi
}
detect_package_manager() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt &> /dev/null; then
echo "apt"
elif command -v yum &> /dev/null; then
echo "yum"
elif command -v dnf &> /dev/null; then
echo "dnf"
elif command -v pacman &> /dev/null; then
echo "pacman"
elif command -v zypper &> /dev/null; then
echo "zypper"
else
echo "❌ Unsupported Linux package manager"
return 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew &> /dev/null; then
echo "brew"
else
echo "❌ Homebrew is not installed"
return 1
fi
elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
echo "❌ Windows detected. Please install dependencies manually."
return 1
else
echo "❌ Unsupported OS"
return 1
fi
}
install_dependency() {
local package_manager=$1
local dependency=$2
if ! command -v $dependency &> /dev/null; then
echo "📦 $dependency is not installed."
if confirm "Would you like to install $dependency using $package_manager?"; then
case $package_manager in
apt)
sudo apt update && sudo apt install -y $dependency
;;
yum)
sudo yum install -y $dependency
;;
dnf)
sudo dnf install -y $dependency
;;
pacman)
sudo pacman -S --noconfirm $dependency
;;
zypper)
sudo zypper install -y $dependency
;;
brew)
export HOMEBREW_NO_AUTO_UPDATE=1
brew install $dependency
;;
*)
echo "❌ Unsupported package manager"
return 1
;;
esac
echo "✅ $dependency has been successfully installed!"
else
echo "⏭️ Skipping $dependency installation."
fi
else
echo "✅ $dependency is already installed."
fi
}
install_python_and_pip() {
if command -v python3 &> /dev/null; then
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')
REQUIRED_VERSION="3.9"
# Check if Python version is at least 3.9
if [[ $(echo -e "$PYTHON_VERSION\n$REQUIRED_VERSION" | sort -V | head -n1) == "$REQUIRED_VERSION" ]]; then
echo "✅ Python 3 (version $PYTHON_VERSION) is already installed and meets the required version."
return 0
else
echo "❌ Current Python version ($PYTHON_VERSION) is less than the required 3.9, trying to upgrade it.."
fi
else
echo "❌ Python 3 is not installed."
fi
echo "⚙️ Attempting to install Python 3.9 or higher..."
package_manager=$(detect_package_manager)
if [ $? -eq 0 ]; then
case $package_manager in
apt)
# For Debian/Ubuntu
sudo apt update
sudo apt install -y python3 python3-pip python3-venv
;;
yum)
# For CentOS/RHEL
sudo yum install -y python3 python3-pip python3-virtualenv
;;
dnf)
# For Fedora
sudo dnf install -y python3 python3-pip python3-virtualenv
;;
pacman)
# For Arch Linux
sudo pacman -Sy --noconfirm python python-pip python-virtualenv
;;
zypper)
# For OpenSUSE
sudo zypper install -y python3 python3-pip python3-virtualenv
;;
brew)
# For macOS using Homebrew
export HOMEBREW_NO_AUTO_UPDATE=1
brew install python
;;
*)
echo "❌ Unsupported package manager: $package_manager"
return 1
;;
esac
echo "✅ Python 3, pip, and virtual environment packages have been successfully installed!"
else
echo "❌ Package manager detection failed: $package_manager"
fi
# Check for pip and venv separately as they might not be included with Python
if ! command -v pip3 &> /dev/null; then
echo "📦 pip3 is not installed. Installing..."
install_dependency $package_manager python3-pip
fi
if ! python3 -m venv --help &> /dev/null; then
echo "📦 venv module is not installed. Installing..."
install_dependency $package_manager python3-venv
fi
}
check_and_install_dependencies() {
install_nvm
install_node_with_nvm 22.8.0
install_python_and_pip
}
# Call the function to start the installation process
check_and_install_dependencies
# Ensure PATH is updated
export PATH="$HOME/.local/bin:$PATH"
# Backend setup
cd backend
python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip setuptools wheel
echo "
🐍 Using Python: $(which python3)"
echo "🐍 Using pip: $(which pip3)"
echo "
🔧 Let's set up your environment. You can skip this step and add it to .env later."
echo "🔑 VideoDB API Key (https://console.videodb.io/) (Press Enter to skip)"
read VIDEO_DB_API_KEY
# Create a .env file and add the content
echo "📝 Creating .env file with provided API keys..."
cat <<EOT > .env
VIDEO_DB_API_KEY=$VIDEO_DB_API_KEY
EOT
cd ..
make install-be
make init-sqlite-db
# Frontend setup
cd frontend
echo "
🌳 Using Node@$(node -v): $(which node)"
echo "🌳 Using npm@$(npm -v): $(which npm)"
cat <<EOT > .env
VITE_APP_BACKEND_URL=http://127.0.0.1:8000
VITE_PORT=8080
VITE_OPEN_BROWSER=true
EOT
cd ../
make install-fe
make update-fe
echo "
*******************************************
* *
* 🎉 Setup Completed Successfully! 🎉 *
* *
* 🚀 IMPORTANT: Next Steps 🚀 *
* *
* 1. Review and Update .env File: *
* - Check the newly created .env file *
* - Add VIDEO_DB_API_KEY *
* *
* 2. Start the Application: *
* Run the following command: *
* $ make run *
* *
* 🎉 You're all set! Happy coding! 🎉 *
* *
*******************************************
"