1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lutim_ynh.git synced 2024-09-03 19:36:24 +02:00

Merge pull request #70 from YunoHost-Apps/upgrade

Upgrade
This commit is contained in:
yalh76 2022-07-29 17:16:16 +02:00 committed by GitHub
commit ca162f25f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 125 deletions

View file

@ -103,7 +103,7 @@
# if set to 1, all the images will be encrypted and the encryption option will no be displayed # if set to 1, all the images will be encrypted and the encryption option will no be displayed
# optional, default is 0 # optional, default is 0
always_encrypt => __ENCRYPT__, always_encrypt => __ALWAYS_ENCRYPT__,
# you can allow to use a watermark on the uploaded images (or enforce its use) # you can allow to use a watermark on the uploaded images (or enforce its use)
# define a path to the watermark image (provide an image with alpha channel) # define a path to the watermark image (provide an image with alpha channel)

View file

@ -121,14 +121,14 @@ ynh_script_progression --message="Reconfiguring SSOwat..."
if [ $is_public -eq 0 ] # Only user with a yunohost account can upload an image if [ $is_public -eq 0 ] # Only user with a yunohost account can upload an image
then then
# If the app is private, viewing images stays publicly accessible. # If the app is private, viewing images stays publicly accessible.
if [ "$new_path" == "/" ]; then if [ "$new_path" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex. # If the path is /, clear it to prevent any error with the regex.
new_path="" new_path=""
fi fi
# Modify the domain to be used in a regex # Modify the domain to be used in a regex
domain_regex=$(echo "$new_domain" | sed 's@-@.@g') domain_regex=$(echo "$new_domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$new_path/stats/?$","$domain_regex$new_path/manifest.webapp/?$","$domain_regex$new_path/?$","$domain_regex$new_path/[d-m]/.*$" ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$new_path/stats/?$","$domain_regex$new_path/manifest.webapp/?$","$domain_regex$new_path/?$","$domain_regex$new_path/[d-m]/.*$"
fi fi
#================================================= #=================================================

View file

@ -109,23 +109,15 @@ ynh_add_nginx_config
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
# SETUP LUTIM # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configure $app" --weight=2 ynh_script_progression --message="Adding a configuration file..." --weight=2
# Configure Lutim workers="$(( $(nproc) * 2 ))"
cp ../conf/lutim.conf.template "$final_path/lutim.conf" ynh_add_config --template="../conf/lutim.conf.template" --destination="$final_path/lutim.conf"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf" chmod 400 "$final_path/lutim.conf"
chown $app:$app "$final_path/lutim.conf"
# Set the number of process for Lutim to twice the number of CPU core.
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$final_path/lutim.conf"
#================================================= #=================================================
# SETUP HOOKS FILE # SETUP HOOKS FILE
@ -134,14 +126,6 @@ ynh_store_file_checksum --file="$final_path/lutim.conf"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_addaccess" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_addaccess"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_removeaccess" ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_removeaccess"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=2
# Create a dedicated systemd config
ynh_add_systemd_config
#================================================= #=================================================
# SETUP CRON # SETUP CRON
#================================================= #=================================================
@ -162,7 +146,7 @@ carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu) arch_dir=$(ls -1 $final_path/local/lib/perl5/ | grep linux-gnu)
if [ "$?" -ne 0 ] if [ "$?" -ne 0 ]
then then
ynh_die --message="Unable to find the perl directory for your architecture." ynh_die --message="Unable to find the perl directory for your architecture."
fi fi
ynh_replace_string --match_string="__ARCHDIR__" --replace_string="$arch_dir" --target_file="$final_path/script/lutim" ynh_replace_string --match_string="__ARCHDIR__" --replace_string="$arch_dir" --target_file="$final_path/script/lutim"
@ -175,6 +159,14 @@ touch /var/log/$app/production.log
chown $app -R /var/log/$app chown $app -R /var/log/$app
ln -s /var/log/$app/production.log "$final_path/log/production.log" ln -s /var/log/$app/production.log "$final_path/log/production.log"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=2
# Create a dedicated systemd config
ynh_add_systemd_config
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
@ -221,17 +213,17 @@ ynh_permission_create --permission="upload images" --allowed="visitors"
if [ $is_public -eq 0 ] if [ $is_public -eq 0 ]
then then
# If the app is private, viewing images stays publicly accessible. # If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex. # If the path is /, clear it to prevent any error with the regex.
path_url="" path_url=""
fi fi
# Modify the domain to be used in a regex # Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g') domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$" ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
# If the app is not public, then the "visitors" group doesn't have this permission # If the app is not public, then the "visitors" group doesn't have this permission
ynh_permission_update --permission="upload images" --remove="visitors" ynh_permission_update --permission="upload images" --remove="visitors"
fi fi
#================================================= #=================================================

View file

@ -78,87 +78,87 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
# Fix is_public as a boolean # Fix is_public as a boolean
if [ "$is_public" = "Yes" ]; then if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1 ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1 is_public=1
elif [ "$is_public" = "No" ]; then elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0 ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0 is_public=0
fi fi
skipped_uris=$(ynh_app_setting_get --app=$app --key=skipped_uris) skipped_uris=$(ynh_app_setting_get --app=$app --key=skipped_uris)
# Unused with the permission system # Unused with the permission system
if [ ! -z "$skipped_uris" ]; then if [ ! -z "$skipped_uris" ]; then
ynh_app_setting_delete --app=$app --key=skipped_uris ynh_app_setting_delete --app=$app --key=skipped_uris
fi fi
# Create the permission "upload images" only if it doesn't exist. # Create the permission "upload images" only if it doesn't exist.
if ! ynh_permission_exists --permission="upload images" if ! ynh_permission_exists --permission="upload images"
then then
# This is a fake permission without any URL. # This is a fake permission without any URL.
# The purpose of this permission is only to trigger hooks post_app_add/removeaccess when it's modified. # The purpose of this permission is only to trigger hooks post_app_add/removeaccess when it's modified.
# We can't use a real permission for now because the actual permision system doesn't support regex. # We can't use a real permission for now because the actual permision system doesn't support regex.
ynh_permission_create --permission="upload images" --allowed="visitors" ynh_permission_create --permission="upload images" --allowed="visitors"
if [ $is_public -eq 0 ] if [ $is_public -eq 0 ]
then then
# If the app is private, viewing images stays publicly accessible. # If the app is private, viewing images stays publicly accessible.
if [ "$path_url" == "/" ]; then if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex. # If the path is /, clear it to prevent any error with the regex.
path_url="" path_url=""
fi fi
# Modify the domain to be used in a regex # Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g') domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$" ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats/?$","$domain_regex$path_url/manifest.webapp/?$","$domain_regex$path_url/?$","$domain_regex$path_url/[d-m]/.*$"
# If the app is not public, then the "visitors" group doesn't have this permission # If the app is not public, then the "visitors" group doesn't have this permission
ynh_permission_update --permission="upload images" --remove="visitors" ynh_permission_update --permission="upload images" --remove="visitors"
fi fi
fi fi
# if final_path isn't set, which can happens with old scripts, set final_path. # if final_path isn't set, which can happens with old scripts, set final_path.
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=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi fi
# Fix always_encrypt as a boolean # Fix always_encrypt as a boolean
if [ "$always_encrypt" = "Yes" ]; then if [ "$always_encrypt" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=always_encrypt --value=1 ynh_app_setting_set --app=$app --key=always_encrypt --value=1
always_encrypt=1 always_encrypt=1
elif [ "$always_encrypt" = "No" ]; then elif [ "$always_encrypt" = "No" ]; then
ynh_app_setting_set --app=$app --key=always_encrypt --value=0 ynh_app_setting_set --app=$app --key=always_encrypt --value=0
always_encrypt=0 always_encrypt=0
fi fi
# If overwrite_settings doesn't exist, create it # If overwrite_settings doesn't exist, create it
if [ -z "$overwrite_settings" ]; then if [ -z "$overwrite_settings" ]; then
overwrite_settings=1 overwrite_settings=1
ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings ynh_app_setting_set --app=$app --key=overwrite_settings --value=$overwrite_settings
fi fi
# If overwrite_nginx doesn't exist, create it # If overwrite_nginx doesn't exist, create it
if [ -z "$overwrite_nginx" ]; then if [ -z "$overwrite_nginx" ]; then
overwrite_nginx=1 overwrite_nginx=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx ynh_app_setting_set --app=$app --key=overwrite_nginx --value=$overwrite_nginx
fi fi
# If overwrite_systemd doesn't exist, create it # If overwrite_systemd doesn't exist, create it
if [ -z "$overwrite_systemd" ]; then if [ -z "$overwrite_systemd" ]; then
overwrite_systemd=1 overwrite_systemd=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=$overwrite_systemd ynh_app_setting_set --app=$app --key=overwrite_systemd --value=$overwrite_systemd
fi fi
# If secret doesn't exist, create it # If secret doesn't exist, create it
if [ -z "$secret" ]; then if [ -z "$secret" ]; then
secret=$(grep "secrets *=>" "$final_path/lutim.conf" | cut -d\' -f2) secret=$(grep "secrets *=>" "$final_path/lutim.conf" | cut -d\' -f2)
ynh_app_setting_set --app=$app --key=secret --value=$secret ynh_app_setting_set --app=$app --key=secret --value=$secret
fi fi
# Close opened port # Close opened port
if yunohost firewall list | grep -q "\- $port$" if yunohost firewall list | grep -q "\- $port$"
then then
ynh_exec_quiet yunohost firewall disallow TCP $port ynh_exec_quiet yunohost firewall disallow TCP $port
fi fi
# Replace skipped_uris by unprotected_uris for the migration to the new permission system. # Replace skipped_uris by unprotected_uris for the migration to the new permission system.
@ -203,8 +203,8 @@ ynh_install_app_dependencies $pkg_dependencies
# Overwrite the nginx configuration only if it's allowed # Overwrite the nginx configuration only if it's allowed
if [ $overwrite_nginx -eq 1 ] if [ $overwrite_nginx -eq 1 ]
then then
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
ynh_add_nginx_config ynh_add_nginx_config
fi fi
#================================================= #=================================================
@ -217,31 +217,23 @@ ynh_script_progression --message="Reconfiguring $app..."
# Overwrite the settings config file only if it's allowed # Overwrite the settings config file only if it's allowed
if [ $overwrite_settings -eq 1 ] if [ $overwrite_settings -eq 1 ]
then then
# Configure Lutim workers="$(( $(nproc) * 2 ))"
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ynh_add_config --template="../conf/lutim.conf.template" --destination="$final_path/lutim.conf"
ynh_backup_if_checksum_is_different --file="$final_path/lutim.conf"
cp ../conf/lutim.conf.template "$final_path/lutim.conf"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf"
# Set the number of process for Lutim to twice the number of CPU core.
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$final_path/lutim.conf"
# Optional parameters from config-panel feature chmod 400 "$final_path/lutim.conf"
if [ -n "$antiflood" ]; then chown $app:$app "$final_path/lutim.conf"
ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$final_path/lutim.conf"
# Disable anti_flood_delay if the delay is 0 # Optional parameters from config-panel feature
if [ $antiflood = 0 ]; then if [ -n "$antiflood" ]; then
ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$final_path/lutim.conf" ynh_replace_string --match_string=".*anti_flood_delay *=>.*" --replace_string=" anti_flood_delay => $antiflood," --target_file="$final_path/lutim.conf"
fi # Disable anti_flood_delay if the delay is 0
fi if [ $antiflood = 0 ]; then
if [ -n "$delay" ]; then ynh_replace_string --match_string="\(anti_flood_delay *=>.*\)" --replace_string="#\1" --target_file="$final_path/lutim.conf"
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$final_path/lutim.conf" fi
fi fi
if [ -n "$delay" ]; then
ynh_replace_string --match_string=".*default_delay *=>.*" --replace_string=" default_delay => $delay," --target_file="$final_path/lutim.conf"
fi
fi fi
#================================================= #=================================================
@ -263,11 +255,11 @@ ynh_add_config --template="../conf/cron_lutim" --destination="/etc/cron.d/$app"
if [ "$upgrade_type" == "UPGRADE_APP" ] if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading $app with Carton..." --weight=4 ynh_script_progression --message="Upgrading $app with Carton..." --weight=4
pushd "$final_path" pushd "$final_path"
ynh_secure_remove --file="$final_path/local" ynh_secure_remove --file="$final_path/local"
carton install --without=mysql --without=htpasswd --without=test carton install --without=mysql --without=htpasswd --without=test
popd popd
fi fi
#================================================= #=================================================
@ -277,8 +269,8 @@ fi
# Overwrite the systemd configuration only if it's allowed # Overwrite the systemd configuration only if it's allowed
if [ $overwrite_systemd -eq 1 ] if [ $overwrite_systemd -eq 1 ]
then then
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2 ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
ynh_add_systemd_config ynh_add_systemd_config
fi fi
#================================================= #=================================================

View file

@ -1,13 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
BEGIN { unshift @INC, "$FindBin::Bin/../local/lib/perl5" }
BEGIN { unshift @INC, "$FindBin::Bin/../local/lib/perl5/__ARCHDIR__" }
# Start command line interface for application
require Mojolicious::Commands;
Mojolicious::Commands->start_app('Mounter');