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

154 lines
4.5 KiB
Text
Raw Normal View History

2015-09-14 17:12:17 +02:00
#!/bin/bash
2016-07-05 15:22:12 +02:00
set -eu
app=$YNH_APP_INSTANCE_NAME
2015-09-14 17:12:17 +02:00
2016-07-05 15:22:12 +02:00
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
2016-12-14 12:14:06 +01:00
version=$YNH_APP_ARG_VERSION
oca=$YNH_APP_ARG_OCA
2016-07-05 15:22:12 +02:00
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
lang=$YNH_APP_ARG_LANG
2016-12-14 21:45:41 +01:00
tz=$YNH_APP_ARG_TZ
# Load common variables
source ./_common.sh
2016-07-05 15:22:12 +02:00
# Source YunoHost helpers
. /usr/share/yunohost/helpers
2015-09-14 17:12:17 +02:00
# Check domain/path availability
domain=${domain}"/"
sudo yunohost app checkurl $domain -a $app \
2016-11-29 00:20:02 +01:00
|| (ynh_die "Path not available: $domain" 1)
2015-09-14 17:12:17 +02:00
# Remove trailing "/" for next commands
domain=${domain%/}
2016-12-14 11:23:57 +01:00
2016-12-14 11:46:00 +01:00
# Generate random password
# Fix a bug on ynh_string_random https://github.com/YunoHost/yunohost/pull/205/commits/0d6cf499a0b858e7009245fd11a9210188047c13
dbpass=$(ynh_string_random | sed "s/\[/e/g" | sed "s/\]/e/g")
2016-12-14 11:23:57 +01:00
2016-07-05 15:22:12 +02:00
ynh_app_setting_set "$app" domain "$domain"
2016-12-14 11:23:57 +01:00
ynh_app_setting_set "$app" lang "$lang"
2016-12-14 21:45:41 +01:00
ynh_app_setting_set "$app" tz "$tz"
2016-12-14 11:46:00 +01:00
ynh_app_setting_set "$app" psqlpwd "$dbpass"
2016-11-29 00:20:02 +01:00
2015-09-16 10:17:50 +02:00
if [ -f /usr/bin/openerp-server ]; then
echo "Odoo is already installed, switching to multi-instances"
2016-07-05 15:22:12 +02:00
ynh_app_setting_set "$app" instance "slave"
2015-09-16 10:17:50 +02:00
else
2016-11-29 00:20:02 +01:00
sudo yunohost app checkport 8069
if [[ ! $? -eq 0 ]]; then
ynh_die "Port 8069 unavailable" 1
2016-11-29 00:20:02 +01:00
fi
2016-12-14 11:23:57 +01:00
echo "Installing odoo"
2016-12-14 12:14:06 +01:00
ynh_app_setting_set "$app" version "$version"
2016-11-29 00:20:02 +01:00
ynh_app_setting_set "$app" instance "master"
2016-12-14 11:33:39 +01:00
2016-11-29 00:20:02 +01:00
# Install Odoo
# Prepare installation
ynh_package_install curl
# Install Odoo
sudo curl -sS https://nightly.odoo.com/odoo.key | sudo apt-key add -
2016-12-14 12:14:06 +01:00
sudo sh -c "echo 'deb http://nightly.odoo.com/${version}/nightly/deb/ ./' > /etc/apt/sources.list.d/odoo.list"
2016-12-14 21:45:41 +01:00
# TODO if 8.0 install https://www.odoo.com/apps/modules/8.0/shell/
2016-11-29 00:20:02 +01:00
sudo apt-get update
# Initialize installation
2016-12-14 12:02:22 +01:00
ynh_package_install postgresql
ynh_package_install odoo
2016-07-05 15:22:12 +02:00
2016-11-29 00:20:02 +01:00
# Install wkhtmltopdf to print PDF reports
2016-12-14 22:17:01 +01:00
ynh_package_install xfonts-75dpi xfonts-base wkhtmltopdf node-less
2016-12-14 11:23:57 +01:00
# The debian package has a bug so we deploy a more recent version
2016-12-14 11:46:00 +01:00
DESTDIR="/tmp/wkhtmltox/"
sudo mkdir -p $DESTDIR
sudo chown -R $APPNAME: /tmp/wkhtmltox
extract_sources $DESTDIR "$APPNAME"
sudo cp -R "$DESTDIR." /usr/
sudo rm -Rf $DESTDIR
ynh_psql_execute_as_root "ALTER USER $APPNAME WITH CREATEDB;"
2016-12-14 14:27:32 +01:00
ynh_psql_execute_as_root "ALTER USER $APPNAME WITH PASSWORD '$dbpass';"
2016-12-14 14:13:13 +01:00
sudo su -c "createdb -O $APPNAME $APPNAME" - postgres
2016-07-05 15:22:12 +02:00
2016-11-29 00:20:02 +01:00
# Set admin password
# TODO Support @ in password
2016-11-29 00:20:02 +01:00
sudo sed -i "s@ADMIN_PASSWORD@$admin_password@g" ../conf/openerp-server.conf
2016-12-14 11:23:57 +01:00
sudo sed -i "s@DATABASE_PASSWORD@$dbpass@g" ../conf/openerp-server.conf
2016-11-29 00:20:02 +01:00
sudo cp ../conf/openerp-server.conf /etc/odoo/openerp-server.conf
sudo chown odoo:odoo /etc/odoo/openerp-server.conf
2016-07-05 15:22:12 +02:00
2016-11-29 00:20:02 +01:00
# 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
2016-07-05 15:22:12 +02:00
2016-11-29 00:20:02 +01:00
# Install oerplib to manage databases
#sudo pip install oerplib
2016-07-05 15:22:12 +02:00
2016-11-29 00:20:02 +01:00
# 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
2015-09-16 10:17:50 +02:00
fi
2015-09-14 17:12:17 +02:00
# Configure Nginx and reload
sed -i "s@#YNH_APP_INSTANCE_NAME#@${YNH_APP_INSTANCE_NAME}@g" ../conf/nginx.conf
2016-07-05 15:22:12 +02:00
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
2015-09-14 17:12:17 +02:00
2015-09-14 18:13:54 +02:00
# Make Odoo public
2016-11-29 00:55:39 +01:00
ynh_app_setting_set "$app" skipped_uris "/"
2015-09-14 17:12:17 +02:00
sudo service nginx reload
2016-07-05 15:22:12 +02:00
# 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//./-}
2016-12-14 21:55:08 +01:00
# Load translation
2016-12-14 22:12:22 +01:00
sudo /usr/bin/openerp-server -c /etc/odoo/openerp-server.conf --stop-after-init -d $database
2016-12-14 21:45:41 +01:00
sudo /usr/bin/openerp-server -c /etc/odoo/openerp-server.conf --stop-after-init -d $database --load-language $lang
2016-12-14 21:55:08 +01:00
# Configure language, timezone and ldap
2016-12-14 22:12:22 +01:00
sudo /usr/bin/openerp-server shell -c /etc/odoo/openerp-server.conf -d $database <<< \
2016-12-14 21:45:41 +01:00
"
self.change_password('admin','$admin_password')
2016-12-14 22:12:22 +01:00
self.env.cr.commit()
2016-12-14 21:45:41 +01:00
self.write({'tz':'$tz','lang':'$lang'})
2016-12-14 22:12:22 +01:00
self.env.cr.commit()
2016-12-14 21:45:41 +01:00
template=env['res.users'].create({
'login':'template',
'password':'',
'name':'template',
'email':'template',
'sel_groups_9_10':9,
'tz':'$tz',
'lang':'$lang'
})
2016-12-14 22:12:22 +01:00
self.env.cr.commit()
2016-12-14 21:45:41 +01:00
self.company_id.ldaps.create({
'ldap_server':'localhost',
'ldap_server_port':389,
'ldap_base':'ou=users, dc=yunohost,dc=org',
'ldap_filter':'uid=%s',
'user':template.id,
'company':self.company_id.id
})
self.env.cr.commit()
"
sudo service odoo restart