libreerp_ynh/scripts/install

120 lines
4.2 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
2017-05-18 23:28:18 +02:00
source /usr/share/yunohost/helpers
source _future.sh
source _common.sh
2018-12-14 03:36:58 +01:00
ynh_abort_if_errors
2017-05-18 23:28:18 +02:00
# Arguments from manifest
export app=$YNH_APP_INSTANCE_NAME
2018-12-14 03:36:58 +01:00
ynh_export domain oca admin_password lang tz
export app_version=$YNH_APP_ARG_VERSION
2017-05-18 23:28:18 +02:00
export is_public=0
2018-12-14 03:36:58 +01:00
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"
2018-12-14 03:36:58 +01:00
fi
if [ "$app_version" = "8" ]; then
bin_file="$final_path/venv/bin/python $final_path/$APPNAME/$FORKNAME.py"
2018-12-14 03:36:58 +01:00
fi
export db_name=$(ynh_sanitize_dbid $app)
export port=$(ynh_find_port 8069)
export port_chat=$(ynh_find_port 8072)
2017-05-18 23:28:18 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
2018-12-14 03:36:58 +01:00
test ! -e "$final_path" || ynh_die "This path already contains a folder"
ynh_webpath_available $domain "/"
ynh_webpath_register $app $domain "/"
2017-05-18 23:28:18 +02:00
#=================================================
# SETUP THE APP BY MODIFYING THE SYSTEM
#=================================================
function setup_files() {
2018-12-14 03:36:58 +01:00
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 <a[^>]*>Odoo<\/a>//g' {} \;
find $final_path/$APPNAME -type f \( -iname '*.xml' -o -iname '*.po' \) -exec sed -i 's/<a[^>]*>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 <[^>]*><img[^>]*Odoo[^>]*><\/a>//g' {} \;
sed -i 's/<a[^>]*>My Odoo.com account<\/a>//g' $final_path/$APPNAME/addons/web/static/src/xml/base.xml
sed -i 's/<a[^>]*>Documentation<\/a>//g' $final_path/$APPNAME/addons/web/static/src/xml/base.xml
sed -i 's/<a[^>]*>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
2018-12-14 03:36:58 +01:00
mkdir -p $final_path/custom-addons
chown -R $app:$app $final_path
ynh_configure server.conf $conf_file
chown $app:$app $conf_file
2016-07-05 15:22:12 +02:00
2016-11-29 00:20:02 +01:00
# Autoinstall the LDAP auth module
if ls $final_path/$APPNAME/$FORKNAME-bin > /dev/null ; then
2018-12-14 03:36:58 +01:00
ynh_replace_string "^{$" "{'auto_install': True," ${final_path}/$APPNAME/addons/auth_ldap/__manifest__.py
2017-05-18 23:28:18 +02:00
else
2018-12-14 03:36:58 +01:00
ynh_replace_string "'auto_install': False" "'auto_install': True" ${final_path}/$APPNAME/addons/auth_ldap/__openerp__.py
2017-05-18 23:28:18 +02:00
fi
2018-12-14 03:36:58 +01:00
touch /var/log/$app.log
chown $app:$app /var/log/$app.log
2015-09-16 10:17:50 +02:00
2017-05-18 23:28:18 +02:00
}
2015-09-14 17:12:17 +02:00
2017-05-18 23:28:18 +02:00
function setup_database() {
2015-09-14 17:12:17 +02:00
2017-05-18 23:28:18 +02:00
# Load translation
2018-12-14 03:36:58 +01:00
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
2017-05-18 23:28:18 +02:00
# Configure language, timezone and ldap
2018-12-14 03:36:58 +01:00
sudo -u $app $bin_file shell -c $conf_file -d $app <<< \
2016-12-14 21:45:41 +01:00
"
2018-12-13 13:07:01 +01:00
self.env['res.users'].search([['login', '=', 'admin']])[0].write({'password': '$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()
"
2017-05-18 23:28:18 +02:00
}
ynh_save_args domain app_version oca lang tz final_path conf_file db_name port port_chat
2018-12-14 03:36:58 +01:00
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
2017-05-18 23:28:18 +02:00
setup_files
2018-12-14 03:36:58 +01:00
install_dependencies
ynh_configure_nginx
2017-05-18 23:28:18 +02:00
add_services
setup_database
ssowat_and_restart
2016-12-14 21:45:41 +01:00