libreerp_ynh/scripts/_common.sh

125 lines
3.4 KiB
Bash
Raw Normal View History

#
# Common variables
#
APPNAME="odoo"
2017-05-18 23:28:18 +02:00
function define_paths() {
# In odoo 10 some file change
if [ $(echo "$odoo_version >= 10" | bc) -ne 0 ]; then
export source_path=/usr/lib/python2.7/dist-packages/odoo/
conf_file=/etc/odoo/odoo.conf
bin_file=/usr/bin/odoo
else
export source_path=/usr/lib/python2.7/dist-packages/openerp/
conf_file=/etc/odoo/openerp-server.conf
bin_file=/usr/bin/openerp-server
fi
}
2017-05-18 23:28:18 +02:00
function check_odoo_version () {
if [ $(echo "$odoo_version >= 10" | bc) -ne 0 ]; then
if [ -f /usr/bin/openerp-server ]; then
ynh_die "Another version of odoo is installed"
fi
else
if [ -f /usr/bin/odoo ]; then
ynh_die "Another version of odoo is installed"
fi
fi
}
2017-05-18 23:28:18 +02:00
function define_is_master() {
if [ -f $bin_file ]; then
export is_master=false
else
export is_master=true
fi
}
2017-05-18 23:28:18 +02:00
function define_port () {
if [ "$is_master" = true ]; then
export port=$(ynh_find_port 8069)
yunohost app checkport $port
if [[ ! $? -eq 0 ]]; then
ynh_die "Port 8069 unavailable" 1
fi
else
# FIXME find master port
export port="8069"
fi
}
2017-05-18 23:28:18 +02:00
function define_dbpass () {
# TODO set -x
if [ "$is_master" = true ]; then
# Generate random password
if [ "${1:-}" = "restore" ]; then
export dbpass=$(ynh_app_setting_get $app psqlpwd)
else
export dbpass=$(ynh_string_random)
fi
else
2017-05-18 23:28:18 +02:00
export dbpass=$(grep db_password /etc/odoo/odoo.conf | cut -d \= -f 2 | sed -e 's/^[ \t]*//')
fi
ynh_app_setting_set "$app" psqlpwd "$dbpass"
}
# Install dependencies
function install_dependencies() {
if [ ! -f /etc/apt/sources.list.d/odoo.list ]; then
# Install Odoo
# Prepare installation
ynh_package_install curl
# Install Odoo
curl -sS https://nightly.odoo.com/odoo.key | sudo apt-key add -
sh -c "echo 'deb http://nightly.odoo.com/${odoo_version}/nightly/deb/ ./' > /etc/apt/sources.list.d/odoo.list"
# TODO if 8.0 install https://www.odoo.com/apps/modules/8.0/shell/
fi
2017-05-18 23:28:18 +02:00
apt-get update
ynh_install_app_dependencies curl postgresql odoo xfonts-75dpi xfonts-base wkhtmltopdf node-less python-xlrd
if ! wkhtmltopdf --version | grep "wkhtmltopdf 0.12.4 (with patched qt)"; then
# The debian package has a bug so we deploy a more recent version
ynh_setup_source /usr/
fi
}
2017-05-18 23:28:18 +02:00
# Create db
function create_general_db() {
service postgresql reload
if ! su -c "psql -lqt | cut -d \| -f 1 " - postgres | grep $APPNAME; then
# Generate random password
ynh_psql_execute_as_root "ALTER USER $APPNAME WITH CREATEDB;"
ynh_psql_execute_as_root "ALTER USER $APPNAME WITH PASSWORD '$dbpass';"
su -c "createdb -O $APPNAME $APPNAME" - postgres
fi
}
2017-05-18 23:28:18 +02:00
# Add services
function add_services() {
if ! grep "^postgresql:$" /etc/yunohost/services.yml; then
yunohost service add postgresql
fi
if ! grep "^odoo:$" /etc/yunohost/services.yml; then
yunohost service add odoo --log /var/log/odoo/odoo-server.log
yunohost service stop odoo
yunohost service start odoo
fi
}
2017-05-18 23:28:18 +02:00
function ssowat_and_restart() {
# Restart odoo service
service odoo restart
2017-05-18 23:28:18 +02:00
# Configure SSOWat
ynh_sso_access "/web/database/manager"
2017-05-18 23:28:18 +02:00
# Reload services
service nginx reload
}