-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
284 lines (245 loc) Β· 8.89 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
#! /bin/bash
# This script sets up a local development environment on an Ubuntu 20.04/22.04 machine
# to work with Poetry managed Python3.10 projects using Postgresql and Docker.
#
# Targets:
# - Poetry 1.5.1
# - Python3.11.5
# - Postgresql 16
# - Docker 24.0.6
#
# Requirements:
# - Ubuntu 20.04/22.04
# - Python3.7+
#
# -----------------------------------------------------------------------------------------------------------
# 1) Base Requirements: this will ensure that you have ca-certificates, curl, make, and gnupg installed.
# -----------------------------------------------------------------------------------------------------------
# Check if ca-certificates is in the apt-cache
if ( apt-cache show ca-certificates > /dev/null )
then
echo "ca-certificates is already cached π’"
else
sudo apt update
fi
# Ensure ca-certificates package is installed on the machine
if ( which update-ca-certificates > /dev/null )
then
echo "ca-certificates is already installed π’"
else
echo "Installing ca-certificates π"
sudo apt-get install -y ca-certificates
fi
# Check if curl is in the apt-cache
if ( apt-cache show curl > /dev/null )
then
echo "curl is already cached π’"
else
sudo apt update
fi
# Ensure curl is installed on the machine
if ( which curl > /dev/null )
then
echo "curl is already installed π’"
else
echo "Installing curl π"
sudo apt install -y curl
fi
# Check if make is in the apt-cache
if ( apt-cache show make > /dev/null )
then
echo "make is already cached π’"
else
sudo apt update
fi
# Ensure make is installed on the machine
if ( which make > /dev/null )
then
echo "make is already installed π’"
else
echo "Installing make π§"
sudo apt install -y make
fi
# Check if gnupg is in the apt-cache
if ( apt-cache show gpg > /dev/null )
then
echo "gnupg is already cached π’"
else
sudo apt update
fi
# Ensure gnupg is installed on the machine
if ( which gpg > /dev/null )
then
echo "make is already installed π’"
else
echo "Installing gnugp π§"
sudo apt install -y gnupg
fi
# -----------------------------------------------------------------------------------------------------------
# 2) Poetry Install: here we'll install and configure Poetry, as well as add Poetry to the PATH.
# -----------------------------------------------------------------------------------------------------------
# Install Poetry using the official installer
if ( which poetry > /dev/null )
then
echo "Poetry is already installed π’"
else
echo "Installing Poetry π§ββοΈ"
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.5.1 python3 -
fi
# Add Poetry to the path in the current user's .bashrc
if ( poetry --version > /dev/null )
then
echo "Poetry is already in PATH π’"
else
echo -e "# Add Poetry (Python Package Manager) to PATH\nexport PATH="/home/$USER/.local/bin:$PATH"" >> ~/.bashrc
source ~/.bashrc
fi
# Configure Poetry to put build all virtual environments in the project's directory
if [ "$(poetry config virtualenvs.in-project)" == "true" ]
then
echo "Poetry already configured to create virtual envs within projects π’"
else
echo "Configuring Poetry to create virtual envs in projects πͺ"
poetry config virtualenvs.in-project true
fi
# -----------------------------------------------------------------------------------------------------------
# 3) Python3.10 Install: here we'll install Python3.10 - feel free to swap this for any version you'd like.
# -----------------------------------------------------------------------------------------------------------
# Check if software-properties-common is in the apt-cache
if ( apt-cache show software-properties-common > /dev/null )
then
echo "software-properties-common is already cached π’"
else
sudo apt update
fi
# Check for the software-properties-common requirement
if ( dpkg -L software-properties-common > /dev/null )
then
echo "software-properties-common requirement met π’"
else
echo "Installing software-properties-common π§"
sudo apt install -y software-properties-common
fi
# Add this apt repository for Python 3.11.5
if [ -n "$(ls /etc/apt/sources.list.d | grep deadsnakes)" ]
then
echo "ppa:deadsnakes/ppa apt repository present π’"
else
echo "Adding deadsnakes to the apt-repository ππ"
sudo add-apt-repository -y ppa:deadsnakes/ppa
# Refresh the package list again
sudo apt update
fi
# Now you can download Python3.11.5
if ( which python3.11 > /dev/null )
then
echo "Python3.11 already installed π"
else
echo "Installing Python3.11 π§"
sudo apt install -y python3.11
fi
# Verify Python3.11 installation
if ( which python3.11 > /dev/null )
then
echo "$(python3.11 --version) π π β¨"
else
echo "Python 3.11 was not installed successfully π΄"
fi
# -----------------------------------------------------------------------------------------------------------
# 4) PostgreSQL Install: here we'll install PostgreSQL 16
# -----------------------------------------------------------------------------------------------------------
# Check if postgresql-common is in the apt-cache
if ( apt-cache show postgresql-common > /dev/null )
then
echo "postgresql-common is already cached π’"
else
sudo apt update
fi
# Check for the postgresql-common requirement
if ( dpkg -L postgresql-common > /dev/null )
then
echo "postgresql-common requirement met π’"
else
echo "Installing postgresql-common π§"
sudo apt install -y postgresql-common
fi
# Enable the PostgreSQL repository locally
if [ -f /etc/apt/sources.list.d/pgdg.list ]
then
echo 'PostgreSQL repository already installed at /etc/apt/sources.list.d/pgdg.list π’'
else
echo 'Setting up PostgreSQL repository at /etc/apt/sources.list.d/pgdg.list π§'
# Create the /etc/apt/keyrings directory with appropriate permissions
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
# Refresh the package lists
sudo apt update
fi
# Install postgresql
if ( which psql > /dev/null )
then
echo 'PostgreSQL already installed π’'
else
echo 'Installing psql π'
sudo apt install postgresql
fi
# Verfiy PostgreSQL 16 installation
if ( which psql > /dev/null )
then
echo "$(psql --version) π π β¨"
else
echo "PostgresSQL was not installed successfully π΄"
fi
# -----------------------------------------------------------------------------------------------------------
# 5) Docker Install: here we'll install Docker
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# 5.1) Set up the repository: Before you install Docker Engine for the first time on a new host machine,
# you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
# -----------------------------------------------------------------------------------------------------------
# Pull the current machine's distro for GPG key targeting
DISTRO=$(lsb_release -d | awk -F ' ' '{print tolower($2)}')
# Add Dockerβs official GPG key
if [ -f /etc/apt/keyrings/docker.gpg ]
then
echo 'Docker GPG Key already installed at /etc/apt/keyrings/docker.gpg π’'
else
echo 'Installing Docker GPG Key at /etc/apt/keyrings/docker.gpg π§'
# Create the /etc/apt/keyrings directory with appropriate permissions
sudo install -m 0755 -d /etc/apt/keyrings
# Download the GPG key from Docker
curl -fsSL https://download.docker.com/linux/$DISTRO/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
fi
# Set up the repository
if [ -f /etc/apt/sources.list.d/docker.list ]
then
echo 'docker.list repository already exists at /etc/apt/sources.list.d/docker.list π’'
else
echo 'Installing docker.list repository at /etc/apt/sources.list.d/docker.list π§'
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$DISTRO \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
fi
# -----------------------------------------------------------------------------------------------------------
# 5.2) Install Docker Engine
# -----------------------------------------------------------------------------------------------------------
# Check if docker-ce is in the apt-cache
if ( apt-cache show docker-ce > /dev/null )
then
echo "docker-ce is already cached π’"
else
sudo apt update
fi
# Install Docker Engine, containerd, and Docker Compose
if ( docker --version > /dev/null )
then
echo "Docker is already installed π’"
echo "Using $(docker --version)"
else
echo "Installing Docker π³"
# Installs
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Verify that the Docker Engine installation is successful by running the hello-world image
sudo docker run --rm hello-world
fi