From 24bce6eec5ac52a872d596fb4158f230df42d7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sat, 27 Jan 2024 14:19:28 +0100 Subject: [PATCH] Update packaging v2, fix upgrade --- conf/nginx.conf | 4 ++-- scripts/install | 41 +++++++++++++++++++++++------------------ scripts/remove | 4 ++-- scripts/restore | 5 +++-- scripts/upgrade | 42 +++++++++++++++++++++++++++++++++--------- 5 files changed, 63 insertions(+), 33 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 64cbe1e..1e5a760 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,8 +1,8 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - alias __INSTALL_DIR__/dist/; - + alias __INSTALL_DIR__/www/; + index index.html; more_set_headers "X-Frame-Options: SAMEORIGIN"; diff --git a/scripts/install b/scripts/install index 2335244..3b90ad0 100644 --- a/scripts/install +++ b/scripts/install @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=7 +ynh_script_progression --message="Installing NodeJS..." --weight=7 # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version @@ -23,39 +23,44 @@ ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_script_progression --message="Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$install_dir" +ynh_setup_source --dest_dir="$install_dir/source" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." - -# Create a dedicated nginx config -ynh_add_nginx_config +chown -R "$app:www-data" "$install_dir" #================================================= # INSTALL THE LOUNGE #================================================= ynh_script_progression --message="Installing $app..." --weight=10 -pushd $install_dir - ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_ENV=production yarn build +pushd "$install_dir/source" + ynh_use_nodejs + ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install + ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" NODE_ENV=production yarn build popd +mv "$install_dir/source/dist" "$install_dir/www" +ynh_secure_remove "$install_dir/source" + #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -ynh_add_config --template="config.example.js" --destination="$install_dir/public/config/config.js" +ynh_add_config --template="config.example.js" --destination="$install_dir/www/public/config/config.js" -chmod 400 "$install_dir/public/config/config.js" -chown $app:$app "$install_dir/public/config/config.js" +chmod -R o-rwx "$install_dir" +chown -R "$app:www-data" "$install_dir" + +chmod 400 "$install_dir/www/public/config/config.js" + +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +# Create a dedicated nginx config +ynh_add_nginx_config #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 5fdfda0..80b06c5 100644 --- a/scripts/remove +++ b/scripts/remove @@ -10,9 +10,9 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# REMOVE NGINX CONFIGURATION +# REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config diff --git a/scripts/restore b/scripts/restore index d0f47a5..613f291 100644 --- a/scripts/restore +++ b/scripts/restore @@ -21,8 +21,9 @@ chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" #================================================= -# RESTORE THE PHP-FPM CONFIGURATION +# RESTORE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -31,7 +32,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 0dd17c6..96ee852 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,28 +10,52 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# CHECK VERSION +# INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Updating NodeJS..." --weight=7 -upgrade_type=$(ynh_check_app_version_changed) +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" --keep="public/config/config.js" -fi +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir/source" --full_replace=1 chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" +#================================================= +# INSTALL THE LOUNGE +#================================================= +ynh_script_progression --message="Installing $app..." --weight=10 + +pushd "$install_dir/source" + ynh_use_nodejs + ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install + ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" NODE_ENV=production yarn build +popd + +mv "$install_dir/source/dist" "$install_dir/www" +ynh_secure_remove "$install_dir/source" + +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +ynh_add_config --template="config.example.js" --destination="$install_dir/www/public/config/config.js" + +chmod -R o-rwx "$install_dir" +chown -R "$app:www-data" "$install_dir" + +chmod 400 "$install_dir/www/public/config/config.js" + #================================================= # NGINX CONFIGURATION #=================================================