1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dotclear2_ynh.git synced 2024-09-03 18:26:29 +02:00

Prepare the HQ tag

This commit is contained in:
Kay0u 2020-04-17 14:38:01 +02:00
parent e8501c7e24
commit 8cd96e82c4
No known key found for this signature in database
GPG key ID: AE1DCADB6415A156
9 changed files with 274 additions and 341 deletions

View file

@ -427,4 +427,4 @@ chdir = __FINALPATH__
; php_admin_value[max_execution_time] = 600
; php_admin_value[max_input_time] = 300
; php_admin_value[memory_limit] = 256M
; php_admin_flag[short_open_tag] = On
; php_admin_flag[short_open_tag] = On

View file

@ -1,74 +1,17 @@
# Curl abstraction to help with POST requests to local pages (such as installation forms)
#
# $domain and $path_url should be defined externally (and correspond to the domain.tld and the /path (of the app?))
#
# example: ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2"
#
# usage: ynh_local_curl "page_uri" "key1=value1" "key2=value2" ...
# | arg: page_uri - Path (relative to $path_url) of the page where POST data will be sent
# | arg: key1=value1 - (Optionnal) POST key and corresponding value
# | arg: key2=value2 - (Optionnal) Another POST key and corresponding value
# | arg: ... - (Optionnal) More POST keys and values
ynh_local_curl () {
# Define url of page to curl
path_url=$(ynh_normalize_url_path $path_url)
local local_page=$(ynh_normalize_url_path $1)
local full_path=$path_url$local_page
if [ "${path_url}" == "/" ]; then
full_path=$local_page
fi
local full_page_url=https://localhost$full_path
#!/bin/bash
# Concatenate all other arguments with '&' to prepare POST data
local POST_data=""
local arg=""
for arg in "${@:2}"
do
POST_data="${POST_data}${arg}&"
done
if [ -n "$POST_data" ]
then
# Add --data arg and remove the last character, which is an unecessary '&'
POST_data="--data ${POST_data::-1}"
fi
# Wait untils nginx has fully reloaded (avoid curl fail with http2)
sleep 2
#=================================================
# COMMON VARIABLES
#=================================================
# Curl the URL
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url"
}
#=================================================
# PERSONAL HELPERS
#=================================================
# Join several urls together
# Return a concatenate normalized url path
#
# example: url_path=$(ynh_url_join $url_path /admin /index.php)
# ynh_url_join example admin index.php -> /example/admin/index.php
# ynh_url_join /example admin /index.php -> /example/admin/index.php
# ynh_url_join / -> /
#
# usage: ynh_url_join url1 url2 ...
ynh_url_join() {
if [ "$#" -eq 0 ]; then
ynh_die "Illegal number of parameters"
fi
local full_url=""
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
for var in "$@"
do
if [ "${var:0:1}" != "/" ]; then # If the first character is not a /
var="/$var" # Add / at begin of path variable
fi
if [ "${var:${#var}-1}" == "/" ]; then # If the last character is a /
var="${var:0:${#var}-1}" # Delete the last character
fi
full_url=${full_url}${var}
done
full_url=$(ynh_normalize_url_path ${full_url:-'/'})
echo $full_url
}
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -6,52 +6,60 @@
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Backing up the main app directory..."
ynh_backup "$final_path"
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Backing up nginx web server configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Backing up php-fpm configuration..."
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Backing up the MySQL database..."
ynh_mysql_dump_db "$db_name" > db.sql
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last

View file

