-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfastSetup.sh
147 lines (122 loc) · 4.02 KB
/
fastSetup.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
echo -e "\e[32mEnter your mongo uri: \e[0m"
read mongoUri
echo -e "\e[32mEnter your Alertzy key: \e[0m"
read alertzyKey
echo -e "\e[32mEnter your server ip: \e[0m"
read serverIp
echo "Creating Dockerfile..."
touch Dockerfile
echo "FROM python:3.9" >> Dockerfile
echo "" >> Dockerfile
echo "WORKDIR /app" >> Dockerfile
echo "" >> Dockerfile
echo "ENV MONGO-URI $mongoUri" >> Dockerfile
echo "ENV ALERTZY-KEY $alertzyKey" >> Dockerfile
echo "ENV SERVER-IP $serverIp" >> Dockerfile
echo "" >> Dockerfile
echo "COPY requirements.txt /app/" >> Dockerfile
echo "" >> Dockerfile
echo "RUN pip install --no-cache-dir -r requirements.txt" >> Dockerfile
echo "" >> Dockerfile
echo "COPY main.py /app/" >> Dockerfile
echo "" >> Dockerfile
echo "EXPOSE 8000" >> Dockerfile
echo "" >> Dockerfile
echo 'CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]' >> Dockerfile
echo -e "\e[32mDockerfile created.\e[0m"
echo "Checking for Docker..."
# Check the machine to see if docker is installed
if ! [ -x "$(command -v docker)" ]; then
echo -e "\e[31mError: Docker is not installed.\e[0m"
echo -e "\e[32mHow would you like to install Docker?\e[0m"
echo "[1] Manually"
echo "[2] Snap"
echo "[3] sudo apt-get"
echo "[4] Yum"
echo "[5] Dnf"
echo "[6] Pacman"
echo "[7] Exit"
read installType
# Install docker based on the user's choice
if [ $installType == "1" ]; then
echo -e "\e[32mPlease install Docker manually.\e[0m"
exit 1
elif [ $installType == "2" ]; then
sudo snap refresh
sudo snap install docker
echo -e "\e[32mDocker installed, please re-launch the script.\e[0m"
exit 1
elif [ $installType == "3" ]; then
sudo apt-get install docker
echo -e "\e[32mDocker installed, please re-launch the script.\e[0m"
exit 1
elif [ $installType == "4" ]; then
sudo yum install docker
echo -e "\e[32mDocker installed, please re-launch the script.\e[0m"
exit 1
elif [ $installType == "5" ]; then
sudo dnf install docker
echo -e "\e[32mDocker installed, please re-launch the script.\e[0m"
exit 1
elif [ $installType == "6" ]; then
sudo pacman -S docker
echo -e "\e[32mDocker installed, please re-launch the script.\e[0m"
exit 1
elif [ $installType == "7" ]; then
exit 1
else
echo -e "\e[31mError: Invalid option.\e[0m"
exit 1
fi
else
echo -e "\e[32mDocker is installed.\e[0m"
fi
echo -e "\e[32mBuilding Docker image...\e[0m"
docker build -t dog_walk_api .
echo -e "\e[32mDocker image built.\e[0m"
echo -e "\e[32mRunning Docker image...\e[0m"
docker run -d -p 8000:8000 dog_walk_api
echo -e "\e[32mDocker image running as a background process.\e[0m"
echo -e "\e[32mThe API documentation is available at http://$serverIp:8000/docs\e[0m"
echo -e "\e[32mSetting up cron job...\e[0m"
# Set up cron job to run 0 18 * * 1-5 python3 Dog-Walked-API/reminder.py
# Check the machine to see if cron is installed
if ! [ -x "$(command -v cron)" ]; then
echo -e "\e[31mError: Cron is not installed.\e[0m"
echo -e "\e[32mHow would you like to install Cron?\e[0m"
echo "[1] Manually"
echo "[2] Snap"
echo "[3] sudo apt-get"
echo "[4] Yum"
echo "[5] Dnf"
echo "[6] Pacman"
echo "[7] Exit"
read installType
# Install cron based on the user's choice
if [ $installType == "1" ]; then
echo -e "\e[32mPlease install Cron manually.\e[0m"
exit 1
elif [ $installType == "2" ]; then
sudo snap refresh
sudo snap install cron
elif [ $installType == "3" ]; then
sudo apt-get install cron
elif [ $installType == "4" ]; then
sudo yum install cron
elif [ $installType == "5" ]; then
sudo dnf install cron
elif [ $installType == "6" ]; then
sudo pacman -S cron
elif [ $installType == "7" ]; then
exit 1
else
echo -e "\e[31mError: Invalid option.\e[0m"
exit 1
fi
else
echo -e "\e[32mCron is installed.\e[0m"
fi
# Add the cron job to the crontab
(crontab -l 2>/dev/null; echo "0 18 * * 1-5 python3 Dog-Walked-API/reminder.py") | crontab -
echo -e "\e[32mCron job set up.\e[0m"
echo -e "\e[32mSetup complete.\e[0m"