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

129 lines
6.2 KiB
Bash
Raw Permalink Normal View History

2023-08-04 22:12:34 +02:00
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
#=================================================
# PERSONAL HELPERS
#=================================================
2023-08-24 17:03:22 +02:00
generate_config_panel() {
2023-08-29 05:53:09 +02:00
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
2023-08-24 17:03:22 +02:00
2023-08-29 03:44:51 +02:00
create_service_properties
}
create_service_properties() {
2023-08-29 05:53:09 +02:00
local app=chatonsinfos
export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g" | grep -v chatonsinfos)
2023-08-29 03:44:51 +02:00
for _app_id in $apps ;
2023-08-24 17:03:22 +02:00
do
2023-08-29 03:44:51 +02:00
_app=${_app_id%__*}
local service_path="$install_dir/public/${_app_id}.properties"
if [ ! -e "$service_path" ]
2023-08-24 17:03:22 +02:00
then
2023-08-29 03:44:51 +02:00
local source_path="$install_dir/sources/MODELES/service-${_app}.properties"
if [ ! -e "$source_path" ]
then
source_path="$install_dir/sources/MODELES/service.properties"
fi
cp "$source_path" "$service_path"
# Prefill the properties
2023-08-29 05:53:09 +02:00
ynh_print_info --message="Filling '$service_path'"
2023-08-29 03:44:51 +02:00
local app_info="$(yunohost app info $_app_id --full --json)"
get_info() {
2023-08-29 05:53:09 +02:00
echo $app_info | jq -r ".$1"
2023-08-29 03:44:51 +02:00
}
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"
ynh_write_var_in_file --file="$service_path" --key="service.name" --value="$(get_info 'name')"
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')"
2023-08-29 05:53:09 +02:00
ynh_write_var_in_file --file="$service_path" --key="service.logo" --value="https://$(get_info 'settings.domain')/yunohost/admin/appslogo/$(get_info 'logo')"
2023-09-02 22:48:56 +02:00
ynh_write_var_in_file --file="$service_path" --key="service.startdate" --value="$(date '+%d/%m/%Y')"
2023-08-29 03:44:51 +02:00
ynh_write_var_in_file --file="$service_path" --key="service.status.level" --value="OK"
local ldap="$(get_info 'manifest.integration.ldap')"
local sso="$(get_info 'manifest.integration.sso')"
local allowed="$(get_info 'permissions.allowed')"
local registration="Member"
if [[ "$allowed" == *"visitors"* && "$ldap" == "not_relevant" && "$sso" == "not_relevant" ]]
then
registration="None"
elif [[ "$allowed" == *"visitors"* && "$ldap" == "false" ]]
then
registration="Free"
fi
ynh_write_var_in_file --file="$service_path" --key="service.registration" --value="$registration"
ynh_write_var_in_file --file="$service_path" --key="service.registration.load" --value="OPEN"
ynh_write_var_in_file --file="$service_path" --key="service.install.type" --value="DISTRIBUTION"
ynh_write_var_in_file --file="$service_path" --key="software.name" --value="$(get_info 'manifest.name')"
ynh_write_var_in_file --file="$service_path" --key="software.website" --value="$(get_info 'manifest.upstream.website')"
ynh_write_var_in_file --file="$service_path" --key="software.license.url" --value="https://spdx.org/licenses/$(get_info 'manifest.upstream.license').html"
ynh_write_var_in_file --file="$service_path" --key="software.license.name" --value="$(get_info 'manifest.upstream.license')"
#ynh_write_var_in_file --file="$service_path" --key="software.version" --value="$(get_info 'manifest.version')"
ynh_write_var_in_file --file="$service_path" --key="software.source.url" --value="$(get_info 'manifest.upstream.code')"
# TODO modules
#ynh_write_var_in_file --file="$service_path" --key="software.modules" --value=""
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//\./_}
2023-08-29 05:53:09 +02:00
local value=$(ynh_app_setting_get --app=$app --key=$settings)
2023-08-29 03:44:51 +02:00
ynh_write_var_in_file --file="$service_path" --key="$config_key" --value="$value"
done
2023-08-24 17:03:22 +02:00
fi
done
2023-08-29 05:53:09 +02:00
chown $app:www-data "$install_dir"
chown -R $app:www-data "$install_dir/public"
2023-08-24 17:03:22 +02:00
chown -R $app:www-data "$install_dir/public"
chmod -R o-rwx "$install_dir"
#chmod a-x "$install_dir/{public,sources}/*"
2023-08-08 10:25:19 +02:00
}
2023-08-29 03:44:51 +02:00
update_subs() {
local app_published
2023-08-29 05:53:09 +02:00
local app=chatonsinfos
2023-09-04 00:40:26 +02:00
export apps=$(yunohost app list | grep "id\:" | sed "s/ *id: //g" | grep -v chatonsinfos)
2023-08-29 05:53:09 +02:00
local orga_path="$install_dir/public/organization.properties"
2023-08-29 03:44:51 +02:00
# Remove all subs
sed -i "/^subs\..* =/d" "$orga_path"
# Add a subs for each published apps
for subs_app_id in $apps
do
local app_published=$(ynh_app_setting_get --app=$app --key=${subs_app_id}_published)
if [ "$app_published" == "" ]
then
sed -i "/\[Subs\]/a \
subs.${subs_app_id} = 'https://$domain$path/${subs_app_id}.properties'" "$orga_path"
fi
done
# Add external subs
local external_subs=$(ynh_app_setting_get --app=$app --key=external_subs | sed "s/,/ /g")
for external_sub in $external_subs
do
local subs_app_id=${external_sub%*:}
local subs_url=${external_sub#*:}
sed -i "/\[Subs\]/a \
subs.${subs_app_id} = '${subs_url}'" "$orga_path"
done
ynh_write_var_in_file --file="$orga_path" --key="file.datetime" --value="$(date '+%Y-%m-%dT%H:%M:%S')"
}
2023-08-04 22:12:34 +02:00
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================