This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
107 lines (91 loc) · 3.1 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
#!/bin/zsh
# This script is used to help the user setup the entire project
banner=$(cat << "EOF"
-------------------------------------
_____ __
/ ____| / _|
| (___ _ __ ___ ___ | |_ _ _
\___ \| '_ \ / _ \ / _ \| _| | | |
____) | |_) | (_) | (_) | | | |_| |
|_____/| .__/ \___/ \___/|_| \__, |
| | __/ |
|_| |___/
-------------------------------------
EOF
)
echo "$banner"
echo "Welcome to the Spoofy setup script!"
echo "Press any key to continue..."
read -n 1 -s
# Function to check if the port is valid
is_valid_port() {
local port=$1
if [[ $port =~ ^[0-9]+$ ]] && [ $port -ge 1 ] && [ $port -le 65535 ]; then
return 0
else
return 1
fi
}
# Check if Docker is running
DOCKER_INSTALLED=$(docker info > /dev/null 2>&1)
if [ -n "$DOCKER_INSTALLED" ]; then
echo "Docker is installed and running."
echo "Proceeding with Docker setup..."
# Setup the Docker container
docker build -t spoofy .
# Ask the user for the port (default is 8080)
echo "Please enter the port for the Docker container (default is 8080):"
read -p "" port
port=${port:-8080}
# Validate the port
while ! is_valid_port $port; do
echo "Invalid port. Please enter a port number between 1 and 65535:"
read -p "" port
port=${port:-8080}
done
echo "Starting Spoofy container on port $port..."
docker run -p $port:$port --name spoofy spoofy
else
# Setup a local environment
echo "It appears that Docker is not installed or the Docker daemon is not running."
echo "Would you like to setup a local environment instead? (y/n)"
while true; do
read -p "" yn
case $yn in
[Yy]* ) echo "Setting up local environment..."; break;;
[Nn]* ) echo "Exiting..."; exit;;
* ) echo "Please answer 'y' or 'n'.";;
esac
done
# Check if Python 3 is installed
PYTHON_INSTALLED=$(python3 --version > /dev/null 2>&1)
if [ -n "$PYTHON_INSTALLED" ]; then
echo "Python 3 installation found. Proceeding..."
else
echo "Python 3 is not installed. Please install Python 3.10 or higher."
echo "Exiting..."
exit
fi
# Ask the user for the host (default is 127.0.0.1)
echo "Please enter the host for the local environment (default is 127.0.0.1):"
read -p "" host
host=${host:-127.0.0.1}
# Ask the user for the port (default is 8080)
echo "Please enter the port for the local environment (default is 8080):"
read -p "" port
port=${port:-8080}
# Validate the port
while ! is_valid_port $port; do
echo "Invalid port. Please enter a port number between 1 and 65535:"
read -p "" port
port=${port:-8080}
done
# Setup python virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip3 install -r requirements.txt
# Run the app with the user's configuration
echo "Starting Spoofy on $host:$port..."
.venv/bin/python start.py -b $host -p $port
fi