diff --git a/scripts/change_url b/scripts/change_url index 4a039ee..05d8e7d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -58,16 +58,6 @@ final_path=/var/www/$app # 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 "$nginx_conf_path" - # # Replace locations starting with old_path - # # Look for every location possible patterns (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location) - # ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $old_path" "location\1 $new_path" "$nginx_conf_path" - # # Replace path in "return" directives - # ynh_replace_string "return \([[:digit:]]\{3\}\) $old_path" "return \1 $new_path" "$nginx_conf_path" - # # Calculate and store the nginx config file checksum - # ynh_store_file_checksum "$nginx_conf_path" - # # ynh_replace_string # 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 diff --git a/scripts/install b/scripts/install index 3d48aba..2ba6b3d 100644 --- a/scripts/install +++ b/scripts/install @@ -79,7 +79,6 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" - #================================================= # Files owned by user app #================================================= @@ -87,7 +86,6 @@ ynh_setup_source --dest_dir="$final_path" chown $app:$app $final_path -R chmod 755 $final_path -R - #================================================= # NGINX CONFIGURATION #================================================= @@ -140,10 +138,6 @@ else ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" fi -# ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin/;" --target_file="$final_path/config.local.php" -# ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = true;" --target_file="$final_path/config.local.php" -# echo "const WWW_URI = '$path_url/';" >> $final_path/config.local.php - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 30bbc66..5569589 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -32,7 +32,6 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) || ynh_die "This p ### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. upgrade_type=$(ynh_check_app_version_changed) - #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -50,7 +49,7 @@ fi #================================================= # Backup squlite, config.local.php and squelettes directory #================================================= -ynh_script_progression --message="Backing up the bdd and squelettes before upgrading (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the data before upgrading (may take a while)..." --time --weight=1 bdd=$final_path/association.sqlite squelettes=$final_path/www/squelettes @@ -83,32 +82,13 @@ ynh_abort_if_errors # # CHECK THE PATH # #================================================= -# # Normalize the URL path syntax -# # N.B. : this is for app installations before YunoHost 2.7 -# # where this value might be something like /foo/ or foo/ -# # instead of /foo .... -# # If nobody installed your app before 2.7, then you may -# # safely remove this line -# path_url=$(ynh_normalize_url_path --path_url=$path_url) - - -# 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) - -# # Check web path availability -# ynh_webpath_available $domain $path_url -# # Register (book) web path -# ynh_webpath_register $app $domain $path_url - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 - -ynh_install_app_dependencies $pkg_dependencies +# Normalize the URL path syntax +# N.B. : this is for app installations before YunoHost 2.7 +# where this value might be something like /foo/ or foo/ +# instead of /foo .... +# If nobody installed your app before 2.7, then you may +# safely remove this line +path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -121,6 +101,21 @@ then ynh_setup_source --dest_dir="$final_path" fi +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 + +ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app + #================================================= # NGINX CONFIGURATION @@ -131,12 +126,45 @@ ynh_script_progression --message="Upgrading nginx web server configuration..." - ynh_add_nginx_config #================================================= -# CREATE DEDICATED USER +# PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 +ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1 -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +# Create a dedicated php-fpm config +ynh_add_fpm_config + +#================================================= +# Change options in file config.dist.php +# and copy in local.dist.php +#================================================= +ynh_script_progression --message="final configuration needed..." --time --weight=1 + +key=$(ynh_string_random --length=50) +cp -a $final_path/config.dist.php $final_path/config.local.php +ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = '$key';" --target_file="$final_path/config.local.php" +if [ "$path_url" == "/" ] +then + ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url';" --target_file="$final_path/config.local.php" +else + ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" +fi +#================================================= +# backup bdd, squelettes directory and config.local.php +#================================================= +ynh_script_progression --message="restore data..." --time --weight=1 + +backup_bdd=/tmp/association.sqlite +backup_squelettes=/tmp/squelettes + +if [ -d "$backup_squelettes" ] +then + cp -ar $backup_squelettes $final_path/www/squelettes +fi + +if [ -e "$backup_bdd" ] +then + cp -a $backup_bdd $final_path/association.sqlite +fi # #================================================= # # STORE THE CONFIG FILE CHECKSUM @@ -144,25 +172,18 @@ ynh_system_user_create --username=$app # ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. # ### 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 --file="$final_path/CONFIG_FILE" +ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" # # Recalculate and store the checksum of the file for the next upgrade. -# ynh_store_file_checksum --file="$final_path/CONFIG_FILE" +ynh_store_file_checksum --file="$final_path/CONFIG_FILE" #================================================= # Files owned by user app #================================================= +# Set permissions on app files chown $app:$app $final_path -R chmod 755 $final_path -R -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1 - -# Create a dedicated php-fpm config -ynh_add_fpm_config - #================================================= # SETUP SSOWAT #================================================= @@ -182,34 +203,7 @@ ynh_script_progression --message="Reloading nginx web server..." --time --weight ynh_systemd_action --service_name=nginx --action=reload -#================================================= -# backup bdd, squelettes directory and config.local.php -#================================================= -if [ "$new_path" == "/" ] - echo "const WWW_URI = '$path_url';" >> $final_path/config.local.php -else - echo "const WWW_URI = '$path_url/';" >> $final_path/config.local.php -fi - -backup_bdd=/tmp/association.sqlite -backup_squelettes=/tmp/squelettes - -if [ -d "$backup_squelettes" ] -then - cp -ar $backup_squelettes $final_path/www/squelettes -fi - -if [ -e "$backup_bdd" ] -then - cp -a $backup_bdd $final_path/association.sqlite -fi - - -#cp -a $final_path/config.dist.php $final_path/config.local.php -# ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" -# ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin/;" --target_file="$final_path/config.local.php" - #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --time --last +ynh_script_progression --message="Upgrade of $app completed" --time --last \ No newline at end of file