2016-11-26 16:25:18 +01:00
|
|
|
#!/bin/bash
|
2017-06-03 18:13:29 +02:00
|
|
|
shopt -s extglob # sets extended pattern matching options in the bash shell
|
2016-11-26 16:25:18 +01:00
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-11-26 16:25:18 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-01-03 18:32:00 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
# Set app specific variables
|
2016-11-26 16:25:18 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Check destination directory
|
|
|
|
DESTDIR="/var/www/$app"
|
|
|
|
[[ ! -d $DESTDIR ]] && ynh_die \
|
|
|
|
"The destination directory '$DESTDIR' does not exist.\
|
|
|
|
The app is not correctly installed, you should remove it first."
|
2017-01-03 18:32:00 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Retrieve arguments
|
2016-11-26 16:25:18 +01:00
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
2017-06-03 18:13:29 +02:00
|
|
|
path_url=$(ynh_app_setting_get "$app" path_url)
|
|
|
|
# Compatibility with previous version
|
|
|
|
if [ -z "$path_url" ] ; then
|
|
|
|
path_url=$(ynh_app_setting_get "$app" path)
|
|
|
|
ynh_app_setting_set $app path_url "$path_url"
|
|
|
|
fi
|
|
|
|
path_url=$(ynh_normalize_url_path $path_url)
|
|
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
|
|
# Compatibility with previous version
|
|
|
|
if [ -z "$final_path" ] ; then
|
|
|
|
final_path="/var/www/$app"
|
|
|
|
ynh_app_setting_set $app final_path "$final_path"
|
|
|
|
fi
|
|
|
|
db_name=$(ynh_app_setting_get "$app" db_name)
|
|
|
|
# Compatibility with previous version
|
|
|
|
if [ -z "$db_name" ] ; then
|
|
|
|
db_name=$app
|
|
|
|
ynh_app_setting_set "$app" db_name "$db_name"
|
|
|
|
fi
|
|
|
|
db_user="$db_name"
|
|
|
|
db_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
|
2016-11-26 16:25:18 +01:00
|
|
|
admin=$(ynh_app_setting_get "$app" admin)
|
2017-06-03 18:13:29 +02:00
|
|
|
admin_pwd=$(ynh_app_setting_get "$app" admin_pwd)
|
|
|
|
# Compatibility with previous version; password not set
|
|
|
|
if [ -z "$admin_pwd" ] ; then
|
|
|
|
# Generate a new password
|
|
|
|
admin_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
|
|
# Compute password hash with the Piwigo function
|
|
|
|
sudo cp ../conf/hash_password.php $final_path
|
|
|
|
hashed_password=$(cd $final_path ; php hash_password.php $admin_pwd)
|
|
|
|
# Update password hash in database
|
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "UPDATE users SET password='$hashed_password' WHERE username='$admin';"
|
|
|
|
ynh_app_setting_set $app admin_pwd "$admin_pwd"
|
|
|
|
ynh_secure_remove "$final_path/hash_password.php"
|
|
|
|
fi
|
2016-11-26 16:25:18 +01:00
|
|
|
language=$(ynh_app_setting_get "$app" language)
|
2017-06-03 18:13:29 +02:00
|
|
|
if [ "$language" = "fr" ] ; then
|
|
|
|
applanguage="fr_FR"
|
|
|
|
else
|
|
|
|
applanguage="en_UK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Use prior backup and restore on error only if backup feature
|
|
|
|
# exists on installed instance
|
|
|
|
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
|
|
|
|
ynh_backup_before_upgrade # Backup the current version of the app
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_backup_after_failed_upgrade
|
|
|
|
}
|
|
|
|
ynh_abort_if_errors # Stop script if an error is detected
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create tmp directory and fetch app inside
|
|
|
|
TMPDIR=$(ynh_mkdir_tmp)
|
|
|
|
ynh_setup_source "$TMPDIR"
|
2016-11-26 16:25:18 +01:00
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app # Create dedicated user if not existing
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Install files and set permissions
|
|
|
|
sudo cp -a $TMPDIR/!(upload|galleries) $final_path
|
|
|
|
|
|
|
|
sudo cp -a $TMPDIR/galleries/* $final_path/galleries/
|
|
|
|
|
|
|
|
sudo cp -R ../plugins/Ldap_Login/* $final_path/plugins/Ldap_Login
|
|
|
|
|
|
|
|
sudo chown -R $app: $final_path
|
|
|
|
sudo chown -R $app: /home/yunohost.app/$app
|
|
|
|
sudo chmod 755 -R $final_path/galleries
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-11-26 16:25:18 +01:00
|
|
|
# Set permissions and reload nginx (needed at this stage for the PHP piwigo installation process)
|
2017-06-03 18:13:29 +02:00
|
|
|
sudo systemctl reload nginx
|
|
|
|
sleep 5s
|
|
|
|
sudo systemctl reload php5-fpm
|
2016-12-30 17:32:19 +01:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2016-11-26 16:25:18 +01:00
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
|
2017-06-03 18:13:29 +02:00
|
|
|
# Configure piwigo via curl
|
|
|
|
sleep 5s
|
|
|
|
ynh_local_curl "/upgrade.php?language=$applanguage&now=true" "language=$applanguage" "username=$admin" "password=$admin_pwd"
|
|
|
|
|
|
|
|
# Change local config
|
|
|
|
sudo cp ../conf/config.inc.php $final_path/local/config/
|
2016-11-26 16:25:18 +01: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
|
|
|
|
sudo cp ../conf/database.inc.php $final_path/local/config/database.inc.php
|
|
|
|
|
|
|
|
# Activate ldap plugin
|
|
|
|
ynh_mysql_connect_as $db_name $db_pwd $db_user <<< "UPDATE plugins SET state='active' WHERE id='Ldap_Login';"
|
|
|
|
|
|
|
|
# Protect URIs if private
|
2016-11-26 16:25:18 +01:00
|
|
|
if [ $is_public -eq 0 ];
|
|
|
|
then
|
2016-12-30 17:32:19 +01:00
|
|
|
ynh_app_setting_delete "$app" unprotected_uris
|
|
|
|
ynh_app_setting_set "$app" protected_uris "/"
|
2017-06-03 18:13:29 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
sudo systemctl restart php5-fpm
|
|
|
|
sudo systemctl reload nginx
|