1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/chatonsinfos_ynh.git synced 2024-09-03 18:15:58 +02:00

[fix] Properties autogen

This commit is contained in:
ljf 2023-08-29 05:53:09 +02:00
parent 63d7dcd62e
commit 22460f532b
No known key found for this signature in database
12 changed files with 58 additions and 30 deletions

View file

@ -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()"

View file

@ -2,6 +2,7 @@
location __PATH__/ {
default_type "text/plain";
charset utf-8;
# Path to source
alias __INSTALL_DIR__/public/;

View file

@ -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')"

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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}"

View file

@ -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
#=================================================

View file

@ -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

View file

@ -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