#!/bin/bash################################################################################# Script for installing Odoo on Ubuntu 22.04 LTS (could be used for other version too)# Author: Henry Robert Muwanika#-------------------------------------------------------------------------------# This script will install Odoo on your Ubuntu 22.04 server. It can install multiple Odoo instances# in one Ubuntu because of the different xmlrpc_ports#-------------------------------------------------------------------------------# crontab -e# 43 6 * * * certbot renew --post-hook "systemctl reload nginx"# Make a new file:# sudo nano install_odoo_ubuntu.sh# Place this content in it and then make the file executable:# sudo chmod +x install_odoo_ubuntu.sh# Execute the script to install Odoo:# ./install_odoo_ubuntu.sh################################################################################OE_USER="odoo"OE_HOME="/opt/$OE_USER"OE_HOME_EXT="/opt/$OE_USER/${OE_USER}-server"# The default port where this Odoo instance will run under (provided you use the command -c in the terminal)# Set to true if you want to install it, false if you don't need it or have it already installed.INSTALL_WKHTMLTOPDF="True"# Set the default Odoo port (you still have to use -c /etc/odoo-server.conf for example to use this.)OE_PORT="8069"# Choose the Odoo version which you want to install. For example: 16.0, 15.0 or 14.0. When using 'master' the master version will be installed.# IMPORTANT! This script contains extra libraries that are specifically needed for Odoo 14.0OE_VERSION="17.0"# Set this to True if you want to install the Odoo enterprise version!IS_ENTERPRISE="False"# Set this to True if you want to install Nginx!INSTALL_NGINX="True"# Set the superadmin password - if GENERATE_RANDOM_PASSWORD is set to "True" we will automatically generate a random password, otherwise we use this oneOE_SUPERADMIN="admin"# Set to "True" to generate a random password, "False" to use the variable in OE_SUPERADMINGENERATE_RANDOM_PASSWORD="True"OE_CONFIG="${OE_USER}-server"# Set the website nameWEBSITE_NAME="example.com"# Set the default Odoo longpolling port (you still have to use -c /etc/odoo-server.conf for example to use this.)LONGPOLLING_PORT="8072"# Set to "True" to install certbot and have ssl enabled, "False" to use httpENABLE_SSL="True"# Provide Email to register ssl certificateADMIN_EMAIL="odoo@example.com"####----------------------------------------------------# Disable password authentication#----------------------------------------------------sudosed-i's/#ChallengeResponseAuthentication yes/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config
sudosed-i's/UsePAM yes/UsePAM no/' /etc/ssh/sshd_config
sudosed-i's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo systemctl restart sshd
###--------------------------------------------------# Update Server#--------------------------------------------------echo-e"\n============== Update Server ======================="sudoapt update
sudoapt upgrade -ysudoapt autoremove -y#--------------------------------------------------# Set up the timezones#--------------------------------------------------# set the correct timezone on ubuntu
timedatectl set-timezone Africa/Kigali
timedatectl
#--------------------------------------------------# Install PostgreSQL Server#--------------------------------------------------sudoaptinstall-y postgresql
sudo systemctl start postgresql &&sudo systemctl enable postgresql
echo-e"\n=============== Creating the ODOO PostgreSQL User ========================="sudosu - postgres -c"createuser -s $OE_USER"2> /dev/null ||true#--------------------------------------------------# Install Python Dependencies#--------------------------------------------------echo-e"\n=================== Installing Python Dependencies ============================"sudoaptinstall-ygit python3 python3-dev python3-pip build-essential wget python3-venv python3-wheel python3-cffi libxslt-dev \
libzip-dev libldap2-dev libsasl2-dev python3-setuptools node-less libjpeg-dev gdebi libatlas-base-dev libblas-dev liblcms2-dev \
zlib1g-dev libjpeg8-dev libxrender1
# install libsslsudoapt-yinstall libssl-dev
#--------------------------------------------------# Install Python pip Dependencies#--------------------------------------------------echo-e"\n=================== Installing Python pip Dependencies ============================"sudoaptinstall-y libpq-dev libxml2-dev libxslt1-dev libffi-dev
echo-e"\n================== Install Wkhtmltopdf ============================================="sudoaptinstall-y xfonts-75dpi xfonts-encodings xfonts-utils xfonts-base fontconfig
echo-e"\n================== Install python packages/requirements ============================"sudo pip3 install--upgrade pip
sudo pip3 install setuptools wheel
echo-e"\n=========== Installing nodeJS NPM and rtlcss for LTR support =================="sudocurl-sL https://deb.nodesource.com/setup_20.x |sudo-Ebash -
sudoaptinstall-y nodejs npm-ysudonpminstall-g--upgradenpmsudoln-s /usr/bin/nodejs /usr/bin/node
sudonpminstall-gless less-plugin-clean-css
sudonpminstall-g rtlcss node-gyp
#--------------------------------------------------# Install Wkhtmltopdf if needed#--------------------------------------------------if[$INSTALL_WKHTMLTOPDF="True"];thenecho-e"\n---- Install wkhtmltopdf and place shortcuts on correct place for ODOO 16 ----"### WKHTMLTOPDF download links## === Ubuntu Jammy x64 === (for other distributions please replace this link,## in order to have correct version of wkhtmltopdf installed, for a danger note refer to## https://github.com/odoo/odoo/wiki/Wkhtmltopdf ):## https://www.odoo.com/documentation/16.0/setup/install.html#debian-ubuntusudowget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
sudo dpkg -i wkhtmltox_0.12.6.1-2.jammy_amd64.deb
sudoln-s /usr/local/bin/wkhtmltopdf /usr/bin
sudoln-s /usr/local/bin/wkhtmltoimage /usr/bin
elseecho"Wkhtmltopdf isn't installed due to the choice of the user!"fiecho-e"\n============== Create ODOO system user ========================"sudo adduser --system--quiet--shell=/bin/bash --home=$OE_HOME--gecos'ODOO'--group$OE_USER#The user should also be added to the sudo'ers group.sudo adduser $OE_USERsudoecho-e"\n=========== Create Log directory ================"sudomkdir /var/log/$OE_USERsudochown-R$OE_USER:$OE_USER /var/log/$OE_USER#--------------------------------------------------# Install Odoo from source#--------------------------------------------------echo-e"\n========== Installing ODOO Server ==============="sudogit clone --depth1--branch$OE_VERSION https://www.github.com/odoo/odoo $OE_HOME_EXT/
sudo pip3 install-r /$OE_HOME_EXT/requirements.txt
if[$IS_ENTERPRISE="True"];then# Odoo Enterprise install!sudo pip3 install psycopg2-binary pdfminer.six
echo-e"\n============ Create symlink for node ==============="sudoln-s /usr/bin/nodejs /usr/bin/node
sudosu$OE_USER-c"mkdir $OE_HOME/enterprise"sudosu$OE_USER-c"mkdir $OE_HOME/enterprise/addons"GITHUB_RESPONSE=$(sudogit clone --depth1--branch $OE_VERSION https://www.github.com/odoo/enterprise "$OE_HOME/enterprise/addons"2>&1)while[[$GITHUB_RESPONSE== *"Authentication"* ]];doecho"\n============== WARNING ====================="echo"Your authentication with Github has failed! Please try again."printf"In order to clone and install the Odoo enterprise version you \nneed to be an offical Odoo partner and you need access to\nhttp://github.com/odoo/enterprise.\n"echo"TIP: Press ctrl+c to stop this script."echo"\n============================================="echo" "GITHUB_RESPONSE=$(sudogit clone --depth1--branch $OE_VERSION https://www.github.com/odoo/enterprise "$OE_HOME/enterprise/addons"2>&1)doneecho-e"\n========= Added Enterprise code under $OE_HOME/enterprise/addons ========="echo-e"\n============= Installing Enterprise specific libraries ============"sudo-H pip3 install num2words ofxparse dbfread ebaysdk firebase_admin pyOpenSSL
sudonpminstall-g less-plugin-clean-css
fiecho-e"\n========= Create custom module directory ============"sudosu$OE_USER-c"mkdir $OE_HOME/custom"sudosu$OE_USER-c"mkdir $OE_HOME/custom/addons"echo-e"\n======= Setting permissions on home folder =========="sudochown-R$OE_USER:$OE_USER$OE_HOME/
echo-e"\n========== Create server config file ============="sudotouch /etc/${OE_CONFIG}.conf
echo-e"\n============= Creating server config file ==========="sudosu root -c"printf '[options] \n; This is the password that allows database operations:\n' >> /etc/${OE_CONFIG}.conf"if[$GENERATE_RANDOM_PASSWORD="True"];thenecho-e"\n========= Generating random admin password ==========="OE_SUPERADMIN=$(cat /dev/urandom |tr-dc'a-zA-Z0-9'|fold-w20|head-n1)fisudosu root -c"printf 'admin_passwd = ${OE_SUPERADMIN}\n' >> /etc/${OE_CONFIG}.conf"if[$OE_VERSION>"11.0"];thensudosu root -c"printf 'http_port = ${OE_PORT}\n' >> /etc/${OE_CONFIG}.conf"elsesudosu root -c"printf 'xmlrpc_port = ${OE_PORT}\n' >> /etc/${OE_CONFIG}.conf"fisudosu root -c"printf 'logfile = /var/log/${OE_USER}/${OE_CONFIG}.log\n' >> /etc/${OE_CONFIG}.conf"if[$IS_ENTERPRISE="True"];thensudosu root -c"printf 'addons_path=${OE_HOME}/enterprise/addons,${OE_HOME_EXT}/addons\n' >> /etc/${OE_CONFIG}.conf"elsesudosu root -c"printf 'addons_path=${OE_HOME_EXT}/addons,${OE_HOME}/custom/addons\n' >> /etc/${OE_CONFIG}.conf"fi# echo -e "\n======== Adding Enterprise or custom modules ============="if[$IS_ENTERPRISE="True"];then#### upgrade odoo community to enterprise edition ##### Odoo 15: https://www.soladrive.com/downloads/enterprise-15.0.tar.gzecho-e"\n======== Adding some enterprise modules ============="wget https://www.soladrive.com/downloads/enterprise-15.0.tar.gz
tar-zxvf enterprise-15.0.tar.gz
cp-rf odoo-15.0*/odoo/addons/* ${OE_HOME}/enterprise/addons
rm enterprise-15.0.tar.gz
chown-R$OE_USER:$OE_USER${OE_HOME}/
fisudochown$OE_USER:$OE_USER /etc/${OE_CONFIG}.conf
sudochmod640 /etc/${OE_CONFIG}.conf
#--------------------------------------------------# Adding Odoo as a deamon (Systemd)#--------------------------------------------------echo-e"\n========== Create Odoo systemd file ==============="cat<<EOF> /lib/systemd/system/$OE_USER.service
[Unit]
Description=Odoo Open Source ERP and CRM
After=network.target
[Service]
Type=simple
User=$OE_USER
Group=$OE_USER
ExecStart=$OE_HOME_EXT/odoo-bin --config /etc/${OE_CONFIG}.conf --logfile /var/log/${OE_USER}/${OE_CONFIG}.log
KillMode=mixed
[Install]
WantedBy=multi-user.target
EOFsudochmod755 /lib/systemd/system/$OE_USER.service
sudochown root: /lib/systemd/system/$OE_USER.service
echo-e"\n======== Odoo startup File ============="sudo systemctl daemon-reload
sudo systemctl enable--now$OE_USER.service
sudo systemctl start $OE_USER.service
sudo systemctl restart $OE_USER.service
#--------------------------------------------------# Install Nginx if needed#--------------------------------------------------echo-e"\n======== Installing nginx ============="if[$INSTALL_NGINX="True"];thenecho-e"\n---- Installing and setting up Nginx ----"sudoaptinstall-y nginx
sudo systemctl enable nginx
cat<<EOF> /etc/nginx/sites-available/$OE_USER
# odoo server
upstream $OE_USER {
server 127.0.0.1:$OE_PORT;
}
upstream ${OE_USER}chat {
server 127.0.0.1:$LONGPOLLING_PORT;
}
server {
listen 80;
server_name $WEBSITE_NAME;
# Specifies the maximum accepted body size of a client request,
# as indicated by the request header Content-Length.
client_max_body_size 500M;
# log
access_log /var/log/nginx/$OE_USER-access.log;
error_log /var/log/nginx/$OE_USER-error.log;
# add ssl specific settings
keepalive_timeout 90;
# increase proxy buffer to handle some Odoo web requests
proxy_buffers 16 64k;
proxy_buffer_size 128k;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Add Headers for odoo proxy mode
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header X-Real-IP \$remote_addr;
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://$OE_USER;
}
# Redirect longpoll requests to odoo longpolling port
location /longpolling {
proxy_pass http://${OE_USER}chat;
}
# cache some static data in memory for 90mins
# under heavy load this should relieve stress on the Odoo web interface a bit.
location ~* /web/static/ {
proxy_cache_valid 200 90m;
proxy_buffering on;
expires 864000;
proxy_pass http://$OE_USER;
}
# common gzip
gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
gzip on;
}
EOFsudomv ~/odoo /etc/nginx/sites-available/
sudoln-s /etc/nginx/sites-available/$OE_USER /etc/nginx/sites-enabled/$OE_USERsudorm /etc/nginx/sites-enabled/default
sudorm /etc/nginx/sites-available/default
sudo systemctl reload nginx
sudosu root -c"printf 'proxy_mode = True\n' >> /etc/${OE_CONFIG}.conf"echo"Done! The Nginx server is up and running. Configuration can be found at /etc/nginx/sites-available/$OE_USER"elseecho"\n===== Nginx isn't installed due to choice of the user! ========"fi#--------------------------------------------------# Enable ssl with certbot#--------------------------------------------------if[$INSTALL_NGINX="True"]&&[$ENABLE_SSL="True"]&&[$WEBSITE_NAME!="example.com"];thensudoapt-get remove certbot
sudo snap install core
sudo snap refresh core
sudo snap install--classic certbot
sudoln-s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx-d$WEBSITE_NAMEsudo systemctl reload nginx
echo"\n============ SSL/HTTPS is enabled! ========================"elseecho"\n==== SSL/HTTPS isn't enabled due to choice of the user or because of a misconfiguration! ======"fi#--------------------------------------------------# UFW Firewall#--------------------------------------------------sudoaptinstall-y ufw
sudo ufw allow 'Nginx Full'sudo ufw allow 'Nginx HTTP'sudo ufw allow 'Nginx HTTPS'sudo ufw allow 22/tcp
sudo ufw allow 6010/tcp
#sudo ufw allow 5432//tcpsudo ufw allow 8069/tcp
sudo ufw allow 8072/tcp
sudo ufw enableecho-e"\n================== Status of Odoo Service ============================="sudo systemctl status $OE_USERecho"\n========================================================================="echo"Done! The Odoo server is up and running. Specifications:"echo"Port: $OE_PORT"echo"User service: $OE_USER"echo"User PostgreSQL: $OE_USER"echo"Code location: $OE_USER"echo"Addons folder: $OE_USER/$OE_CONFIG/addons/"echo"Password superadmin (database): $OE_SUPERADMIN"echo"Start Odoo service: sudo systemctl start $OE_USER"echo"Stop Odoo service: sudo systemctl stop $OE_USER"echo"Restart Odoo service: sudo systemctl restart $OE_USER"if[$INSTALL_NGINX="True"];thenecho"Nginx configuration file: /etc/nginx/sites-available/$OE_USER"fiecho-e"\n========================================================================="