1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/piwigo_ynh.git synced 2024-09-03 20:06:03 +02:00
piwigo_ynh/scripts/install

244 lines
7.6 KiB
Text
Raw Normal View History

2014-07-06 13:21:10 +02:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2014-07-06 13:21:10 +02:00
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# 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
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
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
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Validating installation parameters..."
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
2019-02-17 19:28:37 +01:00
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Storing installation settings..."
2019-02-17 19:28:37 +01:00
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $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
#=================================================
2017-09-23 10:25:23 +02:00
# INSTALL DEPENDENCIES
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Installing dependencies..."
2017-09-23 10:25:23 +02:00
ynh_install_app_dependencies "$pkg_dependencies"
2014-07-06 13:21:10 +02:00
#=================================================
# CREATE A MYSQL DB
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Creating a MySQL database..."
2014-07-06 13:21:10 +02:00
db_name=$(ynh_sanitize_dbid $app)
2019-02-17 19:28:37 +01:00
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
2014-07-06 13:21:10 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Setting up source files..."
2019-02-17 19:28:37 +01:00
ynh_app_setting_set $app final_path $final_path
# Create tmp directory and fetch app inside
2019-02-17 19:28:37 +01:00
tmpdir="$(ynh_smart_mktemp --min_size=300)"
ynh_setup_source "$tmpdir"
2019-02-17 19:28:37 +01:00
# Fetch needed plugins
mkdir -p $tmpdir/plugins/Ldap_Login
ynh_setup_source "$tmpdir/plugins/Ldap_Login" ldap_plugin
ynh_setup_source "$tmpdir/plugins" log_failed_logins_plugin
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Configuring system user..."
2019-02-17 19:28:37 +01:00
# Create a system user
ynh_system_user_create $app
#=================================================
# NGINX CONFIGURATION
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Configuring nginx web server..."
2019-02-17 19:28:37 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# 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
# Install files and set permissions
mkdir $final_path
cp -a $tmpdir/!(upload|_data|galleries) $final_path
2014-07-06 13:21:10 +02:00
datapath=/home/yunohost.app/$app
mkdir -p $datapath/_data
mkdir -p $datapath/upload
mkdir -p $datapath/galleries
ln -sd $datapath/_data $final_path/_data
ln -sd $datapath/upload $final_path/upload
ln -sd $datapath/galleries $final_path/galleries
cp -Rp $tmpdir/_data/. $final_path/_data
cp -Rp $tmpdir/upload/. $final_path/upload
cp -Rp $tmpdir/galleries/. $final_path/galleries
chown -R $app: $final_path
chown -R $app: $datapath
chmod 755 -R $final_path/_data
2019-02-17 19:28:37 +01:00
ynh_secure_remove "$tmpdir"
#=================================================
2019-02-17 19:28:37 +01:00
# PHP-FPM CONFIGURATION
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Configuring php-fpm..."
2019-02-17 19:28:37 +01:00
# Create a dedicated php-fpm config
ynh_add_fpm_config
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-02-17 20:58:31 +01:00
ynh_print_info "Installing piwigo with Curl..."
2017-09-22 21:18:40 +02:00
2019-02-17 19:28:37 +01:00
ynh_app_setting_set $app unprotected_uris "/"
# Reload SSOwat config
yunohost app ssowatconf
2014-07-06 13:21:10 +02:00
2019-02-17 19:28:37 +01:00
# Reload Nginx
systemctl reload nginx
2014-07-06 13:21:10 +02:00
2019-02-17 19:28:37 +01:00
# Generate random password for admin
2017-09-16 12:34:25 +02:00
adm_pwd=$(ynh_string_random 24)
ynh_app_setting_set $app admin_pwd "$adm_pwd"
2014-07-06 13:21:10 +02:00
2019-02-17 19:28:37 +01:00
if [ "$language" = "fr" ] ; then
applanguage="fr_FR"
else
applanguage="en_UK"
fi
# Configure piwigo via curl
2017-09-10 09:22:44 +02:00
mail="$(ynh_user_get_info $admin 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-02-17 20:58:31 +01:00
ynh_print_info "Configuring piwigo..."
2014-07-06 13:21:10 +02:00
# Change local config
cp ../conf/config.inc.php $final_path/local/config/
2019-02-17 19:28:37 +01:00
# 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
# Setup database in local/config/database.inc.php
2019-02-17 19:28:37 +01:00
ynh_replace_string "__DBTOCHANGE__" "$db_name" ../conf/database.inc.php
ynh_replace_string "__USERTOCHANGE__" "$db_name" ../conf/database.inc.php
ynh_replace_string "__PASSTOCHANGE__" "$db_pwd" ../conf/database.inc.php
cp ../conf/database.inc.php $final_path/local/config/database.inc.php
2019-02-17 19:28:37 +01:00
# 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
#=================================================
2019-02-17 19:28:37 +01:00
# ADD LDAP PLUGINS
2017-09-22 21:18:40 +02:00
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Configuring LDAP plugin..."
2017-09-22 21:18:40 +02:00
2017-11-19 19:42:54 +01:00
# Configure and activate LDAP plugin
2019-02-17 19:28:37 +01:00
ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "INSERT INTO plugins (id,state,version) VALUES ('Ldap_Login','active','1.1');"
2017-11-19 19:42:54 +01:00
cp ../conf/data.dat $final_path/plugins/Ldap_Login
2014-07-06 13:21:10 +02:00
2019-02-17 19:28:37 +01:00
#=================================================
# CONFIGURE FAIL2BAN
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Configuring fail2ban..."
2019-02-17 19:28:37 +01:00
# Configure and activate log_failed_logins plugin
2019-02-17 19:28:37 +01:00
ynh_mysql_connect_as $db_name $db_pwd $db_name <<< "INSERT INTO plugins (id,state,version) VALUES ('log_failed_logins','active','1.2');"
ynh_mysql_connect_as $db_name $db_pwd $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"
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-02-17 20:58:31 +01:00
ynh_print_info "Configuring SSOwat..."
# 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-02-17 19:28:37 +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
#=================================================
# RELOAD NGINX
#=================================================
2019-02-17 20:58:31 +01:00
ynh_print_info "Reloading nginx web server..."
2019-02-17 19:28:37 +01:00
systemctl reload nginx
2019-02-17 19:28:37 +01:00
2019-02-17 20:58:31 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Installation of $app completed"