From fa877df587e4cfb3d5dd5122fb38883e0cb62741 Mon Sep 17 00:00:00 2001 From: zamentur Date: Tue, 5 Jul 2016 15:22:12 +0200 Subject: [PATCH] [enh] Adapt for yunohost 2.4 --- conf/openerp-server.conf | 9 ++-- manifest.json | 9 +++- scripts/backup | 25 +++++++++- scripts/install | 102 +++++++++++++++++++++++++-------------- scripts/remove | 37 ++++++++------ scripts/upgrade | 11 ++++- 6 files changed, 133 insertions(+), 60 deletions(-) diff --git a/conf/openerp-server.conf b/conf/openerp-server.conf index 4da9613..f6b8a4a 100644 --- a/conf/openerp-server.conf +++ b/conf/openerp-server.conf @@ -1,10 +1,11 @@ [options] ; This is the password that allows database operations: +without_demo = all admin_passwd = ADMIN_PASSWORD -db_host = False -db_port = False +db_host = false +db_port = false db_user = odoo -db_password = False +db_password = DATABASE_PASSWORD addons_path = /usr/lib/python2.7/dist-packages/openerp/addons proxy_mode = true -dbfilter = %h \ No newline at end of file +dbfilter = %h diff --git a/manifest.json b/manifest.json index b0bcfed..4705215 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,7 @@ { "name": "Odoo", "id": "odoo", + "packaging_format": 1, "description": { "en": "Odoo is a suite of business apps (ERP: CRM, Accounting, Point of Sale, HR, Purchases...).", "fr": "Odoo est une collection d'apps de gestion d'entreprise (ERP : CRM, Comptabilité, Point de Vente, RH, Achats, ...)." @@ -8,7 +9,13 @@ "developer": { "name": "scith" }, + "requirements": { + "yunohost": ">> 2.4.0" + }, "multi_instance": "true", + "services": [ + "nginx" + ], "arguments": { "install" : [ { @@ -44,7 +51,7 @@ } }, { - "name": "database_lang", + "name": "lang", "ask": { "en": "Choose a language for Odoo", "fr": "Choisissez une langue pour Odoo" diff --git a/scripts/backup b/scripts/backup index ccb3be1..1373adf 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,3 +1,24 @@ #! /bin/bash -app=odoo -# TO BE DONE \ No newline at end of file + +# Exit on command errors and treat unset variables as an error +set -eu + +# See comments in install script +app=$YNH_APP_INSTANCE_NAME + +# Source YunoHost helpers +. /usr/share/yunohost/helpers + +# Backup sources & data +ynh_backup "/usr/lib/python2.7/dist-packages/openerp/" "sources" + +# Copy NGINX configuration +domain=$(ynh_app_setting_get "$app" domain) +ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" +ynh_backup "/etc/odoo/openerp-server.conf" "openerp-server.conf" + +# Copy database +database=${domain//./-} +sudo su -c "pg_dump $database" postgres > ./dump.sql +pwd=`pwd` +ynh_backup "$pwd/dump.sql" "dump.sql" diff --git a/scripts/install b/scripts/install index c14ca27..9d920d5 100644 --- a/scripts/install +++ b/scripts/install @@ -1,15 +1,18 @@ #!/bin/bash -app=odoo -set -e + +set -eu + +app=$YNH_APP_INSTANCE_NAME # Retrieve arguments -domain=$1 -odoo_version=$2 -admin_password=$3 -database_password=$4 -database_lang=$5 - +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}"/" @@ -18,25 +21,26 @@ sudo yunohost app checkurl $domain -a $app \ # Remove trailing "/" for next commands domain=${domain%/} -sudo yunohost app setting $app domain -v $domain +ynh_app_setting_set "$app" domain "$domain" +ynh_app_setting_set "$app" domain "$domain" if [ -f /usr/bin/openerp-server ]; then echo "Odoo is already installed, switching to multi-instances" - sudo yunohost app setting $app instance -v "slave" - + ynh_app_setting_set "$app" instance "slave" + else sudo yunohost app checkport 8069 if [[ ! $? -eq 0 ]]; then exit 1 fi - + echo "Installing odoo" - sudo yunohost app setting $app version -v $odoo_version - sudo yunohost app setting $app instance -v "master" + ynh_app_setting_set "$app" version "$odoo_version" + ynh_app_setting_set "$app" instance "master" # Install Odoo # Prepare installation - sudo apt-get -y -qq install curl - + 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 @@ -45,27 +49,28 @@ 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 - sudo apt-get -y -qq install postgresql - sudo su - postgres -c "echo \"CREATE USER odoo WITH PASSWORD '$admin_password' CREATEDB;\" | psql" 2> /dev/null || true - - sudo apt-get -y -qq install odoo - + 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 - sudo apt-get -yf -qq install wkhtmltopdf - + 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 @@ -82,20 +87,45 @@ function exit_properly exit 1 } trap exit_properly ERR + +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 +sudo yunohost app setting $app skipped_uris -v "/" + +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@$database_lang@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 - -# Configure Nginx and reload - sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf - -# Make Odoo public - sudo yunohost app setting $app skipped_uris -v "/" - -sudo service nginx reload echo $? diff --git a/scripts/remove b/scripts/remove index 2f3c61f..eaa90a0 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,24 +1,31 @@ #!/bin/bash -app=odoo -domain=$(sudo yunohost app setting $app domain) +set -eu + +app=$YNH_APP_INSTANCE_NAME +# Source YunoHost helpers +. /usr/share/yunohost/helpers + +# Retrieve app settings +domain=$(ynh_app_setting_get "$app" domain) + database=${domain//./-} -instance=$(sudo yunohost app setting $app instance) +instance=$(ynh_app_setting_get "$app" instance) # Remove database - sudo -u postgres dropdb $database +sudo su -c "dropdb $database" postgres # If removing master instance, remove Odoo. - if [ "$instance" = "master" ]; then - # Remove Odoo - sudo yunohost service stop odoo - sudo apt-get remove odoo -y - sudo apt-get remove wkhtmltopdf -y - sudo yunohost service remove odoo - fi - +if [ "$instance" = "master" ]; then + # Remove Odoo + sudo yunohost service stop odoo + sudo apt-get remove odoo -y + sudo apt-get remove wkhtmltopdf -y + sudo yunohost service remove odoo +fi + # Remove NGINX conf - sudo rm /etc/nginx/conf.d/$domain.d/$app.conf +sudo rm /etc/nginx/conf.d/$domain.d/$app.conf # Reload - sudo service nginx reload - sudo yunohost app ssowatconf +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index 4964284..a3df0a1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,14 @@ #!/bin/bash -app=odoo +set -eu +app=$YNH_APP_INSTANCE_NAME + +# Source YunoHost helpers +. /usr/share/yunohost/helpers + +# Retrieve arguments +domain=$(ynh_app_setting_get "$app" domain) # Upgrade official package sudo apt-get install odoo -y -qq - + # TBD