@ -24,24 +24,27 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
ynh_script_progression --message="Loading installation settings..."
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# Add settings here as needed by your application
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --weight=4
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails
ynh_restore_upgradebackup
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -53,13 +56,13 @@ ynh_abort_if_errors
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
change_path=1
fi
#=================================================
@ -67,30 +70,30 @@ fi
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1
ynh_script_progression --message="Updating nginx web server configuration..." --weight=2
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated nginx config
ynh_add_nginx_config
# Make a backup of the original nginx config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated nginx config
ynh_add_nginx_config
fi
# Change the domain for nginx
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
@ -98,35 +101,37 @@ fi
#=================================================
# UPDATE THE DATABASE
#=================================================
ynh_script_progression --message="Updating database..."
new_index_url=$(ynh_url_join $new_path /index.php)
ynh_mysql_execute_as_root --sql="UPDATE dc_blog SET blog_url='https://$new_domain$new_index_url?' WHERE dc_blog.blog_id='default'" --database=$app
new_public_url=$(ynh_url_join $new_path /public)
ynh_mysql_execute_as_root --sql="UPDATE dc_setting SET setting_value='$new_public_url' WHERE dc_setting.setting_id='public_url'" --database=$app
new_themes_url=$(ynh_url_join $new_path /themes)
ynh_mysql_execute_as_root --sql="UPDATE dc_setting SET setting_value='$new_themes_url' WHERE dc_setting.setting_id='themes_url'" --database=$app
new_index_url="${new_path%/}/index.php"
new_public_url="${new_path%/}/public"
new_themes_url="${new_path%/}/themes"
ynh_mysql_execute_as_root --sql="UPDATE dc_blog SET blog_url='https://$new_domain$new_index_url?' WHERE dc_blog.blog_id='default'" --database=$db_name
ynh_mysql_execute_as_root --sql="UPDATE dc_setting SET setting_value='$new_public_url' WHERE dc_setting.setting_id='public_url'" --database=$db_name
ynh_mysql_execute_as_root --sql="UPDATE dc_setting SET setting_value='$new_themes_url' WHERE dc_setting.setting_id='themes_url'" --database=$db_name
#=================================================
# UPDATE CONFIGURATION
#=================================================
ynh_script_progression --message="Updating configuration file..."
php_config=$final_path/inc/config.php
ynh_backup_if_checksum_is_different "$php_config"
ynh_backup_if_checksum_is_different --file="$php_config"
old_admin_url=$(ynh_url_join $old_path admin/index.php)
new_admin_url=$(ynh_url_join $new_path admin/index.php)
ynh_replace_string "'DC_ADMIN_URL', 'https://$old_domain$old_admin_url'" "'DC_ADMIN_URL', 'https://$new_domain$new_admin_url'" $php_config
new_admin_url="${new_path%/}/admin/index.php"
old_admin_url="${old_path%/}/admin/index.php"
ynh_replace_string --match_string="'DC_ADMIN_URL', 'https://$old_domain$old_admin_url'" --replace_string="'DC_ADMIN_URL', 'https://$new_domain$new_admin_url'" --target_file=$php_config
ynh_store_file_checksum "$php_config"
ynh_store_file_checksum --file="$php_config"
#=================================================
# GENERIC FINALISATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
@ -134,4 +139,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --time --last
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -6,17 +6,13 @@
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup() {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -33,55 +29,54 @@ admin=$YNH_APP_ARG_ADMIN
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register $app $domain $path_url
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
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=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=2
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $app $db_name
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=4
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# In case of a new version, the url change from http://download.dotclear.org/latest/dotclear-X.X.X.tar.gz to http://download.dotclear.org/attic/dotclear-X.X.X.tar.gz
src_url=$(grep 'SOURCE_URL=' "../conf/app.src" | cut -d= -f2-)
if ! curl --output /dev/null --silent --head --fail "$src_url"; then
ynh_replace_string "latest" "attic" ../conf/app.src
ynh_replace_string --match_string="latest" --replace_string="attic" --target_file="../conf/app.src"
fi
ynh_setup_source $final_path
mv $final_path/dotclear/* $final_path/
ynh_secure_remove "$final_path/dotclear"
ynh_setup_source --dest_dir="$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..."
# Create a dedicated nginx config
ynh_add_nginx_config
@ -89,52 +84,55 @@ ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
# Create a system user
ynh_system_user_create $app
ynh_system_user_create --username=$app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring php-fpm..." --weight=2
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
php_config=$final_path/inc/config.php
master_key=$(ynh_string_random 30)
ynh_app_setting_set $app master_key $master_key
firstname=$(ynh_user_get_info $admin firstname)
lastname=$(ynh_user_get_info $admin lastname)
email=$(ynh_user_get_info $admin mail)
password=$(ynh_string_random 30)
master_key=$(ynh_string_random --length=30)
ynh_app_setting_set --app=$app --key=master_key --value=$master_key
cp $php_config.in $php_config
cp ../conf/class.auth.ldap.php $final_path/inc/class.auth.ldap.php
ynh_replace_string "__APP__" "$app" $final_path/inc/class.auth.ldap.php
admin_url=$(ynh_url_join $path_url admin/index.php)
admin_url="${path_url%/}/admin/index.php"
email=$(ynh_user_get_info --username=$admin --key=mail)
# Config as if we called in admin/install/wizard.php
ynh_replace_string "'DC_DBDRIVER', ''" "'DC_DBDRIVER', 'mysqli'" $php_config
ynh_replace_string "'DC_DBHOST', ''" "'DC_DBHOST', 'localhost'" $php_config
ynh_replace_string "'DC_DBUSER', ''" "'DC_DBUSER', '$app'" $php_config
ynh_replace_string "'DC_DBPASSWORD', ''" "'DC_DBPASSWORD', '$db_pwd'" $php_config
ynh_replace_string "'DC_DBNAME', ''" "'DC_DBNAME', '$db_name'" $php_config
ynh_replace_string "'DC_MASTER_KEY', ''" "'DC_MASTER_KEY', '$master_key'" $php_config
ynh_replace_string "'DC_ADMIN_URL', ''" "'DC_ADMIN_URL', 'https://$domain$admin_url'" $php_config
ynh_replace_string "'DC_ADMIN_MAILFROM', ''" "'DC_ADMIN_MAILFROM', '$email'" $php_config
ynh_replace_string --match_string="'DC_DBDRIVER', ''" --replace_string="'DC_DBDRIVER', 'mysqli'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBHOST', ''" --replace_string="'DC_DBHOST', 'localhost'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBUSER', ''" --replace_string="'DC_DBUSER', '$db_user'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBPASSWORD', ''" --replace_string="'DC_DBPASSWORD', '$db_pwd'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBNAME', ''" --replace_string="'DC_DBNAME', '$db_name'" --target_file=$php_config
ynh_replace_string --match_string="'DC_MASTER_KEY', ''" --replace_string="'DC_MASTER_KEY', '$master_key'" --target_file=$php_config
ynh_replace_string --match_string="'DC_ADMIN_URL', ''" --replace_string="'DC_ADMIN_URL', 'https://$domain$admin_url'" --target_file=$php_config
ynh_replace_string --match_string="'DC_ADMIN_MAILFROM', ''" --replace_string="'DC_ADMIN_MAILFROM', '$email'" --target_file=$php_config
# Adding LDAP login
cp ../conf/class.auth.ldap.php $final_path/inc/class.auth.ldap.php
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/inc/class.auth.ldap.php"
cat << EOF >> $php_config
\$__autoload['myDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php';
define('DC_AUTH_CLASS','myDcAuth');
EOF
ynh_store_file_checksum $php_config
ynh_store_file_checksum --file=$php_config
#=================================================
# SETUP APPLICATION WITH CURL
@ -147,26 +145,44 @@ chown -R $app: $final_path
ynh_permission_update --permission "main" --add "visitors"
# Reload Nginx
systemctl reload nginx
ynh_systemd_action --service_name=nginx --action=reload
ynh_script_progression --message="Finalizing installation..." --weight=14
firstname=$(ynh_user_get_info --username=$admin --key=firstname)
lastname=$(ynh_user_get_info --username=$admin --key=lastname)
email=$(ynh_user_get_info --username=$admin --key=mail)
password=$(ynh_string_random --length=30)
# Installation with curl
installUrl="/admin/install/index.php"
ynh_local_curl $installUrl "u_email=$email" "u_firstname=$firstname" "u_name=$lastname" "u_login=$admin" "u_pwd=$password" "u_pwd2=$password"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
if [ $is_public -eq 0 ]; then
ynh_permission_update --permission "main" --remove "visitors"
fi
# Only the admin can access the admin panel of the app (if the app has an admin panel)
ynh_permission_create --permission "admin" --url "/admin" --allowed $admin
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
systemctl reload php7.0-fpm
systemctl reload nginx
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -6,38 +6,43 @@
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get $app final_path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Removing the MySQL database..."
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_user $db_name
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely
ynh_secure_remove "$final_path"
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing nginx web server configuration..."
# Remove the dedicated nginx config
ynh_remove_nginx_config
@ -45,6 +50,7 @@ ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Removing php-fpm configuration..."
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
@ -54,6 +60,13 @@ ynh_remove_fpm_config
#=================================================
# REMOVE DEDICATED USER
#=================================================
ynh_script_progression --message="Removing the dedicated system user..."
# Delete a system user
ynh_system_user_delete $app
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -6,39 +6,39 @@
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
@ -46,28 +46,22 @@ test ! -d $final_path \
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file "$final_path"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
ynh_restore_file --origin_path="$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=2
# Create the dedicated user (if not existing)
ynh_system_user_create $app
ynh_system_user_create --username=$app
#=================================================
# RESTORE USER RIGHTS
@ -80,13 +74,30 @@ chown -R $app: $final_path
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=3
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
systemctl reload php7.0-fpm
systemctl reload nginx
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -12,65 +12,59 @@ source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
password=$(ynh_app_setting_get $app password)
master_key=$(ynh_app_setting_get $app master_key)
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)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
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)
password=$(ynh_app_setting_get --app=$app --key=password)
master_key=$(ynh_app_setting_get --app=$app --key=master_key)
skipped_uris=$(ynh_app_setting_get $app skipped_uris)
unprotected_uris=$(ynh_app_setting_get $app unprotected_uris)
protected_uris=$(ynh_app_setting_get $app protected_uris)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_print_info "Ensuring downward compatibility..."
ynh_script_progression --message="Ensuring downward compatibility..."
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid --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
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
# Delete skipped_uris if it exists
if [ ! -z $skipped_uris ]; then
ynh_app_setting_delete $app skipped_uris
fi
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
# Delete unprotected_uris if it exists
if [ ! -z $unprotected_uris ]; then
ynh_app_setting_delete $app unprotected_uris
fi
if [ -n "$is_public" ]; then
# Remove unprotected_uris
ynh_app_setting_delete --app=$app --key=unprotected_uris
# Remove protected_uris
ynh_app_setting_delete --app=$app --key=protected_uris
# Delete protected_uris if it exists
if [ ! -z $protected_uris ]; then
ynh_app_setting_delete $app protected_uris
fi
# If password exists, remove it
if [ ! -z $password ]; then
ynh_app_setting_delete $app password
fi
# Delete is_public if it exists
if [ ! -z $is_public ]; then
if [ "$is_public" = "1" ]; then
# Removing skipped/unprotected_uris under certain conditions, remove the visitors group added during the migration process of 3.7
# Remove skipped_uris. If the app was public, add visitors again to the main permission
if ynh_permission_has_user --permission=main --user=visitors
then
ynh_app_setting_delete --app=$app --key=skipped_uris
ynh_permission_update --permission "main" --add "visitors"
else
ynh_app_setting_delete --app=$app --key=skipped_uris
fi
ynh_app_setting_delete --app=$app --key=is_public
fi
@ -78,7 +72,7 @@ fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_print_info "Backing up the app before upgrading (may take a while)..."
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4
# Backup the current version of the app
ynh_backup_before_upgrade
@ -94,39 +88,32 @@ ynh_abort_if_errors
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
path_url=$(ynh_normalize_url_path --path_url=$path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_print_info "Upgrading source files..."
ynh_script_progression --message="Upgrading source files..." --weight=4
php_config=$final_path/inc/config.php
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
# Download, check integrity, uncompress and patch the source from app.src
# In case of a new version, the url change from http://download.dotclear.org/latest/dotclear-X.X.X.tar.gz to http://download.dotclear.org/attic/dotclear-X.X.X.tar.gz
src_url=$(grep 'SOURCE_URL=' "../conf/app.src" | cut -d= -f2-)
if ! curl --output /dev/null --silent --head --fail "$src_url"; then
ynh_replace_string "latest" "attic" ../conf/app.src
fi
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$php_config"
ynh_secure_remove "$final_path"
# Download, check integrity, uncompress and patch the source from app.src
# In case of a new version, the url change from http://download.dotclear.org/latest/dotclear-X.X.X.tar.gz to http://download.dotclear.org/attic/dotclear-X.X.X.tar.gz
src_url=$(grep 'SOURCE_URL=' "../conf/app.src" | cut -d= -f2-)
if ! curl --output /dev/null --silent --head --fail "$src_url"; then
ynh_replace_string "latest" "attic" ../conf/app.src
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
ynh_setup_source "$final_path"
mv $final_path/dotclear/* $final_path/
ynh_secure_remove "$final_path/dotclear"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_print_info "Upgrading nginx web server configuration..."
ynh_script_progression --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config
ynh_add_nginx_config
@ -134,15 +121,15 @@ ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_print_info "Making sure dedicated system user exists..."
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create $app
ynh_system_user_create --username=$app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
ynh_print_info "Upgrading php-fpm configuration..."
ynh_script_progression --message="Upgrading php-fpm configuration..." --weight=2
# Create a dedicated php-fpm config
ynh_add_fpm_config
@ -150,29 +137,33 @@ ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# CONFIGURE DOTCLEAR
# MODIFY A CONFIG FILE
#=================================================
php_config=$final_path/inc/config.php
ynh_backup_if_checksum_is_different --file=$php_config
cp $php_config.in $php_config
admin_url="${path_url%/}/admin/index.php"
email=$(ynh_user_get_info --username=$admin --key=mail)
# Config as if we called in admin/install/wizard.php
ynh_replace_string --match_string="'DC_DBDRIVER', ''" --replace_string="'DC_DBDRIVER', 'mysqli'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBHOST', ''" --replace_string="'DC_DBHOST', 'localhost'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBUSER', ''" --replace_string="'DC_DBUSER', '$db_user'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBPASSWORD', ''" --replace_string="'DC_DBPASSWORD', '$db_pwd'" --target_file=$php_config
ynh_replace_string --match_string="'DC_DBNAME', ''" --replace_string="'DC_DBNAME', '$db_name'" --target_file=$php_config
ynh_replace_string --match_string="'DC_MASTER_KEY', ''" --replace_string="'DC_MASTER_KEY', '$master_key'" --target_file=$php_config
ynh_replace_string --match_string="'DC_ADMIN_URL', ''" --replace_string="'DC_ADMIN_URL', 'https://$domain$admin_url'" --target_file=$php_config
ynh_replace_string --match_string="'DC_ADMIN_MAILFROM', ''" --replace_string="'DC_ADMIN_MAILFROM', '$email'" --target_file=$php_config
# Adding LDAP login
cp ../conf/class.auth.ldap.php $final_path/inc/class.auth.ldap.php
ynh_replace_string "__APP__" "$app" $final_path/inc/class.auth.ldap.php
firstname=$(yunohost user info $admin | grep firstname: | cut -d' ' -f2 | tr -d '\n')
lastname=$(yunohost user info $admin | grep lastname: | cut -d' ' -f2 | tr -d '\n')
email=$(yunohost user info $admin | grep mail: | cut -d' ' -f2 | tr -d '\n')
admin_url=$(ynh_url_join $path_url admin/index.php)
# Config as if we called in admin/install/wizard.php
ynh_replace_string "'DC_DBDRIVER', ''" "'DC_DBDRIVER', 'mysqli'" $php_config
ynh_replace_string "'DC_DBHOST', ''" "'DC_DBHOST', 'localhost'" $php_config
ynh_replace_string "'DC_DBUSER', ''" "'DC_DBUSER', '$app'" $php_config
ynh_replace_string "'DC_DBPASSWORD', ''" "'DC_DBPASSWORD', '$db_pwd'" $php_config
ynh_replace_string "'DC_DBNAME', ''" "'DC_DBNAME', '$db_name'" $php_config
ynh_replace_string "'DC_MASTER_KEY', ''" "'DC_MASTER_KEY', '$master_key'" $php_config
ynh_replace_string "'DC_ADMIN_URL', ''" "'DC_ADMIN_URL', 'https://$domain$admin_url'" $php_config
ynh_replace_string "'DC_ADMIN_MAILFROM', ''" "'DC_ADMIN_MAILFROM', '$email'" $php_config
# Adding LDAP login
cat << EOF >> $php_config
\$__autoload['myDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php';
@ -180,7 +171,7 @@ define('DC_AUTH_CLASS','myDcAuth');
EOF
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$php_config"
ynh_store_file_checksum --file=$php_config
#=================================================
# GENERIC FINALIZATION
@ -194,22 +185,22 @@ chown -R $app: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Upgrading permissions configuration..." --weight=2
# Create the admin permission if needed
if ! ynh_permission_exists --permission "admin"; then
ynh_print_info "Upgrading SSOwat configuration..."
ynh_permission_create --permission "admin" --url "/admin" --allowed $admin
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
ynh_script_progression --message="Reloading nginx web server..."
systemctl reload php7.0-fpm
systemctl reload nginx
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Upgrade of $app completed"
ynh_script_progression --message="Upgrade of $app completed" --last

View file

@ -1,54 +0,0 @@
#!/bin/bash
#Brouillon fonctionnel de script d'installation silencieuse de DotClear2, sur un serveur pourvu d'une base MySQL et d'un nginx pointant sur /var/www/dotclear
# dépendances
apt install -y uuid-runtime curl wget
# paramètres
DC_DBDRIVER="mysqli"
DC_DBHOST="localhost"
DC_DBUSER="dotclear"
DC_DBPASSWORD="dotclear"
DC_DBNAME="dotclear"
DC_MASTER_KEY=`uuidgen`
DC_ADMIN_URL="https://vagrant.test/admin/index.php"
EMAIL="root@localhost"
FIRSTNAME="Rémy"
NAME="Garrigue"
LOGIN="remy"
PWD="dotclear"
TZ="Europe/Paris"
cd /var/www/
CONF="dotclear/inc/config.php"
# sources
wget http://download.dotclear.org/latest.tar.gz -O dotclear.tgz
tar xf dotclear.tgz
rm -f dotclear.tgz
chown www-data:www-data -R dotclear
# sql
# create database dotclear;
# grant all privileges on dotclear.* to dotclear@'localhost' identified by 'dotclear';
# config admin/install/wizard.php
mv $CONF.in $CONF
sed -i -e "s;'DC_DBDRIVER','';'DC_DBDRIVER','$DC_DBDRIVER';" $CONF
sed -i -e "s;'DC_DBHOST','';'DC_DBHOST','$DC_DBHOST';" $CONF
sed -i -e "s;'DC_DBUSER','';'DC_DBUSER','$DC_DBUSER';" $CONF
sed -i -e "s;'DC_DBPASSWORD','';'DC_DBPASSWORD','$DC_DBPASSWORD';" $CONF
sed -i -e "s;'DC_DBNAME','';'DC_DBNAME','$DC_DBNAME';" $CONF
#sed -i -e "s;'DC_DBPREFIX','';'DC_DBPREFIX','dc_';" $CONF
sed -i -e "s;'DC_MASTER_KEY','';'DC_MASTER_KEY','$DC_MASTER_KEY';" $CONF
sed -i -e "s;'DC_ADMIN_URL','';'DC_ADMIN_URL','$DC_ADMIN_URL';" $CONF
sed -i -e "s;'DC_ADMIN_MAILFROM','';'DC_ADMIN_MAILFROM','$EMAIL';" $CONF
# config admin/install/index.php
CURL=`curl -F "u_email=$EMAIL" -F "u_firstname=$FIRSTNAME" -F "u_name=$NAME" -F "u_login=$LOGIN" -F "u_pwd=$PWD" -F "u_pwd2=$PWD" -F "u_date=$TZ" http://vagrant.test/admin/install/index.php`
if [ `echo $CURL | grep -c success` -ge 0 ]
then exit 0
else exit 1
fi