#!/bin/bash
set -eu
source /usr/share/yunohost/helpers
source _future.sh
source _common.sh
ynh_abort_if_errors
# Arguments from manifest
export app=$YNH_APP_INSTANCE_NAME
ynh_export domain oca admin_password lang tz
export app_version=$YNH_APP_ARG_VERSION
export is_public=0
export final_path="/var/www/$app"
export conf_file=/etc/$app/main.conf
export bin_file="$final_path/venv/bin/python $final_path/$APPNAME/$FORKNAME-bin"
if [ "$app_version" = "9" ]; then
bin_file="$final_path/venv/bin/python $final_path/$APPNAME/$FORKNAME.py"
fi
if [ "$app_version" = "8" ]; then
bin_file="$final_path/venv/bin/python $final_path/$APPNAME/$FORKNAME.py"
fi
export db_name=$(ynh_sanitize_dbid $app)
export port=$(ynh_find_port 8069)
export port_chat=$(ynh_find_port 8072)
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
test ! -e "$final_path" || ynh_die "This path already contains a folder"
ynh_webpath_available $domain "/"
ynh_webpath_register $app $domain "/"
#=================================================
# SETUP THE APP BY MODIFYING THE SYSTEM
#=================================================
function setup_files() {
ynh_setup_source $final_path/$APPNAME $app_version
# Remove Odoo references to avoid trademark issue
if [ -d $final_path/$APPNAME/$FORKNAME ]; then
python_app=$final_path/$APPNAME/$FORKNAME
else
python_app=$final_path/$APPNAME/openerp
fi
find $final_path/$APPNAME -type f \( -iname '*.xml' -o -iname '*.po' \) -exec sed -i 's/Powered by ]*>Odoo<\/a>//g' {} \;
find $final_path/$APPNAME -type f \( -iname '*.xml' -o -iname '*.po' \) -exec sed -i 's/]*>Powered by <[^>]*>Odoo<\/[^>]*><\/a>//g' {} \;
find $final_path/$APPNAME -type f \( -iname '*.xml' -o -iname '*.po' \) -exec sed -i 's/Powered by <[^>]*>Odoo<\/[^>]*>//g' {} \;
find $final_path/$APPNAME -type f \( -iname '*.xml' -o -iname '*.po' \) -exec sed -i 's/Powered by <[^>]*>]*Odoo[^>]*><\/a>//g' {} \;
sed -i 's/]*>My Odoo.com account<\/a>//g' $final_path/$APPNAME/addons/web/static/src/xml/base.xml
sed -i 's/]*>Documentation<\/a>//g' $final_path/$APPNAME/addons/web/static/src/xml/base.xml
sed -i 's/]*>Support<\/a>//g' $final_path/$APPNAME/addons/web/static/src/xml/base.xml
cp ../conf/logo_type.png $python_app/addons/base/static/img/logo_white.png
mkdir -p $final_path/custom-addons
chown -R $app:$app $final_path
ynh_configure server.conf $conf_file
chown $app:$app $conf_file
# Autoinstall the LDAP auth module
if ls $final_path/$APPNAME/$FORKNAME-bin > /dev/null ; then
ynh_replace_string "^{$" "{'auto_install': True," ${final_path}/$APPNAME/addons/auth_ldap/__manifest__.py
else
ynh_replace_string "'auto_install': False" "'auto_install': True" ${final_path}/$APPNAME/addons/auth_ldap/__openerp__.py
fi
touch /var/log/$app.log
chown $app:$app /var/log/$app.log
}
function setup_database() {
# Load translation
sudo -u $app $bin_file -c $conf_file --stop-after-init -i auth_ldap -d $app
sudo -u $app $bin_file -c $conf_file --stop-after-init -d $app --load-language $lang
# Configure language, timezone and ldap
sudo -u $app $bin_file shell -c $conf_file -d $app <<< \
"
self.env['res.users'].search([['login', '=', 'admin']])[0].write({'password': '$admin_password'})
self.env.cr.commit()
self.write({'tz':'$tz','lang':'$lang'})
self.env.cr.commit()
template=env['res.users'].create({
'login':'template',
'password':'',
'name':'template',
'email':'template',
'sel_groups_9_10':9,
'tz':'$tz',
'lang':'$lang'
})
self.env.cr.commit()
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()
"
}
ynh_save_args domain app_version oca lang tz final_path conf_file db_name port port_chat
ynh_psql_test_if_first_run
ynh_psql_setup_db $db_name $db_name
export db_pass=$(ynh_app_setting_get $app psqlpwd)
ynh_system_user_create $app $final_path
setup_files
install_dependencies
ynh_configure_nginx
add_services
setup_database
ssowat_and_restart