2014-07-06 13:21:10 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC STARTING
|
|
|
|
|
#=================================================
|
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
|
#=================================================
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
source _common.sh
|
|
|
|
|
source /usr/share/yunohost/helpers
|
2020-02-29 21:56:40 +01:00
|
|
|
|
source _ynh_local_curl
|
2017-01-08 14:16:28 +01:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
|
#=================================================
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
|
ynh_abort_if_errors
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2017-06-03 18:13:29 +02:00
|
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2016-09-11 10:15:45 +02:00
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
|
final_path=/var/www/$app
|
2019-05-18 15:03:55 +02:00
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
|
# Register (book) web path
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
|
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
|
|
|
|
ynh_app_setting_set --app=$app --key=language --value=$language
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
|
#=================================================
|
2017-09-23 10:25:23 +02:00
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=40
|
2017-09-23 10:25:23 +02:00
|
|
|
|
|
|
|
|
|
ynh_install_app_dependencies "$pkg_dependencies"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE A MYSQL DB
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Creating a MySQL database..."
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2019-05-18 15:03:55 +02:00
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
|
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=5
|
2016-12-27 14:41:45 +01:00
|
|
|
|
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
# Create tmp directory and fetch app inside
|
2019-02-17 19:28:37 +01:00
|
|
|
|
tmpdir="$(ynh_smart_mktemp --min_size=300)"
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_setup_source --dest_dir="$tmpdir"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-06-18 18:24:10 +02:00
|
|
|
|
# Fetch needed plugins
|
2017-10-19 21:06:34 +02:00
|
|
|
|
mkdir -p $tmpdir/plugins/Ldap_Login
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_setup_source --dest_dir="$tmpdir/plugins/Ldap_Login" --source_id=ldap_plugin
|
|
|
|
|
ynh_setup_source --dest_dir="$tmpdir/plugins" --source_id=log_failed_logins_plugin
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=3
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# Create a system user
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_system_user_create --username=$app
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Configuring nginx web server..."
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
|
ynh_add_nginx_config
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# COPY FILES TO $FINAL_PATH
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
# sets extended pattern matching options in the bash shell
|
|
|
|
|
shopt -s extglob
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
|
|
# Install files and set permissions
|
2017-09-11 22:00:57 +02:00
|
|
|
|
mkdir $final_path
|
2018-07-31 21:35:38 +02:00
|
|
|
|
cp -a $tmpdir/!(upload|_data|galleries) $final_path
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
|
datapath=/home/yunohost.app/$app
|
2017-10-01 21:59:40 +02:00
|
|
|
|
mkdir -p $datapath/_data
|
2017-09-11 22:00:57 +02:00
|
|
|
|
mkdir -p $datapath/upload
|
2018-07-31 21:35:38 +02:00
|
|
|
|
mkdir -p $datapath/galleries
|
2017-01-08 14:16:28 +01:00
|
|
|
|
|
2017-10-01 21:59:40 +02:00
|
|
|
|
ln -sd $datapath/_data $final_path/_data
|
2017-09-11 22:00:57 +02:00
|
|
|
|
ln -sd $datapath/upload $final_path/upload
|
2018-07-31 21:35:38 +02:00
|
|
|
|
ln -sd $datapath/galleries $final_path/galleries
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
2018-07-31 22:29:39 +02:00
|
|
|
|
cp -Rp $tmpdir/_data/. $final_path/_data
|
|
|
|
|
cp -Rp $tmpdir/upload/. $final_path/upload
|
|
|
|
|
cp -Rp $tmpdir/galleries/. $final_path/galleries
|
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
chown -R $app: $datapath
|
2017-10-01 21:59:40 +02:00
|
|
|
|
chmod 755 -R $final_path/_data
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_secure_remove --file="$tmpdir"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# PHP-FPM CONFIGURATION
|
2017-06-03 18:13:29 +02:00
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Configuring php-fpm..." --weight=2
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# Create a dedicated php-fpm config
|
2017-06-03 18:13:29 +02:00
|
|
|
|
ynh_add_fpm_config
|
2017-02-08 18:32:46 +01:00
|
|
|
|
|
2017-09-22 21:18:40 +02:00
|
|
|
|
#=================================================
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# SETUP APPLICATION WITH CURL
|
2017-09-22 21:18:40 +02:00
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Installing piwigo with Curl..." --weight=5
|
2017-09-22 21:18:40 +02:00
|
|
|
|
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# Reload SSOwat config
|
2017-09-11 22:00:57 +02:00
|
|
|
|
yunohost app ssowatconf
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# Reload Nginx
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
|
# Generate random password for admin
|
2019-05-18 15:03:55 +02:00
|
|
|
|
adm_pwd=$(ynh_string_random --length=24)
|
|
|
|
|
ynh_app_setting_set --app=$app --key=admin_pwd --value="$adm_pwd"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2019-05-18 15:03:55 +02:00
|
|
|
|
if [ "$language" = "fr" ]; then
|
2019-02-17 19:28:37 +01:00
|
|
|
|
applanguage="fr_FR"
|
|
|
|
|
else
|
|
|
|
|
applanguage="en_UK"
|
|
|
|
|
fi
|
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
# Configure piwigo via curl
|
2019-05-18 15:03:55 +02:00
|
|
|
|
mail="$(ynh_user_get_info --username=$admin --key=mail)"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
|
|
|
|
# Installation with curl
|
|
|
|
|
ynh_local_curl "/install.php?language=$applanguage" "install=true" "dbuser=$db_name" "dbpasswd=$db_pwd" "dbname=$db_name" "admin_name=$admin" "admin_pass1=$adm_pwd" "admin_pass2=$adm_pwd" "admin_mail=$mail"
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# CONFIGURE PIWIGO
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Configuring piwigo..."
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
# Change local config
|
2017-09-11 22:00:57 +02:00
|
|
|
|
cp ../conf/config.inc.php $final_path/local/config/
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
|
# Calculate and store the config file checksum
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_store_file_checksum --file="$final_path/local/config/config.inc.php"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
# Setup database in local/config/database.inc.php
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_replace_string --match_string="__DBTOCHANGE__" --replace_string="$db_name" --target_file=../conf/database.inc.php
|
|
|
|
|
ynh_replace_string --match_string="__USERTOCHANGE__" --replace_string="$db_name" --target_file=../conf/database.inc.php
|
|
|
|
|
ynh_replace_string --match_string="__PASSTOCHANGE__" --replace_string="$db_pwd" --target_file=../conf/database.inc.php
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
|
cp ../conf/database.inc.php $final_path/local/config/database.inc.php
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
|
# Calculate and store the database config file checksum
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_store_file_checksum --file="$final_path/local/config/database.inc.php"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2017-09-22 21:18:40 +02:00
|
|
|
|
#=================================================
|
2020-02-29 21:56:40 +01:00
|
|
|
|
# ADD LDAP PLUGIN
|
2017-09-22 21:18:40 +02:00
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Configuring LDAP plugin..."
|
2017-09-22 21:18:40 +02:00
|
|
|
|
|
2020-02-29 21:56:40 +01:00
|
|
|
|
# Activate the LDAP plugin using the WS API
|
|
|
|
|
|
|
|
|
|
# Login with admin account
|
|
|
|
|
ynh_local_curl "/ws.php?format=json" "method=pwg.session.login" "username=$admin" "password=$adm_pwd"
|
|
|
|
|
# Get session token
|
|
|
|
|
status=$(ynh_local_curl "/ws.php?format=json" "method=pwg.session.getStatus")
|
|
|
|
|
pwg_token=$(jq --raw-output .result.pwg_token <<< $status)
|
|
|
|
|
# Install the Ldap_Login plugin
|
|
|
|
|
ynh_local_curl "/ws.php?format=json" "method=pwg.plugins.performAction" "action=install" "plugin=Ldap_Login" "pwg_token=$pwg_token"
|
|
|
|
|
# Activate the Ldap_Login plugin
|
|
|
|
|
ynh_local_curl "/ws.php?format=json" "method=pwg.plugins.performAction" "action=activate" "plugin=Ldap_Login" "pwg_token=$pwg_token"
|
|
|
|
|
# Log out
|
|
|
|
|
ynh_local_curl "/ws.php?format=json" "method=pwg.session.logout"
|
|
|
|
|
|
|
|
|
|
# Edit Ldap_Login plugin configuration
|
|
|
|
|
ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name <<< "UPDATE piwigo_ldap_login_config SET value='ou=users,dc=yunohost,dc=org' WHERE param = 'ld_basedn';
|
|
|
|
|
UPDATE piwigo_ldap_login_config SET value='uid' WHERE param = 'ld_user_attr';
|
|
|
|
|
UPDATE piwigo_ldap_login_config SET value='' WHERE param = 'ld_binddn';
|
|
|
|
|
UPDATE piwigo_ldap_login_config SET value='0' WHERE param = 'allow_new_users';
|
|
|
|
|
UPDATE piwigo_ldap_login_config SET value='0' WHERE param = 'ld_group_user_active';"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# CONFIGURE FAIL2BAN
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Configuring fail2ban..." --weight=6
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-06-18 18:24:10 +02:00
|
|
|
|
# Configure and activate log_failed_logins plugin
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name <<< "INSERT INTO plugins (id,state,version) VALUES ('log_failed_logins','active','1.2');"
|
|
|
|
|
ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name <<< "INSERT INTO config (param, value) VALUES ('logFailedLoginsFilename','/var/log/${app}FailedLogins.log');"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
|
touch "/var/log/${app}FailedLogins.log"
|
|
|
|
|
chown $app: "/var/log/${app}FailedLogins.log"
|
2017-06-18 18:24:10 +02:00
|
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
|
ynh_add_fail2ban_config --logpath="/var/log/${app}FailedLogins.log" --failregex="ip=<HOST>" --max_retry=6
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SSOWAT
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Configuring SSOwat..."
|
2017-06-18 18:24:10 +02:00
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
|
# Protect URIs if private
|
2019-02-17 19:28:37 +01:00
|
|
|
|
if [ $is_public -eq 0 ]
|
2014-07-06 13:21:10 +02:00
|
|
|
|
then
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_app_setting_delete --app=$app --key=unprotected_uris
|
|
|
|
|
ynh_app_setting_set --app=$app --key=protected_uris --value="/"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
fi
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# RELOAD NGINX
|
|
|
|
|
#=================================================
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Reloading nginx web server..."
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
2019-02-17 20:58:31 +01:00
|
|
|
|
#=================================================
|
|
|
|
|
# END OF SCRIPT
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2019-05-18 15:03:55 +02:00
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|