2014-07-06 13:21:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
2021-05-16 19:41:11 +02:00
|
|
|
# GENERIC START
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
2017-01-08 14:16:28 +01: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
|
|
|
|
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
|
|
|
|
2019-02-17 19:28:37 +01:00
|
|
|
# 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
|
2023-10-05 21:38:07 +02:00
|
|
|
cp -a $tmpdir/!(upload|_data|galleries) $install_dir
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2023-10-05 21:38:07 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2021-05-18 03:42:40 +02:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
|
|
|
|
|
|
|
|
# Create a dedicated PHP-FPM config
|
2023-12-05 01:34:25 +01:00
|
|
|
ynh_add_fpm_config
|
2022-06-24 05:33:16 +02:00
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2021-05-18 03:42:40 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
2022-07-29 23:56:30 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DATA DIRECTORY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a data directory..."
|
|
|
|
|
2023-10-05 21:38:07 +02:00
|
|
|
ln -sd $data_dir/_data $install_dir/_data
|
|
|
|
ln -sd $data_dir/upload $install_dir/upload
|
|
|
|
ln -sd $data_dir/galleries $install_dir/galleries
|
2022-07-29 23:56:30 +02:00
|
|
|
|
2023-12-04 23:12:12 +01:00
|
|
|
cp -Rp $tmpdir/_data/. $install_dir/_data
|
|
|
|
cp -Rp $tmpdir/upload/. $install_dir/upload
|
|
|
|
cp -Rp $tmpdir/galleries/. $install_dir/galleries
|
2022-07-29 23:56:30 +02:00
|
|
|
|
2022-07-30 07:35:38 +02:00
|
|
|
ynh_secure_remove --file="$tmpdir"
|
|
|
|
|
2023-10-05 21:38:07 +02:00
|
|
|
chmod 750 "$data_dir"
|
|
|
|
chmod -R o-rwx "$data_dir"
|
|
|
|
chown -R $app:www-data "$data_dir"
|
2022-07-29 23:56:30 +02: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
|
|
|
#=================================================
|
2021-05-16 19:41:11 +02:00
|
|
|
ynh_script_progression --message="Setuping application with CURL..." --weight=5
|
2017-09-22 21:18:40 +02:00
|
|
|
|
2021-02-18 19:52:56 +01:00
|
|
|
# Reload NGINX
|
2023-10-05 21:48:46 +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
|
|
|
if [ "$language" = "fr" ]; then
|
2019-02-17 19:28:37 +01:00
|
|
|
applanguage="fr_FR"
|
|
|
|
else
|
|
|
|
applanguage="en_UK"
|
|
|
|
fi
|
|
|
|
|
2021-02-18 19:52:56 +01: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
|
|
|
|
2021-02-18 19:52:56 +01:00
|
|
|
# Installation with cURL
|
2023-12-04 22:43:13 +01:00
|
|
|
ynh_local_curl "/install.php?language=$applanguage" "install=true" "dbhost=127.0.0.1" "dbuser=$db_user" "dbpasswd=$db_pwd" "dbname=$db_name" "prefix=" "admin_name=$admin" "admin_pass1=$password" "admin_pass2=$password" "admin_mail=$mail"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CONFIGURE PIWIGO
|
|
|
|
#=================================================
|
2020-11-12 18:28:43 +01: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
|
2023-10-05 21:38:07 +02:00
|
|
|
ynh_add_config --template="../conf/config.inc.php" --destination="$install_dir/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
|
2023-10-05 21:38:07 +02:00
|
|
|
ynh_add_config --template="../conf/database.inc.php" --destination="$install_dir/local/config/database.inc.php"
|
2019-02-17 19:28:37 +01:00
|
|
|
|
2023-10-05 21:38:07 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
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
|
2023-12-04 22:43:13 +01:00
|
|
|
ynh_local_curl "/ws.php?format=json" "method=pwg.session.login" "username=$admin" "password=$password"
|
2021-08-26 23:39:52 +02:00
|
|
|
# Get session token
|
2020-02-29 21:56:40 +01:00
|
|
|
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"
|
2021-08-26 23:39:52 +02:00
|
|
|
# Log out
|
2020-02-29 21:56:40 +01:00
|
|
|
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
|
|
|
#=================================================
|
2021-05-16 19:41:11 +02:00
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP FAIL2BAN
|
2019-02-17 19:28:37 +01:00
|
|
|
#=================================================
|
2020-11-12 18:28:43 +01: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
|
|
|
|
|
2019-02-17 20:58:31 +01:00
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-05-16 19:41:11 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|