1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dolibarr_ynh.git synced 2024-09-03 18:35:53 +02:00
dolibarr_ynh/scripts/install
Jeff 5cc9b9c96f LDAP and HTTP auth
YunoHost users are now instantly logged in with HTTP auth
For this feature to work, the app now needs to be private, all YNH users
must be added in the database, and the admin user must be a YNH user. As
a result, the manifest has changed:
- Admin password is replaced by admin user
- Public/Private is removed
- Adding YNH users as Dolibarr users is removed: this is default now
Unfortunately, upgrading the app will not change the previous behavior
(ie no automatic login). For automatic login to work, you **must**
reinstall the app
The sync script does not delete users. Therefore the post_user_delete
hook is not needed (and does not work anyway)
2017-05-05 17:34:15 +02:00

133 lines
4.9 KiB
Bash

#!/bin/bash
set -eu
app=$YNH_APP_INSTANCE_NAME
version=$(cat ../sources/version)
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
member=$YNH_APP_ARG_MEMBER
# Correct path: puts a / at the start and nothing at the end
if [ "${path:0:1}" != "/" ]; then
path="/$path"
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
path="${path:0:${#path}-1}"
fi
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "path not available: ${domain}${path}"
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist."
# Store settings
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app member $member
ynh_app_setting_set $app version $version
# Copy source files
src_path=/var/www/$app
sudo mkdir -p $src_path
# Download, unzip and copy source
sudo wget -q https://github.com/Dolibarr/dolibarr/archive/${version}.zip -O dolibarr-${version}.zip
sudo unzip -qq dolibarr-${version}.zip
sudo cp -a dolibarr-${version}/. $src_path
# Create necessary files
sudo touch $src_path/htdocs/conf/conf.php
sudo mkdir -p $src_path/documents
# MySQL
dbuser=$app
dbname=$app
dbpass=$(ynh_string_random 12)
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@${path%/}@g" $nginx_conf
sed -i "s@YNH_WWW_ALIAS@$src_path/htdocs/@g" $nginx_conf
sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
# PHP
sed -i "s@YNH_WWW_APP@$app@g" ../conf/php-fpm.conf
sed -i "s@YNH_WWW_ALIAS@$src_path@g" ../conf/php-fpm.conf
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $finalphpconf
sudo chown root: $finalphpconf
sudo chmod 644 $finalphpconf
sudo service php5-fpm reload
# Install parameters
sed -i "s@YNH_WWW_ALIAS@$src_path@g" ../sources/install.forced.php
sed -i "s@YNH_DBNAME@$dbname@g" ../sources/install.forced.php
sed -i "s@YNH_DBUSER@$dbuser@g" ../sources/install.forced.php
sed -i "s@YNH_DBPASS@$dbpass@g" ../sources/install.forced.php
sed -i "s@YNH_ADMIN@$admin@g" ../sources/install.forced.php
if [ $member = 1 ];
then
# If YNH users are members, we must activate the members module
sed -i "s@modLdap@modLdap,modAdherent@g" ../sources/install.forced.php
fi
forcedinstall=$src_path/htdocs/install/install.forced.php
sudo cp ../sources/install.forced.php $forcedinstall
# Set permissions to app files
sudo chmod -R 755 $src_path
sudo chown -R www-data: $src_path
# Reload Nginx
sudo service nginx reload
# Install
# Disable SSO
ynh_app_setting_set "$app" unprotected_uris "/"
sudo yunohost app ssowatconf
# Generate a random password for the admin user (will be ignored because of LDAP)
password=$(ynh_string_random 8)
# Install with CURL
curl -kL -H "Host: $domain" -X POST https://$domain$path/install/fileconf.php > /dev/null 2>&1
curl -kL -H "Host: $domain" -X POST https://$domain$path/install/step1.php --data "testpost=ok&action=set&selectlang=fr_FR" > /dev/null 2>&1
curl -kL -H "Host: $domain" -X POST https://$domain$path/install/step2.php --data "testpost=ok&action=set&dolibarr_main_db_character_set=latin1&dolibarr_main_db_collation=latin1_swedish_ci&selectlang=fr_FR" > /dev/null 2>&1
curl -kL -H "Host: $domain" -X POST https://$domain$path/install/step4.php --data "testpost=ok&action=set&selectlang=fr_FR" > /dev/null 2>&1
curl -kL -H "Host: $domain" -X POST https://$domain$path/install/step5.php --data "testpost=ok&action=set&selectlang=fr_FR&pass=$password&pass_verif=$password" > /dev/null 2>&1
# Populate the LDAP parameters
mysql -u ${dbuser} -p${dbpass} ${dbname} < ../conf/ldap.sql
# Populate the database with YNH users.
mysql -u ${dbuser} -p${dbpass} ${dbname} < ../conf/ldap_user.sql
sudo sudo -u www-data php $src_path/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y
# If YNH users should be members, populate the database accordingly, create the member list, and sync members
if [ $member = 1 ];
then
mysql -u ${dbuser} -p${dbpass} ${dbname} < ../conf/ldap_member.sql
sudo sudo -u www-data php $src_path/scripts/members/sync_members_ldap2dolibarr.php commitiferror 1 --server=localhost -y
fi
# Re-enable SSO if chosen by the user
ynh_app_setting_delete $app unprotected_uris
sudo yunohost app ssowatconf
# Setup HTTP auth in conf
sudo sed -i "s@\$dolibarr_main_authentication='dolibarr';@\$dolibarr_main_authentication='http';@g" $src_path/htdocs/conf/conf.php
# Setup hooks
sed -i "s@YNH_APP@$app@g" ../hooks/post_user_create
sed -i "s@YNH_MEMBER@$member@g" ../hooks/post_user_create
sed -i "s@YNH_APP@$app@g" ../hooks/post_user_delete
sed -i "s@YNH_MEMBER@$member@g" ../hooks/post_user_delete