2017-04-24 04:16:02 +02:00
|
|
|
|
#!/bin/bash
|
2015-09-28 22:13:34 +02:00
|
|
|
|
|
2018-01-26 17:24:00 +01:00
|
|
|
|
#set -eu
|
|
|
|
|
|
2017-04-24 04:16:02 +02:00
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
version=$(cat ../sources/version)
|
2015-09-28 23:17:30 +02:00
|
|
|
|
|
2018-01-16 17:09:27 +01:00
|
|
|
|
## Source YunoHost helpers - old
|
|
|
|
|
# source /usr/share/yunohost/helpers
|
|
|
|
|
# source ./_extrahelpers
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC START
|
|
|
|
|
#=================================================
|
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
|
|
|
2018-01-16 17:13:48 +01:00
|
|
|
|
################
|
2015-09-28 23:17:30 +02:00
|
|
|
|
|
2017-04-24 04:16:02 +02:00
|
|
|
|
# Retrieve arguments
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2018-01-26 17:29:55 +01:00
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2018-01-26 17:31:51 +01:00
|
|
|
|
path=$YNH_APP_ARG_PATH
|
2017-05-05 17:34:15 +02:00
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2017-04-24 04:16:02 +02:00
|
|
|
|
member=$YNH_APP_ARG_MEMBER
|
|
|
|
|
|
2018-01-26 17:39:11 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
|
|
# Normalize the url path syntax
|
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
|
|
|
|
|
|
# Check web path availability
|
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
|
# Register (book) web path
|
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
|
|
|
|
|
|
|
|
|
|
2017-04-24 04:16:02 +02:00
|
|
|
|
# Correct path: puts a / at the start and nothing at the end
|
2018-01-26 17:39:11 +01:00
|
|
|
|
# if [ "${path:0:1}" != "/" ]; then
|
|
|
|
|
# path="/$path"
|
|
|
|
|
# fi
|
|
|
|
|
# if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
|
|
|
|
|
# path="${path:0:${#path}-1}"
|
|
|
|
|
# fi
|
2015-09-29 16:20:08 +02:00
|
|
|
|
|
2017-04-24 04:16:02 +02:00
|
|
|
|
# Check domain/path availability
|
2018-01-16 17:05:23 +01:00
|
|
|
|
# sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|
# || ynh_die "path not available: ${domain}${path}"
|
|
|
|
|
|
2018-01-26 17:39:11 +01:00
|
|
|
|
# ynh_webpath_register $app $domain $path \
|
|
|
|
|
# || ynh_die "path not available and may be already used : ${domain}${path}"
|
2017-05-05 17:34:15 +02:00
|
|
|
|
|
|
|
|
|
# Check user parameter
|
|
|
|
|
ynh_user_exists "$admin" \
|
|
|
|
|
|| ynh_die "The chosen admin user does not exist."
|
2017-04-24 04:16:02 +02:00
|
|
|
|
|
|
|
|
|
# Store settings
|
|
|
|
|
ynh_app_setting_set $app domain $domain
|
2017-05-05 17:34:15 +02:00
|
|
|
|
ynh_app_setting_set $app admin $admin
|
2017-04-24 04:16:02 +02:00
|
|
|
|
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
|
2018-01-09 10:12:11 +01:00
|
|
|
|
|
2017-04-24 04:16:02 +02:00
|
|
|
|
# Download, unzip and copy source
|
2018-01-09 10:12:11 +01:00
|
|
|
|
sudo wget -q https://github.com/Dolibarr/dolibarr/archive/${version}.zip -O dolibarr-${version}.zip
|
2018-01-25 17:26:35 +01:00
|
|
|
|
sudo unzip -qq dolibarr-${version}.zip || ynh_die "Problem uncompressing dolibarr zip file"
|
2018-01-09 10:02:32 +01:00
|
|
|
|
|
2018-01-09 10:12:11 +01:00
|
|
|
|
sudo cp -a dolibarr-${version}/. $src_path
|
2017-05-18 20:42:22 +02:00
|
|
|
|
|
2017-04-24 04:16:02 +02:00
|
|
|
|
# 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
|
2017-05-05 17:34:15 +02:00
|
|
|
|
sed -i "s@YNH_ADMIN@$admin@g" ../sources/install.forced.php
|
2017-04-24 04:16:02 +02:00
|
|
|
|
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
|
|
|
|
|
|
2017-05-05 17:34:15 +02:00
|
|
|
|
# Generate a random password for the admin user (will be ignored because of LDAP)
|
|
|
|
|
password=$(ynh_string_random 8)
|
|
|
|
|
|
2017-04-24 04:16:02 +02:00
|
|
|
|
# Install with CURL
|
2018-01-26 17:24:00 +01:00
|
|
|
|
|
2018-01-25 17:39:29 +01:00
|
|
|
|
ynh_local_curl "/install/fileconf.php" \
|
|
|
|
|
"testpost=ok"
|
2017-05-18 20:42:22 +02:00
|
|
|
|
|
|
|
|
|
ynh_local_curl "/install/step1.php" \
|
|
|
|
|
"testpost=ok" \
|
|
|
|
|
"action=set" \
|
|
|
|
|
"selectlang=fr_FR"
|
|
|
|
|
|
|
|
|
|
ynh_local_curl "/install/step2.php" \
|
|
|
|
|
"testpost=ok" \
|
|
|
|
|
"action=set" \
|
|
|
|
|
"dolibarr_main_db_character_set=latin1" \
|
|
|
|
|
"dolibarr_main_db_collation=latin1_swedish_ci" \
|
|
|
|
|
"selectlang=fr_FR"
|
|
|
|
|
|
|
|
|
|
ynh_local_curl "/install/step4.php" \
|
|
|
|
|
"testpost=ok" \
|
|
|
|
|
"action=set" \
|
|
|
|
|
"selectlang=fr_FR"
|
|
|
|
|
|
|
|
|
|
ynh_local_curl "/install/step5.php" \
|
|
|
|
|
"testpost=ok" \
|
|
|
|
|
"action=set" \
|
|
|
|
|
"selectlang=fr_FR" \
|
|
|
|
|
"pass=$password" \
|
|
|
|
|
"pass_verif=$password"
|
2017-04-24 04:16:02 +02:00
|
|
|
|
|
|
|
|
|
# Populate the LDAP parameters
|
|
|
|
|
mysql -u ${dbuser} -p${dbpass} ${dbname} < ../conf/ldap.sql
|
2017-05-07 15:35:48 +02:00
|
|
|
|
|
2017-05-05 17:34:15 +02:00
|
|
|
|
# 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
|
2017-04-24 04:16:02 +02:00
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
2017-05-05 17:34:15 +02:00
|
|
|
|
# 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
|
2017-04-24 04:16:02 +02:00
|
|
|
|
|
|
|
|
|
# Setup hooks
|
|
|
|
|
sed -i "s@YNH_APP@$app@g" ../hooks/post_user_create
|
|
|
|
|
sed -i "s@YNH_MEMBER@$member@g" ../hooks/post_user_create
|