mirror of
https://github.com/YunoHost-Apps/spip_ynh.git
synced 2024-09-03 20:25:59 +02:00
266 lines
10 KiB
Bash
266 lines
10 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
password=$(ynh_app_setting_get --app=$app --key=password)
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
users_status=$(ynh_app_setting_get --app=$app --key=users_status)
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
db_user=$db_name
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
if [ $migration_process -eq 1 ]; then
|
|
yunohost app remove $app
|
|
# Reload some values changed by the migration process
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
fi
|
|
# Restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
# Remove is_public
|
|
if [ -n "$(ynh_app_setting_get --app=$app --key=is_public)" ]; then
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
fi
|
|
|
|
# If db_name doesn't exist, create it
|
|
if [ -z $db_name ]; then
|
|
db_name=$app
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
fi
|
|
|
|
# If final_path doesn't exist, create it
|
|
if [ -z $final_path ]; then
|
|
final_path=/var/www/$app
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
fi
|
|
|
|
# If users_status doesn't exist, create it
|
|
if [ -z $users_status ]; then
|
|
users_status="Editor"
|
|
ynh_app_setting_set --app=$app --key=users_status --value=$users_status
|
|
fi
|
|
|
|
if [ -z $password ]; then
|
|
# Generate random password
|
|
password=$(ynh_string_random --length=8)
|
|
|
|
echo "The new version of SPIP provide a new password. You can change it in the private area." > mail_to_send
|
|
echo "" >> mail_to_send
|
|
echo "This password is: $password" >> mail_to_send
|
|
|
|
ynh_send_readme_to_admin --app_message="mail_to_send" --type="upgrade"
|
|
|
|
ynh_app_setting_set --app=$app --key=password --value=$password
|
|
fi
|
|
|
|
# Cleaning legacy permissions
|
|
if ynh_legacy_permissions_exists; then
|
|
ynh_legacy_permissions_delete_all
|
|
fi
|
|
|
|
#=================================================
|
|
# HANDLE MIGRATION FROM SPIP2
|
|
#=================================================
|
|
|
|
ynh_handle_app_migration "spip2" "spip2_migration"
|
|
if [ $migration_process -eq 1 ]; then
|
|
# If a migration has been perform
|
|
# Reload some values changed by the migration process
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
fi
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
fi
|
|
|
|
chmod 750 "$final_path"
|
|
chmod -R o-rwx "$final_path"
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
|
|
|
|
# Create a dedicated PHP-FPM config
|
|
ynh_add_fpm_config
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# SETUP APPLICATION WITH CURL
|
|
#=================================================
|
|
ynh_script_progression --message="Setuping application with CURL..."
|
|
|
|
# Set right permissions for curl install
|
|
mkdir -p $final_path/plugins/auto
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
# Set the app as temporarily public for curl call
|
|
ynh_script_progression --message="Configuring SSOwat..."
|
|
|
|
ynh_backup_if_checksum_is_different --file="$final_path/config/connect.php"
|
|
|
|
mv $final_path/config/connect.php $final_path/config/connect.php.ynh_bkp
|
|
|
|
# Installation with curl
|
|
ynh_script_progression --message="Finalizing installation..."
|
|
ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=chmod"
|
|
ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=2" "chmod=750" "adresse_db=localhost" "login_db=$db_name" "pass_db=$db_pwd" "server_db=mysql"
|
|
ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=3" "adresse_db=localhost" "login_db=$db_name" "pass_db=$db_pwd" "server_db=mysql" "choix_db=$db_name" "tprefix=$db_name"
|
|
# For now spip have a problem with LDAP
|
|
#ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=ldap1"
|
|
#ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=ldap2" "adresse_ldap=localhost" "port_ldap=389" "tls_ldap=no" "protocole_ldap=3"
|
|
#ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=ldap3" "adresse_ldap=localhost" "port_ldap=389" "tls_ldap=no" "protocole_ldap=3"
|
|
#ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=ldap4" "adresse_ldap=localhost" "port_ldap=389" "tls_ldap=no" "protocole_ldap=3" "base_ldap=dc=yunohost,dc=org"
|
|
#
|
|
## statut_ldap can take: 0minirezo for Administrator, 1comite for Editor, 6forum for Visitor
|
|
#if [ $users_status = "Administrator" ]; then
|
|
# status="0minirezo"
|
|
#elif [ $users_status = "Editor" ]; then
|
|
# status="1comite"
|
|
#else
|
|
# status="6forum"
|
|
#fi
|
|
#ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=ldap5" "adresse_ldap=localhost" "port_ldap=389" "tls_ldap=no" "protocole_ldap=3" "base_ldap=dc=yunohost,dc=org" "statut_ldap=$status" "ldap_login=sAMAccountName,uid,login,userid,cn,sn" "ldap_nom=cn" "ldap_email=mail" "ldap_bio=description"
|
|
#ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=3" "ldap_present=true"
|
|
|
|
# Fix db initialization
|
|
ynh_local_curl "/ecrire/?exec=install" "etape=3b"
|
|
|
|
email=$(yunohost user info $admin | grep mail: | cut -d' ' -f2 | tr -d '\n')
|
|
ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=3b" "adresse_db=localhost" "login_db=$db_name" "pass_db=$db_pwd" "server_db=mysql" "sel_db=$db_name" "nom=$admin" "email=$email" "login=$admin" "pass=$password" "pass_verif=$password"
|
|
ynh_local_curl "/ecrire/?suivant" "exec=install" "etape=fin"
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
|
|
#ynh_replace_string --match_string="'','utf8');" --replace_string="'ldap.php','utf8');" --target_file=$final_path/config/connect.php
|
|
cp ../conf/mes_options.php $final_path/config/mes_options.php
|
|
|
|
#=================================================
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
#=================================================
|
|
|
|
if [ ! -f $final_path/config/connect.php ]; then
|
|
mv $final_path/config/connect.php.ynh_bkp $final_path/config/connect.php
|
|
else
|
|
ynh_secure_remove --file="$final_path/config/connect.php.ynh_bkp"
|
|
fi
|
|
|
|
ynh_store_file_checksum --file="$final_path/config/connect.php"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# SEND INFORMATION
|
|
#=================================================
|
|
|
|
echo "To finish the upgrade, you may have to update the database by clicking on the button (if asked) at this location: https://$domain$path_url/ecrire/" > mail_to_send
|
|
|
|
ynh_send_readme_to_admin --app_message="mail_to_send" --type="upgrade"
|
|
|
|
if [ $migration_process -eq 1 ]
|
|
then
|
|
ynh_script_progression --message="Spip2 has been successfully migrated to Spip! \
|
|
A last scheduled operation will run in a couple of minutes to finish the \
|
|
migration in YunoHost side. Do not proceed any application operation while \
|
|
you don't see Spip as installed."
|
|
|
|
# Execute a post migration script after the end of this upgrade.
|
|
# Mainly for some cleaning
|
|
script_post_migration=spip2_post_migration.sh
|
|
cp ../conf/$script_post_migration /tmp
|
|
ynh_replace_string --match_string="__OLD_APP__" --replace_string="$old_app" --target_file=/tmp/$script_post_migration
|
|
ynh_replace_string --match_string="__NEW_APP__" --replace_string="$app" --target_file=/tmp/$script_post_migration
|
|
chmod +x /tmp/$script_post_migration
|
|
(cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes)
|
|
fi
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|