diff --git a/conf/config_panel.toml.j2 b/conf/config_panel.toml.j2 index 9a9e246..0943292 100644 --- a/conf/config_panel.toml.j2 +++ b/conf/config_panel.toml.j2 @@ -1,7 +1,7 @@ version = "1.0" [main] -bind = ":__INSTALL_DIR__/public/organization.properties" +bind = ":{{ install_dir }}/public/organization.properties" services = [] @@ -14,7 +14,7 @@ services = [] # help = "" optional = true - [main.organization.name] + [main.organization._name] ask.fr = "Nom de l'oganisation" type = "string" example = "Le petit chaton" @@ -54,7 +54,7 @@ services = [] bind = "organization.:" - [main.organization.type] + [main.organization._type] ask.fr = "Type d'organisation" type = "string" choices.ASSOCIATION = "Association" @@ -115,7 +115,7 @@ services = [] bind = "organization.memberof.chatons.status.level:" optional = false - [main.organization.status-description] + [main.organization.status-description-chatons] ask.fr = "Description du statut" type = "string" bind = "organization.memberof.chatons.status.description:" @@ -305,7 +305,7 @@ services = [] [host] name = "Hébergement" -bind = "multi_file({% for app in apps %}__INSTALL_DIR__/public/{{ app }}.properties {% endfor %})" +bind = "multi_file({% for app in apps.split(',') %}{{ install_dir }}/public/{{ app }}.properties {% endfor %})" [host.provider] name = "Fournisseur" @@ -361,9 +361,9 @@ bind = "multi_file({% for app in apps %}__INSTALL_DIR__/public/{{ app }}.propert choices.SHARED = "hébergement mutualisé" choices.CLOUD = "infrastructure multi-serveurs" -{% for app in apps %} +{% for app in apps.split(',') %} [{{ app }}] -bind = ":__INSTALL_DIR__/public/{{ app }}.properties" +bind = ":{{ install_dir }}/public/{{ app }}.properties" [{{ app }}.service] @@ -463,6 +463,6 @@ name.fr = "Avancé" ask.fr = "Fichiers properties complémentaires" help.fr = "Permet de déclarer d'autres services ou offres d'hébergement présent sur d'autres serveurs. Saisissez les tags au format: `clé:https://url/du/fichier.properties`. Attention: la clé doit-être unique et ne pas être en conflit avec un id d'une app sur ce yunohost" type = "tags" - pattern.regexp = "^[a-zA-Z_]+:https?://.*\.properties$" + pattern.regexp = "^[a-zA-Z_]+:https?://.*\\.properties$" pattern.error = "Saisissez les tags au format: `clé:https://url/du/fichier.properties`" bind="manage_subs()" diff --git a/conf/nginx.conf b/conf/nginx.conf index aeb0009..1fdbde0 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,6 +2,7 @@ location __PATH__/ { default_type "text/plain"; + charset utf-8; # Path to source alias __INSTALL_DIR__/public/; diff --git a/hooks/post_app_change_url b/hooks/post_app_change_url index 403aa35..6d73392 100644 --- a/hooks/post_app_change_url +++ b/hooks/post_app_change_url @@ -1,6 +1,6 @@ #!/bin/bash source /usr/share/yunohost/helpers -properties_path="/var/www/chatonsinfo/public/${YNH_APP_INSTANCE_NAME}.properties" +properties_path="/var/www/chatonsinfos/public/${YNH_APP_INSTANCE_NAME}.properties" ynh_write_var_in_file --file="$properties_path" --key="service.website" --value="https://$YNH_APP_NEW_DOMAIN/$YNH_APP_NEW_PATH" ynh_write_var_in_file --file="$properties_path" --key="file.datetime" --value="$(date '+%Y-%m-%dT%H:%M:%S')" diff --git a/hooks/post_app_install b/hooks/post_app_install index 4bd0cca..085c37c 100644 --- a/hooks/post_app_install +++ b/hooks/post_app_install @@ -1,7 +1,8 @@ #!/bin/bash -source /etc/yunohost/apps/chatonsinfo/scripts/_common.sh +source /etc/yunohost/apps/chatonsinfos/scripts/_common.sh source /usr/share/yunohost/helpers +install_dir=/var/www/chatonsinfos/ generate_config_panel update_subs diff --git a/hooks/post_app_remove b/hooks/post_app_remove index 2b14418..a5f5ba8 100644 --- a/hooks/post_app_remove +++ b/hooks/post_app_remove @@ -1,8 +1,9 @@ #!/bin/bash -source /etc/yunohost/apps/chatonsinfo/scripts/_common.sh +source /etc/yunohost/apps/chatonsinfos/scripts/_common.sh source /usr/share/yunohost/helpers +install_dir=/var/www/chatonsinfos/ ynh_secure_remove --file="$install_dir/public/${YNH_APP_ID}.properties" sed -i "/^subs\.${YNH_APP_ID} =/d" "$install_dir/public/organization.properties" diff --git a/manifest.toml b/manifest.toml index 1367203..af62330 100644 --- a/manifest.toml +++ b/manifest.toml @@ -20,7 +20,7 @@ code = "https://framagit.org/chatons/chatonsinfos" [integration] yunohost = ">= 11.1.0" architectures = "all" -multi_instance = "not_relevant" +multi_instance = false ldap = "not_relevant" sso = "not_relevant" disk = "50M" @@ -45,6 +45,7 @@ ram.runtime = "50M" [resources.sources.main] url = "https://framagit.org/chatons/chatonsinfos/-/archive/master/chatonsinfos-master.tar.gz?path=MODELES" sha256 = "664e1c934ea2fd0b5ee4ff55bbabbc81227a256ee12fd7d18319d13c095690bb" + format = "tar.gz" in_subdir = true [resources.system_user] @@ -53,3 +54,9 @@ ram.runtime = "50M" [resources.install_dir] # This will create/remove the install dir as /var/www/$app # and store the corresponding setting $install_dir + + [resources.permissions] + main.url = "/" + main.show_tile = false + main.allowed = "visitors" + main.auth_header = false diff --git a/scripts/_common.sh b/scripts/_common.sh index fd55961..c98be42 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,14 +8,15 @@ # PERSONAL HELPERS #================================================= generate_config_panel() { - export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g") - ynh_render_template /etc/yunohost/apps/chatonsinfo/conf/config_panel.toml.j2 /etc/yunohost/apps/chatonsinfo/config_panel.toml + export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g" | grep -v chatonsinfos | tr '\n' ',' | sed "s/,$//") + ynh_render_template /etc/yunohost/apps/chatonsinfos/conf/config_panel.toml.j2 /etc/yunohost/apps/chatonsinfos/config_panel.toml create_service_properties } create_service_properties() { - export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g") + local app=chatonsinfos + export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g" | grep -v chatonsinfos) for _app_id in $apps ; do _app=${_app_id%__*} @@ -30,10 +31,10 @@ create_service_properties() { cp "$source_path" "$service_path" # Prefill the properties - ynh_print_info --message="Filling service.properties" + ynh_print_info --message="Filling '$service_path'" local app_info="$(yunohost app info $_app_id --full --json)" get_info() { - cat $app_info | jq -r ".$1" + echo $app_info | jq -r ".$1" } ynh_write_var_in_file --file="$service_path" --key="file.datetime" --value="$(date '+%Y-%m-%dT%H:%M:%S')" ynh_write_var_in_file --file="$service_path" --key="file.generator" --value="chatonsinfos_ynh" @@ -42,6 +43,8 @@ create_service_properties() { ynh_write_var_in_file --file="$service_path" --key="service.description" --value="$(get_info 'description')" ynh_write_var_in_file --file="$service_path" --key="service.guide.technical" --value="$(get_info 'from_catalog.git.url')" ynh_write_var_in_file --file="$service_path" --key="service.website" --value="https://$(get_info 'domain_path')" + ynh_write_var_in_file --file="$service_path" --key="service.logo" --value="https://$(get_info 'settings.domain')/yunohost/admin/appslogo/$(get_info 'logo')" + ynh_write_var_in_file --file="$service_path" --key="service.startdate" --value="$(date '+%Y-%m-%dT%H:%M:%S')" ynh_write_var_in_file --file="$service_path" --key="service.status.level" --value="OK" local ldap="$(get_info 'manifest.integration.ldap')" @@ -71,19 +74,22 @@ create_service_properties() { for config_key in host.name host.description host.server.distribution host.server.type host.provider.type host.provider.hypervisor host.country.name host.country.code do settings=${config_key//\./_} - local value=$(ynh_app_setting_set --app=$app --key=$settings) + local value=$(ynh_app_setting_get --app=$app --key=$settings) ynh_write_var_in_file --file="$service_path" --key="$config_key" --value="$value" done fi done + chown $app:www-data "$install_dir" + chown -R $app:www-data "$install_dir/public" chown -R $app:www-data "$install_dir/public" chmod -R o-rwx "$install_dir" #chmod a-x "$install_dir/{public,sources}/*" } update_subs() { local app_published + local app=chatonsinfos export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g") - local orga_path"$install_dir/public/organization.properties" + local orga_path="$install_dir/public/organization.properties" # Remove all subs sed -i "/^subs\..* =/d" "$orga_path" diff --git a/scripts/backup b/scripts/backup index f094cfc..0fc4824 100755 --- a/scripts/backup +++ b/scripts/backup @@ -38,7 +38,7 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/cron.d/$app" +ynh_backup --src_path="/etc/cron.daily/$app" #================================================= # END OF SCRIPT diff --git a/scripts/config b/scripts/config index 6ef5fa8..bcc7875 100644 --- a/scripts/config +++ b/scripts/config @@ -32,11 +32,13 @@ get__host_properties() { #================================================= # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= +get__multi_file() { + ynh_app_setting_get --app=$app --key=$1 +} set__multi_file() { local short_setting="${1//_/.}" local type="${2}" - local bind_files="${3#*(}" - bind_files="${3%*)}" + local bind_files="$(echo $3 | sed 's/multi_file(//' | sed 's/)//')" local value="${!1}" local bind_file ynh_app_setting_set --app=$app --key=$1 --value="$value" @@ -51,6 +53,9 @@ set__multi_file() { fi } +get__manage_subs() { + ynh_app_setting_get --app=$app --key=$1 +} set__manage_subs() { ynh_print_info --message="Configuration key '$1' edited in app settings" ynh_app_setting_set --app=$app --key=$1 --value="${!1}" diff --git a/scripts/install b/scripts/install index a60fb19..3fad7b8 100755 --- a/scripts/install +++ b/scripts/install @@ -18,7 +18,7 @@ source /usr/share/yunohost/helpers # STORE SETTINGS FROM MANIFEST #================================================= -#ynh_app_setting_set --app=$app --key=maintenance_mode --value=$maintenance_mode +ynh_app_setting_set --app=$app --key=host_server_distribution --value="YunoHost" #================================================= @@ -38,10 +38,19 @@ mkdir $install_dir/public # $install_dir will automatically be initialized with some decent # permission by default ... however, you may need to recursively reapply # ownership to all files such as after the ynh_setup_source step -chown -R root:root "$install_dir/sources" +chown -R root:root "$install_dir" +chown $app:www-data "$install_dir" chown -R $app:www-data "$install_dir/public" chmod -R o-rwx "$install_dir" +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config using the conf/nginx.conf template +ynh_add_nginx_config + #================================================= # APP INITIAL CONFIGURATION #================================================= @@ -49,15 +58,13 @@ chmod -R o-rwx "$install_dir" #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -ls -l $install_dir/sources/main +tree $install_dir/sources cp "$install_dir/sources/MODELES/organization.properties" "$install_dir/public/" orga_path="$install_dir/public/organization.properties" ynh_write_var_in_file --file="$orga_path" --key="file.datetime" --value="$(date '+%Y-%m-%dT%H:%M:%S')" ynh_write_var_in_file --file="$orga_path" --key="file.generator" --value="chatonsinfos_ynh" -mkdir -p "$install_dir/public/organization.d/subs" -mkdir "$install_dir/public/organization.d/metrics" chown -R $app:www-data "$install_dir/public" @@ -71,6 +78,7 @@ generate_config_panel #================================================= # ADD A CRON JOB #================================================= +ynh_script_progression --message="Adding cron job to generate metrics..." --weight=1 cron_path="/etc/cron.daily/$app" ynh_add_config --template="../conf/cron" --destination="$cron_path" @@ -80,7 +88,6 @@ chmod 644 "$cron_path" #================================================= # GENERIC FINALIZATION #================================================= - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index c8a9ab8..2b9f3ab 100755 --- a/scripts/remove +++ b/scripts/remove @@ -11,7 +11,7 @@ source /usr/share/yunohost/helpers ynh_remove_nginx_config -ynh_secure_remove --file="/etc/cron.d/$app" +ynh_secure_remove --file="/etc/cron.daily/$app" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index ca93e67..b10a405 100755 --- a/scripts/restore +++ b/scripts/restore @@ -33,7 +33,7 @@ ynh_script_progression --message="Restoring system configurations related to $ap ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore_file --origin_path="/etc/cron.d/$app" +ynh_restore_file --origin_path="/etc/cron.daily/$app" #================================================= # GENERIC FINALIZATION