Skip to content

Instantly share code, notes, and snippets.

@sniper7kills
Last active July 30, 2016 13:36
Show Gist options
  • Save sniper7kills/0276a483db1cc30c4c03 to your computer and use it in GitHub Desktop.
Save sniper7kills/0276a483db1cc30c4c03 to your computer and use it in GitHub Desktop.
Odoo Install with reverse Proxy
#!/bin/bash
################################################################################
# Script for Installation: ODOO Saas4/Trunk server on Ubuntu 14.04 LTS
# Author: André Schenkels, ICTSTUDIO 2014
# Updated by: Will Gaudette, CMIT 14MAR15
#-------------------------------------------------------------------------------
#
# This script will install ODOO Server and a reverse Nginx proxy on a
# clean Ubuntu 14.04 Server
#-------------------------------------------------------------------------------
# USAGE:
#
# odoo-install
#
# EXAMPLE:
# ./odoo-install
#
################################################################################
##
# This should be set to the full path where Odoo server installations go.
##
OE_MAIN="/opt"
##
#
##
################################################################################
# DO NOT EDIT BELLOW THIS LINE
#
# Some Helper Functions
################################################################################
clear
confirm () {
# call with a prompt string or use a default
echo "CMIT # ${1}"
read -r -p "CMIT [Y/n/q] > " answer
case "${answer}" in
[yY]|[yY][eE][sS]) GO=false ;;
[nN]|[nN][oO]) GO=true ;;
[qQ]|[qQ][uU][iI][tT]) exit 1 ;;
esac
}
################################################################################
# DO NOT EDIT BELLOW THIS LINE
#
# Prompt For Some Information
################################################################################
GO=true
#System User To Run Under
while $GO; do
OE_USER=
while (id -u $OE_USER > /dev/null 2>&1); do
echo "CMIT # What user will this run under?"
read -r -p "CMIT > " OE_USER
if id -u $OE_USER > /dev/null 2>&1; then
echo "CMIT # Bad User Name. Try Again"
fi
done
clear
confirm "Continue installing using '$OE_USER' as the server name?"
clear
done
GO=true
#URL To Respond To On Port 80
while $GO; do
echo "CMIT # What URL or IP address should we respond to?"
read -r -p "CMIT > " OE_URL
clear
confirm "Continue using http://$OE_URL/ as the URL?"
clear
done
GO=true
#Port This Instance of Odoo Runs On. Doesn't have to be public
while $GO; do
OE_PORT=80
while (echo >/dev/tcp/127.0.0.1/$OE_PORT >/dev/null -ne 0); do
echo "CMIT # What port should we use?"
read -r -p "CMIT [8069] > " OE_PORT
(echo >/dev/tcp/127.0.0.1/$OE_PORT) &>/dev/null
if [ $? -eq 0 ]; then
echo "CMIT # Port In Use. Try Again"
fi
done
clear
confirm "Continue installing using '$OE_PORT' as the server port?"
clear
done
GO=true
#Branch used for getting code
while $GO; do
echo "CMIT # What Version should we use?"
read -r -p "CMIT [8.0/7.0/master] > " OE_VERSION
clear
confirm "Continue installing using '$OE_VERSION' branch?"
clear
done
GO=true
#SuperAdmin Password
#TODO Better Input Confirmation
while $GO; do
OE_SUPERADMIN=
echo "CMIT # What should the Super Admin password be?"
read -r -p "CMIT [admin] > " OE_SUPERADMIN
clear
confirm "Use '$OE_SUPERADMIN' as the Database Master Password?"
clear
done
GO=true
clear
##
# Some Hard Coded Paths
##
OE_HOME="$OE_MAIN/$OE_USER"
OE_CONFIG="$OE_USER-server"
OE_HOME_EXT="$OE_MAIN/$OE_USER/$OE_CONFIG"
NGINX_CONFIG="/etc/nginx/sites-available/$OE_CONFIG"
##
# Lets Update The Server
##
echo "CMIT # Please wait while we update the system."
sudo apt-get update &>/dev/null
sudo apt-get upgrade -y &>/dev/null
if [ -e "$OE_MAIN/CMIT-ODOO-INSTALLED" ]
then
echo "CMIT # Skipping Dependency And Requirement Installs."
else
##
# Install PostgreSQL Server
##
echo "CMIT # Please wait while we install the PostgreSQL Server."
sudo apt-get install postgresql -y &>/dev/null
# PostgreSQL Server Configuration
sudo sed -i s/"#listen_addresses = 'localhost'"/"listen_addresses = '*'"/g /etc/postgresql/9.3/main/postgresql.conf
##
# Install Nginx Server
##
echo "CMIT # Please wait while we install the Nginx Server."
sudo apt-get install nginx -y &>/dev/null
##
# Install Dependencies
##
echo "CMIT # Please wait while we install tool packages."
sudo apt-get install wget subversion git bzr bzrtools python-pip -y &>/dev/null
echo "CMIT # Please wait while we install python packages."
sudo apt-get install python-dateutil python-feedparser python-ldap python-libxslt1 python-lxml python-mako python-openid python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi python-docutils python-psutil python-mock python-unittest2 python-jinja2 python-pypdf python-decorator python-requests python-passlib python-pil -y &>/dev/null
echo "CMIT # Please wait while we install python libraries."
sudo pip install gdata &>/dev/null
echo "CMIT # Please wait while we install wkhtml and place it in correct then place for ODOO."
sudo wget http://downloads.sourceforge.net/project/wkhtmltopdf/archive/0.12.1/wkhtmltox-0.12.1_linux-trusty-amd64.deb &>/dev/null
sudo dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb &>/dev/null
sudo rm wkhtmltox-0.12.1_linux-trusty-amd64.deb
sudo cp /usr/local/bin/wkhtmltopdf /usr/bin
sudo cp /usr/local/bin/wkhtmltoimage /usr/bin
echo "CMIT # Please wait while we install Node-less."
sudo apt-get install node-less -y &>/dev/null
##
# Install Extra Modules
##
echo "CMIT # Please wait while we add some shared addons."
mkdir $OE_MAIN/odoo-shared-addons
mkdir $OE_MAIN/odoo-addons-src
# Server Tools
sudo git clone https://github.com/OCA/server-tools.git $OE_MAIN/odoo-addons-src/server-tools &>/dev/null
sudo ln -s $OE_MAIN/odoo-addons-src/server-tools/* $OE_MAIN/odoo-shared-addons/
sudo cp $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py.bak
head -n -1 $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py.bak > $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py
echo " \"auto_install\": True," >> $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py
echo "}" >> $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py
# Multi-Image for products
sudo git clone -b 8.0 https://github.com/OdooCommunityWidgets/website_multi_image.git $OE_MAIN/odoo-addons-src/website_multi_image &>/dev/null
sudo ln -s $OE_MAIN/odoo-addons-src/website_multi_image/website_multi_image $OE_MAIN/odoo-shared-addons/
# Server Tools
echo date > $OE_MAIN/CMIT-ODOO-INSTALLED
fi
##
# Create system user
##
echo "CMIT # Please wait while we create the ODOO system user."
sudo adduser --system --quiet --shell=/bin/bash --home=$OE_HOME --gecos 'ODOO' --group $OE_USER
##
# Create ODOO PostgreSQL User
##
sudo su - postgres -c "createuser -s $OE_USER" 2> /dev/null || true
##
# Create Log Directory
##
echo "CMIT # Please wait while we create the Log Directory."
sudo mkdir /var/log/$OE_USER
sudo chown $OE_USER:$OE_USER /var/log/$OE_USER
ln -s /var/log/$OE_USER $OE_HOME/logs
##
# Install Odoo
##
echo "CMIT # Please wait while we clone the server files."
sudo git clone --branch $OE_VERSION https://www.github.com/odoo/odoo $OE_HOME_EXT/ &>/dev/null
sudo su $OE_USER -c "mkdir $OE_HOME/custom"
sudo su $OE_USER -c "mkdir $OE_HOME/custom/addons"
sudo chown -R $OE_USER:$OE_USER $OE_HOME/*
##
# Install Extra Modules
##
echo "CMIT # Please wait while we add some shared addons."
mkdir $OE_MAIN/odoo-shared-addons
mkdir $OE_MAIN/odoo-addons-src
sudo git clone https://github.com/OCA/server-tools.git $OE_MAIN/odoo-addons-src/server-tools &>/dev/null
sudo ln -s $OE_MAIN/odoo-addons-src/server-tools/* $OE_MAIN/odoo-shared-addons/
sudo cp $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py.bak
head -n -1 $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py.bak > $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py
echo " \"auto_install\": True," >> $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py
echo "}" >> $OE_MAIN/odoo-addons-src/server-tools/disable_openerp_online/__openerp__.py
##
# Configure Odoo
##
echo "CMIT # Please wait while we configure Odoo."
sudo su root -c "echo '[options]' > $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo '; This is the password that allows database operations:' >> $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo 'admin_passwd = $OE_SUPERADMIN' >> $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo 'db_host = False' >> $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo 'db_port = False' >> $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo 'db_user = $OE_USER' >> $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo 'db_password = False' >> $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo 'logfile = /var/log/$OE_USER/$OE_CONFIG$1.log' >> $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo 'addons_path = $OE_HOME_EXT/addons,$OE_HOME/custom/addons,$OE_MAIN/odoo-shared-addons' >> $OE_HOME/$OE_CONFIG.conf"
sudo su root -c "echo 'xmlrpc_port = $OE_PORT' >> $OE_HOME/$OE_CONFIG.conf"
sudo chown $OE_USER:$OE_USER $OE_HOME/$OE_CONFIG.conf
sudo chmod 640 $OE_HOME/$OE_CONFIG.conf
##
# Configure Odoo as a daemon
##
echo "CMIT # Please wait while we configure the Odoo daemon."
echo '#!/bin/sh' >> ~/$OE_CONFIG
echo '### BEGIN INIT INFO' >> ~/$OE_CONFIG
echo '# Provides: $OE_CONFIG' >> ~/$OE_CONFIG
echo '# Required-Start: $remote_fs $syslog' >> ~/$OE_CONFIG
echo '# Required-Stop: $remote_fs $syslog' >> ~/$OE_CONFIG
echo '# Should-Start: $network' >> ~/$OE_CONFIG
echo '# Should-Stop: $network' >> ~/$OE_CONFIG
echo '# Default-Start: 2 3 4 5' >> ~/$OE_CONFIG
echo '# Default-Stop: 0 1 6' >> ~/$OE_CONFIG
echo '# Short-Description: Enterprise Business Applications' >> ~/$OE_CONFIG
echo '# Description: ODOO Business Applications' >> ~/$OE_CONFIG
echo '### END INIT INFO' >> ~/$OE_CONFIG
echo 'PATH=/bin:/sbin:/usr/bin' >> ~/$OE_CONFIG
echo "DAEMON=$OE_HOME_EXT/openerp-server" >> ~/$OE_CONFIG
echo "NAME=$OE_CONFIG" >> ~/$OE_CONFIG
echo "DESC=$OE_CONFIG" >> ~/$OE_CONFIG
echo '' >> ~/$OE_CONFIG
echo '# Specify the user name (Default: odoo).' >> ~/$OE_CONFIG
echo "USER=$OE_USER" >> ~/$OE_CONFIG
echo '' >> ~/$OE_CONFIG
echo '# Specify an alternate config file (Default: /etc/openerp-server.conf).' >> ~/$OE_CONFIG
echo "CONFIGFILE=\"$OE_HOME/$OE_CONFIG.conf\"" >> ~/$OE_CONFIG
echo '' >> ~/$OE_CONFIG
echo '# pidfile' >> ~/$OE_CONFIG
echo 'PIDFILE=$OE_HOME/$NAME.pid' >> ~/$OE_CONFIG
echo '' >> ~/$OE_CONFIG
echo '# Additional options that are passed to the Daemon.' >> ~/$OE_CONFIG
echo 'DAEMON_OPTS="-c $CONFIGFILE"' >> ~/$OE_CONFIG
echo '[ -x $DAEMON ] || exit 0' >> ~/$OE_CONFIG
echo '[ -f $CONFIGFILE ] || exit 0' >> ~/$OE_CONFIG
echo 'checkpid() {' >> ~/$OE_CONFIG
echo '[ -f $PIDFILE ] || return 1' >> ~/$OE_CONFIG
echo 'pid=`cat $PIDFILE`' >> ~/$OE_CONFIG
echo '[ -d /proc/$pid ] && return 0' >> ~/$OE_CONFIG
echo 'return 1' >> ~/$OE_CONFIG
echo '}' >> ~/$OE_CONFIG
echo '' >> ~/$OE_CONFIG
echo 'case "${1}" in' >> ~/$OE_CONFIG
echo 'start)' >> ~/$OE_CONFIG
echo 'echo -n "Starting ${DESC}: "' >> ~/$OE_CONFIG
echo 'start-stop-daemon --start --quiet --pidfile ${PIDFILE} \' >> ~/$OE_CONFIG
echo '--chuid ${USER} --background --make-pidfile \' >> ~/$OE_CONFIG
echo '--exec ${DAEMON} -- ${DAEMON_OPTS}' >> ~/$OE_CONFIG
echo 'echo "${NAME}."' >> ~/$OE_CONFIG
echo ';;' >> ~/$OE_CONFIG
echo 'stop)' >> ~/$OE_CONFIG
echo 'echo -n "Stopping ${DESC}: "' >> ~/$OE_CONFIG
echo 'start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \' >> ~/$OE_CONFIG
echo '--oknodo' >> ~/$OE_CONFIG
echo 'echo "${NAME}."' >> ~/$OE_CONFIG
echo ';;' >> ~/$OE_CONFIG
echo '' >> ~/$OE_CONFIG
echo 'restart|force-reload)' >> ~/$OE_CONFIG
echo 'echo -n "Restarting ${DESC}: "' >> ~/$OE_CONFIG
echo 'start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \' >> ~/$OE_CONFIG
echo '--oknodo' >> ~/$OE_CONFIG
echo 'sleep 1' >> ~/$OE_CONFIG
echo 'start-stop-daemon --start --quiet --pidfile ${PIDFILE} \' >> ~/$OE_CONFIG
echo '--chuid ${USER} --background --make-pidfile \' >> ~/$OE_CONFIG
echo '--exec ${DAEMON} -- ${DAEMON_OPTS}' >> ~/$OE_CONFIG
echo 'echo "${NAME}."' >> ~/$OE_CONFIG
echo ';;' >> ~/$OE_CONFIG
echo '*)' >> ~/$OE_CONFIG
echo 'N=/etc/init.d/${NAME}' >> ~/$OE_CONFIG
echo 'echo "Usage: ${NAME} {start|stop|restart|force-reload}" >&2' >> ~/$OE_CONFIG
echo 'exit 1' >> ~/$OE_CONFIG
echo ';;' >> ~/$OE_CONFIG
echo '' >> ~/$OE_CONFIG
echo 'esac' >> ~/$OE_CONFIG
echo 'exit 0' >> ~/$OE_CONFIG
sudo mv ~/$OE_CONFIG /etc/init.d/$OE_CONFIG
sudo chmod 755 /etc/init.d/$OE_CONFIG
sudo chown root: /etc/init.d/$OE_CONFIG
##
# Configure Odoo to start on boot
##
echo "CMIT # Please wait while we configure the Odoo daemon to start on boot."
sudo update-rc.d $OE_CONFIG defaults &>/dev/null
##
# Start the server
##
sudo service $OE_CONFIG start &>/dev/null
echo "CMIT # Odoo Started."
##
# Give User Permissions to control server
##
echo "$OE_USER ALL = NOPASSWD: /usr/sbin/service $OE_CONFIG *" | (EDITOR="tee -a" visudo) &>/dev/null
##
# Reverse Proxy Setup
##
echo "CMIT # Please wait while we configure the Reverse Proxy."
cd /etc/nginx
##
# Warning... You need to pay attention again
##
clear
echo "################################################################################"
echo "# CMIT WARNING"
echo "#"
echo "# YOUR ABOUT TO CREATE A SSL Cert"
echo "# YOU CAN REPLACE IT AT"
echo "# /etc/nginx/$OE_CONFIG.key"
echo "# /etc/nginx/$OE_CONFIG.crt"
echo "#"
echo "# Press Any Key To Continue"
echo "#"
echo "# Enter works if you can't find the Any Key"
echo "#"
echo -n "################################################################################"
read -n 1
##
# Generate the SSL Cert
##
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/$OE_CONFIG.key -out /etc/nginx/$OE_CONFIG.crt
##
# Nginx Config File
##
sudo echo "server {" > $NGINX_CONFIG
sudo echo " listen 443;" >> $NGINX_CONFIG
sudo echo " server_name $OE_URL;" >> $NGINX_CONFIG
sudo echo " ssl_certificate /etc/nginx/$OE_CONFIG.crt;" >> $NGINX_CONFIG
sudo echo " ssl_certificate_key /etc/nginx/$OE_CONFIG.key;" >> $NGINX_CONFIG
sudo echo " ssl on;" >> $NGINX_CONFIG
sudo echo " ssl_session_cache builtin:1000 shared:SSL:10m;" >> $NGINX_CONFIG
sudo echo " ssl_protocols TLSv1 TLSv1.1 TLSv1.2;" >> $NGINX_CONFIG
sudo echo " ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;" >> $NGINX_CONFIG
sudo echo " ssl_prefer_server_ciphers on;" >> $NGINX_CONFIG
sudo echo " access_log /var/log/nginx/$OE_CONFIG.access.log;" >> $NGINX_CONFIG
sudo echo " location / {" >> $NGINX_CONFIG
sudo echo " proxy_set_header Host \$host;" >> $NGINX_CONFIG
sudo echo " proxy_set_header X-Real-IP \$remote_addr;" >> $NGINX_CONFIG
sudo echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;" >> $NGINX_CONFIG
sudo echo " proxy_set_header X-Forwarded-Proto \$scheme;" >> $NGINX_CONFIG
sudo echo " # Fix the \"It appears that your reverse proxy set up is broken\" error." >> $NGINX_CONFIG
sudo echo " proxy_pass http://localhost:$OE_PORT;" >> $NGINX_CONFIG
sudo echo " proxy_read_timeout 90;" >> $NGINX_CONFIG
sudo echo " proxy_redirect http://localhost:$OE_PORT https://$OE_URL;" >> $NGINX_CONFIG
sudo echo " }" >> $NGINX_CONFIG
sudo echo "}" >> $NGINX_CONFIG
sudo echo "server {" >> $NGINX_CONFIG
sudo echo " listen 80;" >> $NGINX_CONFIG
sudo echo " server_name $OE_URL;" >> $NGINX_CONFIG
sudo echo " access_log /var/log/nginx/$OE_CONFIG.access.log;" >> $NGINX_CONFIG
sudo echo " location / {" >> $NGINX_CONFIG
sudo echo " proxy_set_header Host \$host;" >> $NGINX_CONFIG
sudo echo " proxy_set_header X-Real-IP \$remote_addr;" >> $NGINX_CONFIG
sudo echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;" >> $NGINX_CONFIG
sudo echo " proxy_set_header X-Forwarded-Proto \$scheme;" >> $NGINX_CONFIG
sudo echo " # Fix the \"It appears that your reverse proxy set up is broken\" error." >> $NGINX_CONFIG
sudo echo " proxy_pass http://localhost:$OE_PORT;" >> $NGINX_CONFIG
sudo echo " proxy_read_timeout 90;" >> $NGINX_CONFIG
sudo echo " proxy_redirect http://localhost:$OE_PORT https://$OE_URL;" >> $NGINX_CONFIG
sudo echo " }" >> $NGINX_CONFIG
sudo echo "}" >> $NGINX_CONFIG
sudo ln -s /etc/nginx/sites-available/$OE_CONFIG /etc/nginx/sites-enabled/$OE_CONFIG
sudo service nginx restart &>/dev/null
clear
##
# Install Info
##
echo "################################################################################"
echo "# CMIT Info"
echo "#"
echo "# Odoo Was Installed!"
echo "#"
echo "# Please remember that $OE_USER does not have a password yet."
echo "# run 'passwd $OE_USER' to set a password"
echo "#"
echo "# To View your enviroment login as $OE_USER"
echo "# run 'su $OE_USER'"
echo "#"
echo "# To start/stop/restart the server"
echo "# run 'sudo service $OE_USER-server start/stop/restart"
echo "#"
echo "# Your Database Master Password is: $OE_SUPERADMIN"
echo "#"
echo "################################################################################"
echo "################################################################################" > $OE_HOME/README.txt
echo "# CMIT Info" >> $OE_HOME/README.txt
echo "#" >> $OE_HOME/README.txt
echo "# Odoo Was Installed!" >> $OE_HOME/README.txt
echo "#" >> $OE_HOME/README.txt
echo "# Please remember that $OE_USER does not have a password yet." >> $OE_HOME/README.txt
echo "# run 'passwd $OE_USER' to set a password" >> $OE_HOME/README.txt
echo "#" >> $OE_HOME/README.txt
echo "# To View your enviroment login as $OE_USER" >> $OE_HOME/README.txt
echo "# run 'su $OE_USER'" >> $OE_HOME/README.txt
echo "#" >> $OE_HOME/README.txt
echo "# To start/stop/restart the server" >> $OE_HOME/README.txt
echo "# run 'sudo service $OE_USER-server start/stop/restart" >> $OE_HOME/README.txt
echo "#" >> $OE_HOME/README.txt
echo "# Your Database Master Password is: $OE_SUPERADMIN" >> $OE_HOME/README.txt
echo "#" >> $OE_HOME/README.txt
echo "################################################################################" >> $OE_HOME/README.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment