-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver_install.sh
465 lines (383 loc) · 16.7 KB
/
server_install.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#!/bin/bash
alias rm=rm
export MAKEFLAGS="-j6"
export LC_ALL="C"
export O_LC=$LC_ALL
export PN="ov"
export DOM="example.com"
export MONTH=$(date +%m)
export YEAR=$(date +%y)
export OVER=$(expr $YEAR - 6) #OdooVersion - computed
[[ 1$MONTH -lt 111 ]] && export OVER=$(expr $OVER - 1) || export OVER=${OVER}
{ #Colors - ref: https://stackoverflow.com/a/5947802
export RED='\033[0;31m'
export GREEN='\033[0;32m'
export BLUE='\033[0;34m'
export LRED='\033[1;31m'
export LGREEN='\033[1;32m'
export LBLUE='\033[1;34m'
export NC='\033[0m' # No Color
}
sayok(){
echo -e "${LGREEN} OK ${NC}"
}
die(){ # Function to print an error and kill the script
export MSG=$1; export ERR=$2;
echo -e "${LRED}Error: $MSG ${NC}" #error msg
echo -e "${LRED}
Something went wrong ...
Plz check the previous messages for errors
and try re-running the installation again.
You may delete $ODIR before restarting.
${NC}"
[[ -n $ERR ]] && exit $ERR || exit 9
}
read -p "Enter Odoo version you want to install (default $OVER): " UV #UserVersion
read -p "Enter Project Name ex: Hajjaj (default ${PN}): " UPN #ProjectName
read -p "Enter Your Main Domain ex: Hajjaj.pro (default ${DOM}): " UDOM #ProjectName
[[ -n $UPN ]] && export PN=$(echo $UPN | sed "s, ,,g")
[[ -n $UDOM ]] && export DOM=$UDOM
if [[ x$UV != x ]]; then
[ $UV -eq 0 ] 2>&1 >/dev/null
if [ $? -eq 2 ]; then
die "Input is not a number, exiting ..." 33
elif [[ $UV -gt $OVER ]]; then
die "version $UV not released yet, exitting ..." 44
else
echo $UV | grep '.0' && export OVER=$(echo $UV | sed "s,\.0,,g") || export OVER=$UV
fi
fi
export AUSR=${PN}$OVER
which apt &>/dev/null && ( useradd -s /bin/bash -m -G adm,sudo $AUSR || die "Failed creating user $AUSR" )
which dnf &>/dev/null && ( useradd -s /bin/bash -m -G wheel $AUSR || die "Failed creating user $AUSR" )
export BWS=$(eval echo ~$AUSR)
{ # Other exports
export PORT1=1$(id -u $AUSR) #Port for multi install
export PORT2=2$(id -u $AUSR) #IM Port for multi install
export aria2c='aria2c -c -x4 -s4'
export OGH="https://github.com/odoo/odoo"
export RQF=${ODIR}/odoo_requirements.txt
export DISTS="Ubuntu: xenial bionic focal, Debian: stretch buster bullseye"
### Config vars
export SFX=$OVER
export VER=${OVER}.0
export ODIR="$BWS/Odoo" # Odoo dir name
export LOGFILE="/$ODIR/Install.log"
mkdir -p $ODIR
export ODSVC=odoo-$PN$SFX
# clean
rm -f $RQF $LOGFILE
# apt based exports
which apt-get &>/dev/null && export DIST=$(lsb_release -c | awk '{print $2}') \
&& ( echo $DISTS | grep -i $DIST &>>$LOGFILE || die "Linux $DIST is not supported, supported debian bases are: $DISTS" )
which apt-get &>/dev/null && export VSURL="https://go.microsoft.com/fwlink/?LinkID=760868" \
&& export WKURL="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb"
# && export WKURL="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.${DIST}_amd64.deb"
# rpm based exports
which dnf &>>$LOGFILE && export VSURL="https://go.microsoft.com/fwlink/?LinkID=760867" \
&& export WKURL="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.centos8.x86_64.rpm"
}
{ # Intro
touch $LOGFILE
echo -e "${LBLUE}
#############################################################
# Welcome to Odoo installer script by
# ${LGREEN}Mohamed M. Hagag https://linkedin.com/in/mohamedhagag${LBLUE}
# released under GPL3 License
#-----------------------------------------------------------
# This should work on ${LGREEN}Ubuntu 18.04+, Debian 9+ & RHEL 8.x .${LBLUE}
# You can set odoo version by calling ${NC}$0 \${VER}$LBLUE
# for ex. $NC# $0 14.0 ${LBLUE}to install odoo v 14.0
#-----------------------------------------------------------
# Now we will install Odoo v.${LRED} $VER $LBLUE
# In$LGREEN $ODIR $LBLUE
# On success:
# - you can re/start odoo by running systemctl start $ODSVC
# - stop odoo by systemctl stop $ODSVC
# - Odoo config file $LGREEN $ODIR/Odoo.conf $LBLUE
# - Odoo will be running on$LRED http://localhost:$PORT1 $LBLUE
############################################################
Press Enter to continue or CTRL+C to exit :
${NC}" | tee -a $LOGFILE && read
}
export shmmax=$(expr $(free | grep Mem | awk '{print $2}') / 2)000
export shmall=$(expr $shmmax / 4096)
cat /etc/sysctl.conf | grep "kernel.shmmax = $shmmax" &>>$LOGFILE \
|| echo "############ Odoo Postgress #########
fs.inotify.max_user_watches = 524288
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = $shmall
kernel.shmmax = $shmmax
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
" | tee -a /etc/sysctl.conf &>>$LOGFILE; sysctl -p &>>$LOGFILE
cat /etc/security/limits.conf | grep ^* &>>$LOGFILE \
|| cat <<EOF >>/etc/security/limits.conf
* soft nproc 304700
* hard nproc 463848
* soft nofile 524288
* hard nofile 524288
EOF
ulimit -a &>>$LOGFILE
cat <<EOF >/tmp/ngxcfg
upstream ${ODSVC} {
server 127.0.0.1:${PORT1};
}
upstream ${ODSVC}-im {
server 127.0.0.1:${PORT2};
}
server {
server_name ${AUSR}.$DOM;
add_header Access-Control-Allow-Origin *;
keepalive_timeout 3010;
keepalive_requests 1024;
client_header_timeout 3010;
client_body_timeout 3010;
send_timeout 3010;
proxy_read_timeout 3000;
proxy_connect_timeout 3000;
proxy_send_timeout 3000;
client_max_body_size 200G;
access_log /var/log/nginx/${ODSVC}-access.log;
error_log /var/log/nginx/${ODSVC}-error.log;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forward-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header X-Forwarded-Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_buffering off;
location /websocket {
proxy_redirect off;
proxy_pass http://${ODSVC}-im;
}
location /longpolling {
proxy_pass http://${ODSVC}-im;
}
location / {
proxy_pass http://${ODSVC};
}
location ~* /web/static/ {
proxy_cache_valid 200 90m;
proxy_buffering on;
expires 864000;
proxy_pass http://${ODSVC};
}
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;
gzip on;
}
EOF
export REQ="https://raw.githubusercontent.com/odoo/odoo/$VER/requirements.txt"
# create user's bin and add it to $PATH
mkdir -p $BWS/bin
cat $BWS/.bashrc | grep "~/bin\|HOME/bin" &>>$LOGFILE || echo "PATH=~/bin:\$PATH:/snap/bin" >>$BWS/.bashrc
cd $BWS
apt_do(){
echo "Updating system ... "
apt-get update &>>$LOGFILE
echo -n "Installing base tools ..."
apt-get install -y --no-install-recommends bash snapd nginx aria2 git wget curl python3-{dev,pip,venv} &>>$LOGFILE && sayok || die "Deps. install Failed"
snap install certbot --classic &>/dev/null &
cd $BWS
$aria2c -o wkhtml.deb "$WKURL" &>>$LOGFILE #|| die "Download WKHTML2PDF failed" &
echo -n "Installing Dependencies ... "
apt-get install -y postgresql sassc node-less npm libxml2-dev libsasl2-dev libldap2-dev \
libxslt1-dev libjpeg-dev libpq-dev cython3 gcc g++ make automake cmake autoconf tcsh \
build-essential &>>$LOGFILE && sayok || die "can not install deps" 11
while $(ps aux | grep wkhtml | grep aria2 &>/dev/null); do sleep 5; done
echo "Installing WKHTML2PDF ... "
which wkhtmltopdf &>>$LOGFILE || apt-get -y install $BWS/wkhtml.deb &>>$LOGFILE
#which wkhtmltopdf &>>$LOGFILE || die "can not install wkhtml2pdf" 777
rm /etc/nginx/sites-enabled/default
cp /tmp/ngxcfg /etc/nginx/sites-available/$ODSVC
ln -s /etc/nginx/sites-available/$ODSVC /etc/nginx/sites-enabled/
systemctl restart nginx &>/dev/null
}
pgdg_el(){
export PGEL8="https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
export PGEL9="https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
cat /etc/passwd | grep postgres &>/dev/null \
|| (
(dnf install -y $PGEL9 || dnf -y install $PGEL8) \
&& dnf -qy module disable postgresql \
&& dnf install -y postgresql16-server \
&& /usr/pgsql-16/bin/postgresql-16-setup initdb \
&& systemctl enable --now postgresql-16 \
&& systemctl start postgresql-16
)
}
dnf_do(){
setenforce 0
source /etc/os-release
echo "INSTALLING GIT ...." && dnf -y install git &>>$LOGFILE
echo $ID_LIKE | grep rhel &>/dev/null \
&& echo "Configuring OS" \
&& (dnf -y install yum-utils &>>$LOGFILE || echo -n) \
&& (dnf config-manager --set-enabled powertools &>>$LOGFILE || dnf config-manager --set-enabled crb &>>$LOGFILE || echo -n ) \
&& dnf -y update &>>$LOGFILE \
&& dnf -y install bash-completion telnet dnf-plugins-core epel-release &>>$LOGFILE \
&& (dnf -y install dnf install epel-next-release &>>$LOGFILE || echo -n) \
&& (which node || dnf -y module enable nodejs:20 &>>$LOGFILE || dnf -y module enable nodejs:18 &>>$LOGFILE) \
&& (which nginx || dnf -y module enable nginx:1.22 &>>$LOGFILE) \
&& (which python3.11 || dnf -y install bash python3.11-{devel,pip,wheel,setuptools} &>>$LOGFILE) \
&& (dnf remove -y python3 &>>$LOGFILE || echo -n) || die "OS Conf Failed"
echo -n "Installing base tools ..."
which nginx &>>$LOGFILE || dnf install -y nginx aria2 wget curl &>>$LOGFILE && sayok || die "Failed"
cd $BWS
# which wkhtmltopdf &>/dev/null || $aria2c -o wkhtml.rpm "$WKURL" &>>$LOGFILE || die "Download WKHTML2PDF failed" &
echo -n "Installing Dependencies ... "
echo $ID_LIKE $VERSION| grep rhel &>/dev/null && pgdg_el &>>$LOGFILE || die "Postgres install Fialed"
dnf -y install libpq5-devel &>>$LOGFILE || dnf -y install libpq-devel &>>$LOGFILE
which npm &>>$LOGFILE || dnf install -y sassc npm libxml2-devel libgsasl-devel openldap-devel \
libxslt-devel libjpeg-devel gcc gcc-c++ make automake cmake autoconf &>>$LOGFILE \
&& sayok || die "can not install deps" 11
echo -n "Setting up postgres ..."
systemctl status --no-pager postgres* &>>$LOGFILE && sayok || \
( /usr/bin/postgresql*setup initdb &>>$LOGFILE && systemctl enable --now postgresql &>>$LOGFILE && sayok ) \
|| die "Postgres setup failed"
while $(ps aux | grep wkhtml | grep aria2 &>/dev/null); do sleep 5; done
echo "Installing WKHTML2PDF ... "
# echo $VERSION_ID | grep '9.' && export WKURL="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox-0.12.6.1-2.almalinux9.x86_64.rpm"
export WKURL="https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.centos8.x86_64.rpm"
# which wkhtmltopdf &>>$LOGFILE || dnf -y install $BWS/wkhtml.rpm &>>$LOGFILE
dnf -y install compat-openssl11 &>>$LOGFILE
wkhtmltopdf -V | grep "12" | grep -i "patch" &>>$LOGFILE || dnf -y install $WKURL &>>$LOGFILE
# which wkhtmltopdf &>>$LOGFILE || die "can not install wkhtml2pdf" 777
rm -f /etc/nginx/conf.d/default
sed -i -e "s,server_name.*,server_name xxx\;,g" /etc/nginx/nginx.conf
sed -i -e "s,default_server,,g" /etc/nginx/nginx.conf
cp /tmp/ngxcfg /etc/nginx/conf.d/${ODSVC}.conf
dnf -y install bash-completion sqlite htop screen nano tcsh &>>$LOGFILE
}
which apt-get &>>$LOGFILE && apt_do
which dnf &>>$LOGFILE && dnf_do
echo -n "Creating venv $BWS ... "
#which apt &>/dev/null && python3 -m venv $BWS || die "can not create VENV in $BWS"
#which dnf &>/dev/null && python3.11 -m venv $BWS || die "can not create VENV in $BWS"
/usr/bin/python3 -m venv $BWS || die "can not create VENV in $BWS"
source $BWS/bin/activate || die "VENV Failed"
# python3 -V | grep 11 || die "python 3.11 failed" ; sleep 3
echo "Cloning odoo git $VER ... "
cd $ODIR || die "$ODIR"
[[ -d odoo ]] || git clone -b $VER --single-branch --depth=1 $OGH &>>$LOGFILE \
|| die "can not download odoo sources" 45 &
curl $REQ | grep -v ==\ \'win32 | sed "s,\#.*,,g" | sort | uniq >$RQF || die "can not get $REQ " 22
echo -n "Creating postgres user for $AUSR ..."
su -s /bin/tcsh -l postgres -c "psql -qtAc '\du'" | grep ^${AUSR}\| &>>$LOGFILE \
&& sayok || ( su -s /bin/tcsh -l postgres -c "createuser -d $AUSR " &>>$LOGFILE && sayok ) || die "Postgres user creation failed"
# install rtlcss requored for RTL support in Odoo
echo -n "Installing rtlcss... "
for pkg in less rtlcss less-plugin-clean-css; do
which $pkg &>>$LOGFILE && sayok || ( npm install -g $pkg &>>$LOGFILE && sayok )
done
echo "Creating start/stop scripts"
echo "#!/bin/bash
find $ODIR/ -type f -name \"*pyc\" -delete
for prc in \$(ps aux | grep -v grep | grep -i \$(basename $ODIR) | grep python | awk '{print \$2}'); do kill -9 \$prc &>/dev/null; done
cd $ODIR && source $BWS/bin/activate && ./odoo/odoo-bin --without-demo=all -c $ODIR/Odoo.conf \$@
" > $ODIR/.start.sh && chmod +x $ODIR/.start.sh || die "can not create start script"
echo "Creating odoo config file ..."
cat <<EOF >$ODIR/Odoo.conf
[options]
addons_path = ${ODIR}/odoo/odoo/addons,${ODIR}/odoo/addons,${ODIR}/my_adds/${AUSR},${ODIR}/my_adds/community,${ODIR}/my_adds/enterprise
admin_passwd = 123@admin
xmlrpc_port = ${PORT1}
longpolling_port = ${PORT2}
limit_time_cpu = 1800
limit_time_real = 3600
log_level = warn
workers = 4
EOF
mkdir -p $ODIR/my_adds/{enterprise,community}
mkdir -p $ODIR/my_adds/${AUSR}
echo asn1crypto >> $RQF
echo phonenumbers >> $RQF
echo pyaml >> $RQF
echo pylint >> $RQF
# link a folder to avoid an error in pip install lxml
ln -sf /usr/include/libxml2/libxml /usr/include/ &>>$LOGFILE
# fix python-ldap build
ln -s /usr/lib64/libldap.so /usr/lib64/libldap_r.so &>/dev/null
echo "Installing Python libraries:"
source $BWS/bin/activate || die "VENV Failed"
# python3 -V | grep 11 || die "python 3.11 failed" ; sleep 3
python3 -m pip install --upgrade pip &>/dev/null
while read line
do
export LMSG=$(echo "$line" | awk '{print $1}')
echo -n " - Installing $LMSG : "
python3 -m pip install "$line" &>>$LOGFILE && sayok || echo Failed\?
# || ( die "$LMSG library install error" )
ls &>/dev/null # To avoid asking for passwd again
done < $RQF
cat <<EOF >/etc/systemd/system/${ODSVC}.service
[Unit]
Description=$ODSVC
After=network.target
[Service]
Restart=always
RestartSec=1
User=$AUSR
Group=$AUSR
ExecStart=$ODIR/.start.sh
ExecReload=/bin/kill -USR1 \$MAINPID
KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s
[Install]
WantedBy=multi-user.target
EOF
source $BWS/bin/activate; pip freeze | grep psycopg2 &>/dev/null || \
(echo "Installing psycopg2" && pip3 install psycopg2-binary &>/dev/null)
chown -R $AUSR: ~$BWS &>/dev/null
systemctl daemon-reload; systemctl enable --now nginx; systemctl enable --now $ODSVC
ps aux | grep git | grep odoo &>>$LOGFILE && echo "Waiting for git clone ..."
while $(ps aux | grep git | grep clone | grep odoo &>>$LOGFILE); do sleep 5; done
which dnf && dnf -y remove python3 &>/dev/null
chown -R $AUSR: $BWS && source $BWS/bin/activate && [[ -d $ODIR ]] && [[ -f $ODIR/odoo/odoo-bin ]] &>>$LOGFILE \
&& echo -e "${LGREEN}
#############################################################
# Looks like everything went well.
# You should now:
# - Have Odoo v$VER In $LRED $ODIR $LGREEN
# - To re/start odoo run $LRED systemctl restart $ODSCV $LGREEN
# - To re/start odoo run $LRED systemctl stop $ODSCV $LGREEN
# - Odoo config file $ODIR/Odoo.conf
# - Odoo addons dirs $ODIR/my_adds/${AUSR} for project addons
# - $ODIR/my_adds/community use it for 3rd party addons
# - $ODIR/my_adds/enterprise use it for EE addons
# - Then access odoo on domain if DNS configured $LRED http://${AUSR}.${DOM} $LGREEN
# - or using IP:PORT $LRED http://$(curl http://ifconfig.me):$PORT1 $LGREEN
#############################################################
${LBLUE}***For best results restart this Server now***$LGREEN
Good luck, ;) .
${NC}" || die "Installation Failed" 1010