1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/libreerp_ynh.git synced 2024-09-03 19:36:13 +02:00
libreerp_ynh/scripts/install
2016-11-29 00:55:39 +01:00

149 lines
4.3 KiB
Bash

#!/bin/bash
set -eu
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
odoo_version=$YNH_APP_ARG_ODOO_VERSION
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
database_password=$YNH_APP_ARG_DATABASE_PASSWORD
lang=$YNH_APP_ARG_LANG
# Source YunoHost helpers
. /usr/share/yunohost/helpers
# Check domain/path availability
domain=${domain}"/"
sudo yunohost app checkurl $domain -a $app \
|| (ynh_die "Path not available: $domain" 1)
# Remove trailing "/" for next commands
domain=${domain%/}
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" domain "$domain"
is_master=false
# Exit to allow host change in my trap function
function exit_without_linter_warning
{
ynh_die "$1" $2
}
function exit_properly
{
set +e
if [ "$is_master" = true ]; then
sudo rm -f /etc/apt/sources.list.d/odoo.list
sudo apt-get update
ynh_package_remove odoo
sudo rm -f /etc/odoo/openerp-server.conf
sudo yunohost service remove odoo
fi
# TODO: uninstall db
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
sudo service nginx reload
exit_without_linter_warning "Error during installation" 1
}
trap exit_properly ERR
if [ -f /usr/bin/openerp-server ]; then
echo "Odoo is already installed, switching to multi-instances"
ynh_app_setting_set "$app" instance "slave"
else
is_master=true
sudo yunohost app checkport 8069
if [[ ! $? -eq 0 ]]; then
exit_without_linter_warning "Port 8069 unavailable" 1
fi
echo "Installing odoo"
ynh_app_setting_set "$app" version "$odoo_version"
ynh_app_setting_set "$app" instance "master"
# Install Odoo
# Prepare installation
ynh_package_install curl
# Install Odoo
sudo curl -sS https://nightly.odoo.com/odoo.key | sudo apt-key add -
if [ "$odoo_version" = "8.0" ]; then
sudo sh -c 'echo "deb http://nightly.odoo.com/8.0/nightly/deb/ ./" > /etc/apt/sources.list.d/odoo.list'
else
sudo sh -c 'echo "deb http://nightly.odoo.com/9.0/nightly/deb/ ./" > /etc/apt/sources.list.d/odoo.list'
fi
sudo apt-get update
# Initialize installation
ynh_package_install postgresql
sudo su -c "psql" postgres <<< \
"CREATE USER $app WITH PASSWORD '$database_password' CREATEDB;"
ynh_package_install odoo
# Install wkhtmltopdf to print PDF reports
ynh_package_install wkhtmltopdf
# Set admin password
sudo sed -i "s@ADMIN_PASSWORD@$admin_password@g" ../conf/openerp-server.conf
sudo sed -i "s@DATABASE_PASSWORD@$database_password@g" ../conf/openerp-server.conf
sudo cp ../conf/openerp-server.conf /etc/odoo/openerp-server.conf
sudo chown odoo:odoo /etc/odoo/openerp-server.conf
# Autoinstall the LDAP auth module
sudo sed -i "s@'auto_install': False@'auto_install': True@g" /usr/lib/python2.7/dist-packages/openerp/addons/auth_ldap/__openerp__.py
# Install oerplib to manage databases
#sudo pip install oerplib
# Add services
sudo yunohost service add postgresql
sudo yunohost service add odoo --log /var/log/odoo/odoo-server.log
sudo yunohost service stop odoo
sudo yunohost service start odoo
fi
ynh_psql_create_user() {
sudo su -c "psql" postgres <<< \
"CREATE USER ${1} WITH PASSWORD '${2}';"
}
ynh_psql_create_db() {
db=$1
# grant all privilegies to user
if [[ $# -gt 1 ]]; then
ynh_psql_create_user ${2} '${3}'
sudo su -c "createdb -O ${2} $db" postgres
else
sudo su -c "createdb $db" postgres
fi
}
# Configure Nginx and reload
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Make Odoo public
ynh_app_setting_set "$app" skipped_uris "/"
sudo service nginx reload
# Fix peer authentification issue
sudo sed -i '/local\s*all\s*all\s*peer/i \
local all odoo password' /etc/postgresql/9.4/main/pg_hba.conf
sudo service postgresql reload
# Setup database: not working
database=${domain//./-}
sudo /usr/bin/openerp-server -c /etc/odoo/openerp-server.conf --stop-after-init -d $database
#ynh_psql_create_db $database
#sudo sed -i "s@ADMIN_PASSWORD@$admin_password@g" ../conf/install_database.py
#sudo sed -i "s@DOMAIN_DATABASE@${domain//./-}@g" ../conf/install_database.py
#sudo sed -i "s@DATABASE_LANG@$lang@g" ../conf/install_database.py
#sudo sed -i "s@DATABASE_PASSWORD@$database_password@g" ../conf/install_database.py
#sudo python ../conf/install_database.py
# Setup LDAP: TO BE DONE
echo $?