2014-07-06 13:21:10 +02:00
|
|
|
#!/bin/bash
|
2017-06-03 18:13:29 +02:00
|
|
|
shopt -s extglob # sets extended pattern matching options in the bash shell
|
2014-07-06 13:21:10 +02:00
|
|
|
|
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
|
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
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
ynh_abort_if_errors # Stop script if an error is detected
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Retrieve app id
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-01-03 18:32:00 +01:00
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Retrieve arguments
|
|
|
|
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
|
|
|
|
|
|
|
|
if [ "$language" = "fr" ] ; then
|
|
|
|
applanguage="fr_FR"
|
|
|
|
else
|
|
|
|
applanguage="en_UK"
|
2014-07-06 13:21:10 +02:00
|
|
|
fi
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url) # Check and normalize path
|
2017-09-11 22:00:57 +02:00
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Check web path availability
|
|
|
|
ynh_webpath_available $domain $path_url
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_app_setting_set $app domain "$domain"
|
|
|
|
ynh_app_setting_set $app path_url "$path_url"
|
|
|
|
ynh_app_setting_set $app admin "$admin"
|
|
|
|
ynh_app_setting_set $app is_public "$is_public"
|
|
|
|
ynh_app_setting_set $app language "$language"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE A MYSQL DB
|
|
|
|
#=================================================
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid $app)
|
|
|
|
db_user="$db_name"
|
|
|
|
ynh_app_setting_set "$app" db_name "$db_name"
|
2017-01-28 10:58:14 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Initialize database
|
|
|
|
ynh_mysql_setup_db "$db_user" "$db_name"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2016-12-27 14:41:45 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
ynh_app_setting_set $app final_path "$final_path"
|
|
|
|
# Create tmp directory and fetch app inside
|
|
|
|
TMPDIR=$(mktemp -d)
|
|
|
|
ynh_setup_source "$TMPDIR"
|
2017-06-18 18:24:10 +02:00
|
|
|
# Fetch needed plugins
|
2017-09-22 18:34:06 +02:00
|
|
|
mkdir -p $TMPDIR/plugins/Ldap_Login
|
|
|
|
ynh_setup_source "$TMPDIR/plugins/Ldap_Login" ldap_plugin
|
2017-06-18 18:24:10 +02:00
|
|
|
ynh_setup_source "$TMPDIR/plugins" log_failed_logins_plugin
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app # Create a dedicated system user
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Install files and set permissions
|
2017-09-11 22:00:57 +02:00
|
|
|
mkdir $final_path
|
|
|
|
cp -a $TMPDIR/!(upload|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-09-11 22:00:57 +02:00
|
|
|
mkdir -p $datapath
|
|
|
|
mkdir -p $datapath/galleries
|
|
|
|
mkdir -p $datapath/upload
|
2017-01-08 14:16:28 +01:00
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
ln -sd $datapath/galleries $final_path/galleries
|
|
|
|
cp -a $TMPDIR/galleries/* $final_path/galleries/
|
|
|
|
ln -sd $datapath/upload $final_path/upload
|
2017-06-03 18:13:29 +02:00
|
|
|
|
2017-09-11 22:00:57 +02:00
|
|
|
chown -R $app: $final_path
|
|
|
|
chown -R $app: $datapath
|
|
|
|
chmod 755 -R $final_path/galleries
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
2017-09-22 21:18:40 +02:00
|
|
|
# NGINX AND PHP-FPM CONFIGURATION
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_add_nginx_config
|
|
|
|
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
|
|
|
# Copy and set php-fpm configuration
|
|
|
|
ynh_add_fpm_config
|
2017-02-08 18:32:46 +01:00
|
|
|
|
2017-09-22 21:18:40 +02:00
|
|
|
#=================================================
|
|
|
|
# CONFIGURE PIWIGO
|
|
|
|
#=================================================
|
|
|
|
|
2016-09-11 10:15:45 +02:00
|
|
|
# Set permissions and reload nginx (needed at this stage for the PHP piwigo installation process)
|
2017-09-11 22:00:57 +02:00
|
|
|
systemctl reload nginx
|
2017-06-03 18:13:29 +02:00
|
|
|
sleep 5s
|
2017-09-11 22:00:57 +02:00
|
|
|
systemctl reload php5-fpm
|
2016-12-30 17:32:19 +01:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2017-09-11 22:00:57 +02:00
|
|
|
yunohost app ssowatconf
|
2014-07-06 13:21:10 +02:00
|
|
|
|
|
|
|
# Generate random password for admin
|
|
|
|
|
2017-09-16 12:34:25 +02:00
|
|
|
adm_pwd=$(ynh_string_random 24)
|
2017-06-03 18:13:29 +02:00
|
|
|
ynh_app_setting_set $app admin_pwd "$adm_pwd"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Configure piwigo via curl
|
|
|
|
sleep 5s
|
2017-09-10 09:22:44 +02:00
|
|
|
mail="$(ynh_user_get_info $admin mail)"
|
|
|
|
ynh_local_curl "/install.php?language=$applanguage" "install=true" "dbuser=$db_user" "dbpasswd=$db_pwd" "dbname=$db_name" "admin_name=$admin" "admin_pass1=$adm_pwd" "admin_pass2=$adm_pwd" "admin_mail=$mail"
|
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/
|
|
|
|
# Calculate and store the config file checksum
|
|
|
|
ynh_store_file_checksum "$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
|
|
|
|
ynh_replace_string "DBTOCHANGE" "$db_name" ../conf/database.inc.php
|
|
|
|
ynh_replace_string "USERTOCHANGE" "$db_user" ../conf/database.inc.php
|
|
|
|
ynh_replace_string "PASSTOCHANGE" "$db_pwd" ../conf/database.inc.php
|
2017-09-11 22:00:57 +02:00
|
|
|
cp ../conf/database.inc.php $final_path/local/config/database.inc.php
|
|
|
|
# Calculate and store the database config file checksum
|
|
|
|
ynh_store_file_checksum "$final_path/local/config/database.inc.php"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2017-09-22 21:18:40 +02:00
|
|
|
#=================================================
|
|
|
|
# ADD LDAP & FAIL2BAN PLUGINS
|
|
|
|
#=================================================
|
|
|
|
|
2017-06-18 18:24:10 +02:00
|
|
|
# Activate LDAP plugin
|
2017-06-03 18:13:29 +02:00
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "INSERT INTO plugins (id,state,version) VALUES ('Ldap_Login','active','1.1');"
|
2014-07-06 13:21:10 +02:00
|
|
|
|
2017-06-18 18:24:10 +02:00
|
|
|
# Configure and activate log_failed_logins plugin
|
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "INSERT INTO plugins (id,state,version) VALUES ('log_failed_logins','active','1.2');"
|
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "INSERT INTO config (param, value) VALUES ('logFailedLoginsFilename','/var/log/${app}FailedLogins.log');"
|
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
|
|
|
|
|
|
|
# Set-up fail2ban
|
|
|
|
ynh_add_fail2ban_config "/var/log/${app}FailedLogins.log" "ip=<HOST>" 6
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Protect URIs if private
|
2016-09-11 10:15:45 +02:00
|
|
|
if [ $is_public -eq 0 ];
|
2014-07-06 13:21:10 +02:00
|
|
|
then
|
2016-12-30 17:32:19 +01:00
|
|
|
ynh_app_setting_delete "$app" unprotected_uris
|
|
|
|
ynh_app_setting_set "$app" protected_uris "/"
|
2014-07-06 13:21:10 +02:00
|
|
|
fi
|
2017-06-03 18:13:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2017-09-11 22:00:57 +02:00
|
|
|
systemctl reload nginx
|