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

@ -1,74 +1,17 @@
# Curl abstraction to help with POST requests to local pages (such as installation forms) #!/bin/bash
#
# $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 # COMMON VARIABLES
fi #=================================================
local full_page_url=https://localhost$full_path #=================================================
# PERSONAL HELPERS
#=================================================
# Concatenate all other arguments with '&' to prepare POST data #=================================================
local POST_data="" # EXPERIMENTAL HELPERS
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 # FUTURE OFFICIAL HELPERS
#=================================================
# Curl the URL
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url"
}
# 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=""
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
}

View file

@ -6,52 +6,60 @@
# IMPORT GENERIC HELPERS # 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 ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # 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 # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # 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 # 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 # 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 # 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,15 +24,18 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
# LOAD SETTINGS # 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" # Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path) 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 # 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 # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
@ -67,7 +70,7 @@ fi
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # 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 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
@ -98,35 +101,37 @@ fi
#================================================= #=================================================
# UPDATE THE DATABASE # UPDATE THE DATABASE
#================================================= #=================================================
ynh_script_progression --message="Updating database..."
new_index_url=$(ynh_url_join $new_path /index.php) new_index_url="${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="${new_path%/}/public"
new_public_url=$(ynh_url_join $new_path /public) new_themes_url="${new_path%/}/themes"
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
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 # UPDATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Updating configuration file..."
php_config=$final_path/inc/config.php 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="${new_path%/}/admin/index.php"
new_admin_url=$(ynh_url_join $new_path admin/index.php) old_admin_url="${old_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 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 # GENERIC FINALISATION
#================================================= #=================================================
# RELOAD NGINX # 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 ynh_systemd_action --service_name=nginx --action=reload
@ -134,4 +139,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT # 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 # IMPORT GENERIC HELPERS
#================================================= #=================================================
source /usr/share/yunohost/helpers
source _common.sh source _common.sh
source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # 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 # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -33,55 +29,54 @@ admin=$YNH_APP_ARG_ADMIN
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
ynh_script_progression --message="Validating installation parameters..."
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Register (book) web path # 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 # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set $app domain $domain ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set $app path $path_url ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set $app admin $admin ynh_app_setting_set --app=$app --key=admin --value=$admin
#================================================= #=================================================
# CREATE A MYSQL DATABASE # CREATE A MYSQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=2
db_name=$(ynh_sanitize_dbid $app) db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set $app db_name $db_name db_user=$db_name
ynh_mysql_setup_db $app $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 # 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 # 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-) src_url=$(grep 'SOURCE_URL=' "../conf/app.src" | cut -d= -f2-)
if ! curl --output /dev/null --silent --head --fail "$src_url"; then 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 fi
ynh_setup_source $final_path ynh_setup_source --dest_dir="$final_path"
mv $final_path/dotclear/* $final_path/
ynh_secure_remove "$final_path/dotclear"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring nginx web server..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -89,52 +84,55 @@ ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
# Create a system user # Create a system user
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring php-fpm..." --weight=2
# Create a dedicated php-fpm config # Create a dedicated php-fpm config
ynh_add_fpm_config ynh_add_fpm_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
php_config=$final_path/inc/config.php php_config=$final_path/inc/config.php
master_key=$(ynh_string_random 30) master_key=$(ynh_string_random --length=30)
ynh_app_setting_set $app master_key $master_key ynh_app_setting_set --app=$app --key=master_key --value=$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)
cp $php_config.in $php_config 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 # Config as if we called in admin/install/wizard.php
ynh_replace_string "'DC_DBDRIVER', ''" "'DC_DBDRIVER', 'mysqli'" $php_config ynh_replace_string --match_string="'DC_DBDRIVER', ''" --replace_string="'DC_DBDRIVER', 'mysqli'" --target_file=$php_config
ynh_replace_string "'DC_DBHOST', ''" "'DC_DBHOST', 'localhost'" $php_config ynh_replace_string --match_string="'DC_DBHOST', ''" --replace_string="'DC_DBHOST', 'localhost'" --target_file=$php_config
ynh_replace_string "'DC_DBUSER', ''" "'DC_DBUSER', '$app'" $php_config ynh_replace_string --match_string="'DC_DBUSER', ''" --replace_string="'DC_DBUSER', '$db_user'" --target_file=$php_config
ynh_replace_string "'DC_DBPASSWORD', ''" "'DC_DBPASSWORD', '$db_pwd'" $php_config ynh_replace_string --match_string="'DC_DBPASSWORD', ''" --replace_string="'DC_DBPASSWORD', '$db_pwd'" --target_file=$php_config
ynh_replace_string "'DC_DBNAME', ''" "'DC_DBNAME', '$db_name'" $php_config ynh_replace_string --match_string="'DC_DBNAME', ''" --replace_string="'DC_DBNAME', '$db_name'" --target_file=$php_config
ynh_replace_string "'DC_MASTER_KEY', ''" "'DC_MASTER_KEY', '$master_key'" $php_config ynh_replace_string --match_string="'DC_MASTER_KEY', ''" --replace_string="'DC_MASTER_KEY', '$master_key'" --target_file=$php_config
ynh_replace_string "'DC_ADMIN_URL', ''" "'DC_ADMIN_URL', 'https://$domain$admin_url'" $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 "'DC_ADMIN_MAILFROM', ''" "'DC_ADMIN_MAILFROM', '$email'" $php_config ynh_replace_string --match_string="'DC_ADMIN_MAILFROM', ''" --replace_string="'DC_ADMIN_MAILFROM', '$email'" --target_file=$php_config
# Adding LDAP login # 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 cat << EOF >> $php_config
\$__autoload['myDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php'; \$__autoload['myDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php';
define('DC_AUTH_CLASS','myDcAuth'); define('DC_AUTH_CLASS','myDcAuth');
EOF EOF
ynh_store_file_checksum $php_config ynh_store_file_checksum --file=$php_config
#================================================= #=================================================
# SETUP APPLICATION WITH CURL # SETUP APPLICATION WITH CURL
@ -147,26 +145,44 @@ chown -R $app: $final_path
ynh_permission_update --permission "main" --add "visitors" ynh_permission_update --permission "main" --add "visitors"
# Reload Nginx # 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 # Installation with curl
installUrl="/admin/install/index.php" 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" 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 # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Configuring permissions..."
if [ $is_public -eq 0 ]; then if [ $is_public -eq 0 ]; then
ynh_permission_update --permission "main" --remove "visitors" ynh_permission_update --permission "main" --remove "visitors"
fi 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 ynh_permission_create --permission "admin" --url "/admin" --allowed $admin
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading nginx web server..."
systemctl reload php7.0-fpm ynh_systemd_action --service_name=nginx --action=reload
systemctl reload nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -6,38 +6,43 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source /usr/share/yunohost/helpers
source _common.sh source _common.sh
source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments domain=$(ynh_app_setting_get --app=$app --key=domain)
domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_name=$(ynh_app_setting_get $app db_name)
db_user=$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 # REMOVE THE MYSQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Removing the MySQL database..."
# Remove a database if it exists, along with the associated user # 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 # REMOVE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove "$final_path" ynh_secure_remove --file="$final_path"
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing nginx web server configuration..."
# Remove the dedicated nginx config # Remove the dedicated nginx config
ynh_remove_nginx_config ynh_remove_nginx_config
@ -45,6 +50,7 @@ ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE PHP-FPM CONFIGURATION # REMOVE PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing php-fpm configuration..."
# Remove the dedicated php-fpm config # Remove the dedicated php-fpm config
ynh_remove_fpm_config ynh_remove_fpm_config
@ -54,6 +60,13 @@ ynh_remove_fpm_config
#================================================= #=================================================
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Removing the dedicated system user..."
# Delete a 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 # 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 ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # 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 # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get $app db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
ynh_script_progression --message="Validating restoration parameters..."
ynh_webpath_available $domain $path_url \ ynh_webpath_available --domain=$domain --path_url=$path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \ 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 # STANDARD RESTORATION STEPS
@ -46,28 +46,22 @@ test ! -d $final_path \
# RESTORE THE NGINX CONFIGURATION # 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 # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file "$final_path" ynh_restore_file --origin_path="$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
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=2
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
# RESTORE USER RIGHTS # RESTORE USER RIGHTS
@ -80,13 +74,30 @@ chown -R $app: $final_path
# RESTORE THE PHP-FPM CONFIGURATION # 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 # 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 ynh_script_progression --message="Restoration completed for $app" --last
systemctl reload nginx

View file

@ -12,65 +12,59 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_print_info "Loading installation settings..." ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get $app admin) admin=$(ynh_app_setting_get --app=$app --key=admin)
is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
final_path=$(ynh_app_setting_get $app final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_name=$(ynh_app_setting_get $app db_name) db_user=$db_name
db_pwd=$(ynh_app_setting_get $app mysqlpwd) db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
password=$(ynh_app_setting_get $app password) password=$(ynh_app_setting_get --app=$app --key=password)
master_key=$(ynh_app_setting_get $app master_key) 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) # CHECK VERSION
protected_uris=$(ynh_app_setting_get $app protected_uris) #=================================================
upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # 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 db_name doesn't exist, create it
if [ -z $db_name ]; then if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid $app) db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set $app db_name $db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi fi
# If final_path doesn't exist, create it # If final_path doesn't exist, create it
if [ -z $final_path ]; then if [ -z "$final_path" ]; then
final_path=/var/www/$app 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 fi
# Delete skipped_uris if it exists is_public=$(ynh_app_setting_get --app=$app --key=is_public)
if [ ! -z $skipped_uris ]; then
ynh_app_setting_delete $app skipped_uris
fi
# Delete unprotected_uris if it exists if [ -n "$is_public" ]; then
if [ ! -z $unprotected_uris ]; then # Remove unprotected_uris
ynh_app_setting_delete $app unprotected_uris ynh_app_setting_delete --app=$app --key=unprotected_uris
fi # Remove protected_uris
ynh_app_setting_delete --app=$app --key=protected_uris
# Delete protected_uris if it exists # Removing skipped/unprotected_uris under certain conditions, remove the visitors group added during the migration process of 3.7
if [ ! -z $protected_uris ]; then # Remove skipped_uris. If the app was public, add visitors again to the main permission
ynh_app_setting_delete $app protected_uris if ynh_permission_has_user --permission=main --user=visitors
fi then
ynh_app_setting_delete --app=$app --key=skipped_uris
# 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
ynh_permission_update --permission "main" --add "visitors" ynh_permission_update --permission "main" --add "visitors"
else
ynh_app_setting_delete --app=$app --key=skipped_uris
fi fi
ynh_app_setting_delete --app=$app --key=is_public ynh_app_setting_delete --app=$app --key=is_public
fi fi
@ -78,7 +72,7 @@ fi
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # 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 # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
@ -94,22 +88,17 @@ ynh_abort_if_errors
#================================================= #=================================================
# Normalize the URL path syntax # 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 # STANDARD UPGRADE STEPS
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # 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
### 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"
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
# Download, check integrity, uncompress and patch the source from app.src # 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 # 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-) src_url=$(grep 'SOURCE_URL=' "../conf/app.src" | cut -d= -f2-)
@ -117,16 +106,14 @@ if ! curl --output /dev/null --silent --head --fail "$src_url"; then
ynh_replace_string "latest" "attic" ../conf/app.src ynh_replace_string "latest" "attic" ../conf/app.src
fi fi
ynh_setup_source "$final_path" # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
mv $final_path/dotclear/* $final_path/ fi
ynh_secure_remove "$final_path/dotclear"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_print_info "Upgrading nginx web server configuration..." ynh_script_progression --message="Upgrading nginx web server configuration..."
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
@ -134,15 +121,15 @@ ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # 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) # Create a dedicated user (if not existing)
ynh_system_user_create $app ynh_system_user_create --username=$app
#================================================= #=================================================
# PHP-FPM CONFIGURATION # 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 # Create a dedicated php-fpm config
ynh_add_fpm_config ynh_add_fpm_config
@ -150,29 +137,33 @@ ynh_add_fpm_config
#================================================= #=================================================
# SPECIFIC UPGRADE # 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 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 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 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 cat << EOF >> $php_config
\$__autoload['myDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php'; \$__autoload['myDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php';
@ -180,7 +171,7 @@ define('DC_AUTH_CLASS','myDcAuth');
EOF EOF
# Recalculate and store the checksum of the file for the next upgrade. # 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 # GENERIC FINALIZATION
@ -194,22 +185,22 @@ chown -R $app: $final_path
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
ynh_script_progression --message="Upgrading permissions configuration..." --weight=2
# Create the admin permission if needed
if ! ynh_permission_exists --permission "admin"; then if ! ynh_permission_exists --permission "admin"; then
ynh_print_info "Upgrading SSOwat configuration..."
ynh_permission_create --permission "admin" --url "/admin" --allowed $admin ynh_permission_create --permission "admin" --url "/admin" --allowed $admin
fi fi
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_print_info "Reloading nginx web server..." ynh_script_progression --message="Reloading nginx web server..."
systemctl reload php7.0-fpm ynh_systemd_action --service_name=nginx --action=reload
systemctl reload nginx
#================================================= #=================================================
# END OF SCRIPT # 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