libreerp_ynh/scripts/install

132 lines
3.8 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
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
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 \
|| (echo "Path not available: $domain" && exit 1)
# Remove trailing "/" for next commands
domain=${domain%/}
2016-07-05 15:22:12 +02:00
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" domain "$domain"
2015-09-14 17:12:17 +02: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
sudo yunohost app checkport 8069
if [[ ! $? -eq 0 ]]; then
exit 1
fi
2016-07-05 15:22:12 +02:00
2015-09-16 10:17:50 +02:00
echo "Installing odoo"
2016-07-05 15:22:12 +02:00
ynh_app_setting_set "$app" version "$odoo_version"
ynh_app_setting_set "$app" instance "master"
2015-09-16 10:17:50 +02:00
# Install Odoo
2015-09-14 17:42:46 +02:00
# Prepare installation
2016-07-05 15:22:12 +02:00
ynh_package_install curl
2015-09-14 17:12:17 +02:00
# Install Odoo
2015-09-14 17:42:46 +02:00
sudo curl -sS https://nightly.odoo.com/odoo.key | sudo apt-key add -
2015-09-14 18:23:11 +02:00
if [ "$odoo_version" = "8.0" ]; then
2015-09-14 18:20:51 +02:00
sudo sh -c 'echo "deb http://nightly.odoo.com/8.0/nightly/deb/ ./" > /etc/apt/sources.list.d/odoo.list'
2015-09-14 18:23:11 +02:00
else
2015-09-14 18:20:51 +02:00
sudo sh -c 'echo "deb http://nightly.odoo.com/9.0/nightly/deb/ ./" > /etc/apt/sources.list.d/odoo.list'
fi
2015-09-14 17:42:46 +02:00
sudo apt-get update
2016-07-05 15:22:12 +02:00
2015-09-14 20:27:12 +02:00
# Initialize installation
2016-07-05 15:22:12 +02:00
ynh_package_install postgresql
sudo su -c "psql" postgres <<< \
"CREATE USER $app WITH PASSWORD '$database_password' CREATEDB;"
ynh_package_install odoo
2015-09-14 20:38:40 +02:00
# Install wkhtmltopdf to print PDF reports
2016-07-05 15:22:12 +02:00
ynh_package_install wkhtmltopdf
2015-09-14 18:38:24 +02:00
# Set admin password
2015-09-14 19:10:35 +02:00
sudo sed -i "s@ADMIN_PASSWORD@$admin_password@g" ../conf/openerp-server.conf
2016-07-05 15:22:12 +02:00
sudo sed -i "s@DATABASE_PASSWORD@$database_password@g" ../conf/openerp-server.conf
2015-09-14 18:56:06 +02: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
2015-09-16 12:13:00 +02:00
# Autoinstall the LDAP auth module
2015-09-14 18:38:24 +02:00
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
2015-09-16 12:13:00 +02:00
# Install oerplib to manage databases
2015-11-27 09:41:18 +01:00
#sudo pip install oerplib
2016-07-05 15:22:12 +02:00
2015-09-14 17:42:46 +02:00
# Add services
sudo yunohost service add postgresql
2016-02-02 10:02:34 +01:00
sudo yunohost service add odoo --log /var/log/odoo/odoo-server.log
2015-09-14 17:43:17 +02:00
sudo yunohost service stop odoo
sudo yunohost service start odoo
2015-09-16 10:17:50 +02:00
fi
function exit_properly
{
set +e
# TODO: uninstall db
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf
sudo service nginx reload
exit 1
}
trap exit_properly ERR
2015-09-16 12:13:00 +02:00
2016-07-05 15:22:12 +02:00
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
}
2015-09-14 20:38:40 +02:00
2015-09-14 17:12:17 +02:00
# Configure Nginx and reload
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-07-05 15:22:12 +02:00
sudo yunohost app setting $app skipped_uris -v "/"
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//./-}
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
2015-09-19 11:48:14 +02:00
echo $?