diff --git a/README.md b/README.md index 5cc6842..819184f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Set of games Framagames from Framasoft. -**Shipped version:** 1.0~ynh4 +**Shipped version:** 2022.12.28~ynh1 ## Documentation and resources * Official app website: diff --git a/README_fr.md b/README_fr.md index 1a53c40..bf37cb4 100644 --- a/README_fr.md +++ b/README_fr.md @@ -18,7 +18,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po Set of games Framagames from Framasoft. -**Version incluse :** 1.0~ynh4 +**Version incluse :** 2022.12.28~ynh1 ## Documentations et ressources * Site officiel de l’app : diff --git a/conf/nginx.conf b/conf/nginx.conf index 74155b1..4372e33 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,26 +1,11 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - # Path to source - alias __INSTALL_DIR__/; + # Path to source + alias __INSTALL_DIR__/public/; - index index.php index.html; + index index.html; - # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file - client_max_body_size 10G; - - try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; - - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param REMOTE_USER $remote_user; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME $request_filename; - } - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; -} + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} \ No newline at end of file diff --git a/manifest.toml b/manifest.toml index 8f2842f..e6e4de0 100644 --- a/manifest.toml +++ b/manifest.toml @@ -5,14 +5,14 @@ name = "Framagames" description.en = "Set of games Framagames from Framasoft" description.fr = "Ensemble de jeux Framagames venant de Framasoft" -version = "1.0~ynh4" +version = "2022.12.28~ynh1" maintainers = [] [upstream] license = "AGPL-3.0-only" -website = "https://framagit.org/framasoft/framagames" code = "https://framagit.org/framasoft/framagames" +website = "https://framagames.org/en/" [integration] yunohost = ">= 11.2" @@ -32,16 +32,26 @@ ram.runtime = "50M" type = "path" default = "/framagames" + [install.language] + ask.en = "Choose the application language" + ask.fr = "Choisissez la langue de l'application" + type = "select" + choices = ["fr", "en"] + default = "en" + [install.init_main_permission] + help.en = "If enabled, Framagames will be accessible by people who doesn’t have an account. This can be changed later via the webadmin." + help.fr = "Si cette case est cochée, Framagames sera accessible aux personnes n’ayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin." type = "group" default = "visitors" [resources] - [resources.sources.main] + [resources.sources] - url = "https://framagit.org/framasoft/framagames/-/archive/6808f75cd18f4a1bb0345ce65d055e2dfef8c0b7/framagames-6808f75cd18f4a1bb0345ce65d055e2dfef8c0b7.tar.gz" - sha256 = "6c2bf60663dad46ac6660ddb3634d1c05dcf38cea1f2687b8ee26743deb8a10e" + [resources.sources.main] + url = "https://framagit.org/framasoft/framagames/-/archive/5510754d92e9649aa1808ffb1d3255d5da1ebf47/framagames-5510754d92e9649aa1808ffb1d3255d5da1ebf47.tar.gz" + sha256 = "d1b772cbda377ee2fdecf468eb251fb0d05b865d1b39703790a86943a1731973" [resources.system_user] @@ -49,6 +59,3 @@ ram.runtime = "50M" [resources.permissions] main.url = "/" - - [resources.apt] - packages = "php8.2-fpm" diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..9195d57 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,6 +4,8 @@ # COMMON VARIABLES #================================================= +nodejs_version=18 + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 18f83fe..52eea5b 100755 --- a/scripts/backup +++ b/scripts/backup @@ -27,12 +27,6 @@ ynh_backup --src_path="$install_dir" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# BACKUP THE PHP-FPM CONFIGURATION -#================================================= - -ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index a26579c..7afa82d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -21,3 +21,4 @@ ynh_change_url_nginx_config #================================================= ynh_script_progression --message="Change of URL completed for $app" + diff --git a/scripts/install b/scripts/install index ac0157e..d02d79a 100644 --- a/scripts/install +++ b/scripts/install @@ -9,24 +9,65 @@ source _common.sh source /usr/share/yunohost/helpers +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." + +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= 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/build" +chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring PHP-FPM..." +ynh_script_progression --message="Building...." --weight=5 + +ynh_use_nodejs + +stripped_path=$(echo $path_url | sed -e 's/\///') + +pushd "$install_dir/build" + ynh_replace_string --match_string="framanav: true" --replace_string="framanav: false" --target_file="src/data/main.yml" + ynh_replace_string --match_string="defaultLang: fr" --replace_string="defaultLang: $language" --target_file="src/data/main.yml" + + ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH NODE_OPTIONS="--openssl-legacy-provider" $ynh_npm run commons + if [ $path_url == "/" ]; then + ynh_replace_string --match_string="canonical: https://framagames.org" --replace_string="canonical: https://$domain" --target_file="src/data/main.yml" + ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH NODE_ENV=production NODE_OPTIONS="--openssl-legacy-provider" $ynh_npm run prod + else + ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH NODE_ENV=production CI_JOB_NAME=pages CI_PAGES_URL="https://$domain$path_url" NODE_OPTIONS="--openssl-legacy-provider" $ynh_npm run prod + fi + + ynh_secure_remove --file="$install_dir/build/public" + mv dist/ public/ + + if [ $path_url == "/" ]; then + cp ./public/$language/index.html ./public/index.html + mv -f games/* public/ + else + cp ./public/$stripped_path/$language/index.html ./public/$stripped_path/index.html + mv -f games/* public/$stripped_path + fi + cd public && for f in $(find -type l);do cp --remove-destination $(readlink -f $f) $f;done; + +popd + +if [ $path_url == "/" ]; then + mv "$install_dir/build/public" "$install_dir/public" +else + mv "$install_dir/build/public/$stripped_path" "$install_dir/public" +fi + +ynh_secure_remove --file="$install_dir/build" -# Create a dedicated PHP-FPM config -ynh_add_fpm_config # Create a dedicated NGINX config ynh_add_nginx_config diff --git a/scripts/remove b/scripts/remove index 2c04d62..bb21364 100644 --- a/scripts/remove +++ b/scripts/remove @@ -17,9 +17,6 @@ ynh_script_progression --message="Removing NGINX web server configuration..." # Remove the dedicated NGINX config ynh_remove_nginx_config -# Remove the dedicated PHP-FPM config -ynh_remove_fpm_config - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 72e44fb..c15bb32 100755 --- a/scripts/restore +++ b/scripts/restore @@ -11,36 +11,39 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= -# RESTORE THE APP MAIN DIR +# STANDARD RESTORATION STEPS #================================================= -ynh_script_progression --message="Restoring the app main directory..." - -ynh_restore_file --origin_path="$install_dir" - -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - +# RESTORE THE NGINX CONFIGURATION #================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the PHP-FPM configuration..." - -ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.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 $app main directory..." --weight=2 + +ynh_restore_file --origin_path="$install_dir" + +#================================================= +# RESTORE USER RIGHTS +#================================================= + +# Restore permissions on app files +chown -R $app:www-data $install_dir +chmod o-rwx $install_dir + #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND PHP-FPM +# RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." +ynh_script_progression --message="Reloading NGINX web server..." --weight=3 -ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index d87c4e7..42fa531 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,36 +15,112 @@ source /usr/share/yunohost/helpers upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 + +# If language doesn't exist, create it +if [ -z "${language:-}" ]; then + language="en" + ynh_app_setting_set --app=$app --key=language --value=$language +fi + +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." + +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." - ynh_secure_remove --file="$install_dir" + if $(ynh_compare_current_package_version --comparison lt --version "2022.12.28~ynh1") + then + ynh_script_progression --message="Removing old files..." --weight=2 + ynh_secure_remove --file="$install_dir" + + mkdir -p $install_dir + # Set permissions on app files + chown $app:www-data $install_dir + chmod o-rwx $install_dir + fi + 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/build" fi - -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - #================================================= -# PHP-FPM CONFIGURATION +# NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." - -# Create a dedicated PHP-FPM config -ynh_add_fpm_config +ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 # Create a dedicated NGINX config ynh_add_nginx_config +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set permissions on app files +chown -R $app:www-data $install_dir +chmod o-rwx $install_dir + +#================================================= +# BUILD +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Building...." --weight=5 + + ynh_use_nodejs + + stripped_path=$(echo $path_url | sed -e 's/\///') + + pushd "$install_dir/build" + ynh_replace_string --match_string="framanav: true" --replace_string="framanav: false" --target_file="src/data/main.yml" + ynh_replace_string --match_string="defaultLang: fr" --replace_string="defaultLang: $language" --target_file="src/data/main.yml" + + ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH NODE_OPTIONS="--openssl-legacy-provider" $ynh_npm run commons + if [ $path_url == "/" ]; then + ynh_replace_string --match_string="canonical: https://framagames.org" --replace_string="canonical: https://$domain" --target_file="src/data/main.yml" + ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH NODE_ENV=production NODE_OPTIONS="--openssl-legacy-provider" $ynh_npm run prod + else + ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH NODE_ENV=production CI_JOB_NAME=pages CI_PAGES_URL="https://$domain$path_url" NODE_OPTIONS="--openssl-legacy-provider" $ynh_npm run prod + fi + + ynh_secure_remove --file="$install_dir/build/public" + mv dist/ public/ + + if [ $path_url == "/" ]; then + cp ./public/$language/index.html ./public/index.html + mv -f games/* public/ + else + cp ./public/$stripped_path/$language/index.html ./public/$stripped_path/index.html + mv -f games/* public/$stripped_path + fi + cd public && for f in $(find -type l);do cp --remove-destination $(readlink -f $f) $f;done; + + popd + + if [ $path_url == "/" ]; then + mv "$install_dir/build/public" "$install_dir/public" + else + mv "$install_dir/build/public/$stripped_path" "$install_dir/public" + fi + + ynh_secure_remove --file="$install_dir/build" +fi + #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/tests.toml b/tests.toml index eb73b8d..6a8774d 100644 --- a/tests.toml +++ b/tests.toml @@ -1,3 +1,9 @@ test_format = 1.0 -[default] \ No newline at end of file +[default] + + # ------------ + # Tests to run + # ------------ + + test_upgrade_from.fb3cdde65e8003c2386002e7dc49c02989f9198d.name = "Upgrade from 1.0~ynh4"