From 8d3a052a238e1d456507b64f6af0783bbada3938 Mon Sep 17 00:00:00 2001 From: tytan652 Date: Wed, 19 Jan 2022 21:01:53 +0100 Subject: [PATCH] Use add_config rather than various replace_string --- conf/lufi.conf.template | 30 +++++++++++++++--------------- scripts/change_url | 28 +++++++++------------------- scripts/install | 27 ++++++++------------------- scripts/upgrade | 28 ++++++++-------------------- 4 files changed, 40 insertions(+), 73 deletions(-) diff --git a/conf/lufi.conf.template b/conf/lufi.conf.template index 75a5c33..20993f6 100644 --- a/conf/lufi.conf.template +++ b/conf/lufi.conf.template @@ -59,7 +59,7 @@ # max file size, in octets # you can write it 100*1024*1024 # optional, no default - max_file_size => __MAX_FILE_SIZE__*1024*1024, + __MAX_SIZE_SET__max_file_size => __MAX_FILE_SIZE__*1024*1024, # if you want to have piwik statistics, provide a piwik image tracker # only the image tracker is allowed, no javascript @@ -199,20 +199,20 @@ # set `ldap` if you want that only authenticated users can upload files # please note that everybody can still download files # optional, no default - __USE_LDAP__ldap => { - __USE_LDAP__ uri => 'ldap://localhost:389', # server URI - __USE_LDAP__ user_tree => 'dc=yunohost,dc=org', # search base DN - __USE_LDAP__ bind_dn => 'ou=users,dc=yunohost,dc=org', # search bind DN - __USE_LDAP__ #bind_pwd => 'secr3t', # search bind password - __USE_LDAP__ user_attr => 'uid', # user attribute (uid, mail, sAMAccountName, etc.) - __USE_LDAP__ user_filter => '(&(objectClass=posixAccount)(permission=cn=__APP__.main,ou=permission,dc=yunohost,dc=org))', # user filter (to exclude some users, etc.) - __USE_LDAP__ # optional start_tls configuration. See https://metacpan.org/pod/distribution/perl-ldap/lib/Net/LDAP.pod#start_tls - __USE_LDAP__ # don't set or uncomment if you don't want to configure it - __USE_LDAP__ #start_tls => { - __USE_LDAP__ # verify => 'optional', - __USE_LDAP__ # clientcert => '/etc/ssl/certs/ca-bundle.pem' - __USE_LDAP__ #} - __USE_LDAP__}, + __LDAP__ldap => { + __LDAP__ uri => 'ldap://localhost:389', # server URI + __LDAP__ user_tree => 'dc=yunohost,dc=org', # search base DN + __LDAP__ bind_dn => 'ou=users,dc=yunohost,dc=org', # search bind DN + __LDAP__ #bind_pwd => 'secr3t', # search bind password + __LDAP__ user_attr => 'uid', # user attribute (uid, mail, sAMAccountName, etc.) + __LDAP__ user_filter => '(&(objectClass=posixAccount)(permission=cn=__APP__.main,ou=permission,dc=yunohost,dc=org))', # user filter (to exclude some users, etc.) + __LDAP__ # optional start_tls configuration. See https://metacpan.org/pod/distribution/perl-ldap/lib/Net/LDAP.pod#start_tls + __LDAP__ # don't set or uncomment if you don't want to configure it + __LDAP__ #start_tls => { + __LDAP__ # verify => 'optional', + __LDAP__ # clientcert => '/etc/ssl/certs/ca-bundle.pem' + __LDAP__ #} + __LDAP__}, # if you've set ldap above, the session will last `session_duration` seconds before # the user needs to reauthenticate diff --git a/scripts/change_url b/scripts/change_url index 9d52ff1..46cadcf 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -119,28 +119,18 @@ ynh_script_progression --message="Configuring lufi..." domain="$new_domain" path_url="$new_path" -config=${final_path}/lufi.conf -ynh_backup_if_checksum_is_different --file="$config" -cp ../conf/lufi.conf.template "$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__MAX_FILE_SIZE__" --replace_string="$max_file_size" --target_file="$config" -if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit - ynh_replace_string --match_string="max_file_size" --replace_string="#max_file_size" --target_file="$config" -fi -ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config" +ldap="#" if [ $use_ldap -eq 1 ]; then - ynh_replace_string --match_string="__USE_LDAP__" --replace_string="" --target_file="$config" - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config" -else - ynh_replace_string --match_string="__USE_LDAP__" --replace_string="#" --target_file="$config" + ldap="" fi -ynh_store_file_checksum --file="$config" + +max_size_set="" +if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit + max_size_set="#" +fi + +ynh_add_config --template="../conf/lufi.conf.template" --destination="$final_path/lufi.conf" chmod 600 $final_path/lufi.conf chown $app:$app $final_path/lufi.conf diff --git a/scripts/install b/scripts/install index b400437..848bd44 100644 --- a/scripts/install +++ b/scripts/install @@ -126,29 +126,18 @@ ynh_add_nginx_config max_file_size #================================================= ynh_script_progression --message="Configuring $app..." -config=${final_path}/lufi.conf -cp ../conf/lufi.conf.template "$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__MAX_FILE_SIZE__" --replace_string="$max_file_size" --target_file="$config" -if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit - ynh_replace_string --match_string="max_file_size" --replace_string="#max_file_size" --target_file="$config" -fi -ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config" - +ldap="#" if [ $use_ldap -eq 1 ]; then - ynh_replace_string --match_string="__USE_LDAP__" --replace_string="" --target_file="$config" - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config" -else - ynh_replace_string --match_string="__USE_LDAP__" --replace_string="#" --target_file="$config" + ldap="" fi -ynh_store_file_checksum --file="$config" +max_size_set="" +if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit + max_size_set="#" +fi + +ynh_add_config --template="../conf/lufi.conf.template" --destination="$final_path/lufi.conf" chmod 600 $final_path/lufi.conf chown $app:$app $final_path/lufi.conf diff --git a/scripts/upgrade b/scripts/upgrade index 6056ed6..1d9d4b3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -156,30 +156,18 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Configuring Lufi..." -config=${final_path}/lufi.conf -ynh_backup_if_checksum_is_different --file="$config" -cp ../conf/lufi.conf.template "$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config" -ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config" -ynh_replace_string --match_string="__MAX_FILE_SIZE__" --replace_string="$max_file_size" --target_file="$config" -if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit - ynh_replace_string --match_string="max_file_size" --replace_string="#max_file_size" --target_file="$config" -fi -ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config" - +ldap="#" if [ $use_ldap -eq 1 ]; then - ynh_replace_string --match_string="__USE_LDAP__" --replace_string="" --target_file="$config" - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config" -else - ynh_replace_string --match_string="__USE_LDAP__" --replace_string="#" --target_file="$config" + ldap="" fi -ynh_store_file_checksum --file="$config" +max_size_set="" +if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit + max_size_set="#" +fi + +ynh_add_config --template="../conf/lufi.conf.template" --destination="$final_path/lufi.conf" chmod 600 $final_path/lufi.conf chown $app:$app $final_path/lufi.conf