#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=5 # Create tmp directory and fetch app inside tmpdir="$(ynh_smart_mktemp --min_size=300)" ynh_setup_source --dest_dir="$tmpdir" # Fetch needed plugins mkdir -p $tmpdir/plugins/Ldap_Login 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 # sets extended pattern matching options in the bash shell shopt -s extglob # Install files and set permissions cp -a $tmpdir/!(upload|_data|galleries) $install_dir chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 ynh_add_fpm_config ynh_add_nginx_config #================================================= # SPECIFIC SETUP #================================================= # CREATE DATA DIRECTORY #================================================= ynh_script_progression --message="Creating a data directory..." ln -sd $data_dir/_data $install_dir/_data ln -sd $data_dir/upload $install_dir/upload ln -sd $data_dir/galleries $install_dir/galleries cp -Rp $tmpdir/_data/. $install_dir/_data cp -Rp $tmpdir/upload/. $install_dir/upload cp -Rp $tmpdir/galleries/. $install_dir/galleries ynh_secure_remove --file="$tmpdir" chmod 750 "$data_dir" chmod -R o-rwx "$data_dir" chown -R $app:www-data "$data_dir" #================================================= # SETUP APPLICATION WITH CURL #================================================= ynh_script_progression --message="Setuping application with CURL..." --weight=5 # Generate random password for admin if [ "$language" = "fr" ]; then applanguage="fr_FR" else applanguage="en_UK" fi # Configure Piwigo via cURL mail="$(ynh_user_get_info --username=$admin --key=mail)" # Installation with cURL 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" #================================================= # CONFIGURE PIWIGO #================================================= ynh_script_progression --message="Configuring $app..." --weight=2 # Change local config ynh_add_config --template="config.inc.php" --destination="$install_dir/local/config/config.inc.php" # Setup database in local/config/database.inc.php ynh_add_config --template="database.inc.php" --destination="$install_dir/local/config/database.inc.php" chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= # ADD LDAP PLUGIN #================================================= ynh_script_progression --message="Configuring LDAP plugin..." --weight=2 # 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=$password" # 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';" #================================================= # GENERIC FINALIZATION #================================================= # SETUP FAIL2BAN #================================================= ynh_script_progression --message="Configuring Fail2Ban..." --weight=6 # Configure and activate log_failed_logins plugin 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');" touch "/var/log/${app}FailedLogins.log" chown $app: "/var/log/${app}FailedLogins.log" ynh_add_fail2ban_config --logpath="/var/log/${app}FailedLogins.log" --failregex="ip=" --max_retry=6 #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last