File size: 1,387 Bytes
8e25340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4da033f
 
 
8e25340
4da033f
8e25340
4da033f
8e25340
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

VENV_DIR="venv"

#ensure package list
sudo add-apt-repository -y universe
#ensure python and requirements is installed
sudo apt install -qq -y python3-venv
sudo apt install -qq -y python3-pip
sudo apt install -y build-essential
sudo apt install -y gcc g++ 
sudo apt install -y screen


# Check if the virtual environment exists
if [ ! -d "$VENV_DIR" ]; then
  echo "Virtual environment not found. Creating a new one..."
  # Create a virtual environment
  python3 -m venv "$VENV_DIR"
  echo "Virtual environment created."

else
    echo "Virtual environment found."
fi

# Activate the virtual environment
source "$VENV_DIR/bin/activate"
echo "Virtual environment $VENV_DIR activated."

pip install --upgrade pip


if git pull | grep -q 'Already up to date.'; then
    echo "Repository is up to date. Proceeding with setup."

else
    echo "Repository updated successfully. Proceeding to next step."
fi

echo "Checking if http://127.0.0.1:7860 is running..."
if curl -s --head http://127.0.0.1:7860 | grep "200 OK" > /dev/null; then
    echo "URL is running.No further action required. Exiting."
    exit 0  # Exit script since the service is already running
else
    echo "URL is not running.Proceeding with setup."
    # Install dependencies and run the application
    pip install -r requirements.txt

    screen -S "app" -d -m bash -c 'python3 app.py'
fi
deactivate
exit 0