mirror of
https://github.com/YunoHost-Apps/dolibarr_ynh.git
synced 2024-09-03 18:35:53 +02:00
cc4c506757
Major rework of the app: - Update to latest sources - Auto-install - Install, upgrade, remove, backup, restore scripts - Readme - Sets up LDAP (still a bug to solve with the passwords preventing LDAP auth) - Sync YNH users with Dolibarr users and/or members - Check_process (broken because of CURL?) - Hooks (broken)
134 lines
4.9 KiB
Bash
134 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
|
|
password=$YNH_APP_ARG_PASSWORD
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
user=$YNH_APP_ARG_USER
|
|
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}"
|
|
|
|
# Store settings
|
|
ynh_app_setting_set $app domain $domain
|
|
ynh_app_setting_set $app is_public $is_public
|
|
ynh_app_setting_set $app user $user
|
|
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
|
|
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
|
|
|
|
# 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
|
|
|
|
# If YNH users should be users, populate the database accordingly and sync users. Set the script as executable by all users to tackle a Hook limitation
|
|
if [ $user = 1 ];
|
|
then
|
|
mysql -u ${dbuser} -p${dbpass} ${dbname} < ../conf/ldap_user.sql
|
|
sudo sudo -u www-data php php $src_path/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y
|
|
fi
|
|
|
|
# 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
|
|
|
|
# Enable SSO if chosen by the user
|
|
if [ $is_public = 0 ];
|
|
then
|
|
ynh_app_setting_delete $app unprotected_uris
|
|
sudo yunohost app ssowatconf
|
|
fi
|
|
|
|
# Setup hooks
|
|
sed -i "s@YNH_APP@$app@g" ../hooks/post_user_create
|
|
sed -i "s@YNH_USER@$user@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_USER@$user@g" ../hooks/post_user_delete
|
|
sed -i "s@YNH_MEMBER@$member@g" ../hooks/post_user_delete
|