From 20b5c886b1092e4c03595805b160db04b6beedbe Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 11 Dec 2023 03:44:46 +0100 Subject: [PATCH] [fix] config during install + skeleton dir --- conf/config.json | 2 +- config_panel.toml | 7 ++++++- manifest.toml | 4 ++-- scripts/backup | 1 + scripts/config | 2 +- scripts/install | 32 +++++++++++++++++++++++++------- scripts/remove | 1 + scripts/restore | 1 + 8 files changed, 38 insertions(+), 12 deletions(-) diff --git a/conf/config.json b/conf/config.json index 422aa90..1686aeb 100644 --- a/conf/config.json +++ b/conf/config.json @@ -23,7 +23,7 @@ "lost_password_link": "", "localstorage.allowsymlinks": true, "simpleSignUpLink.shown": false, - "forbidden_chars": ["?", "<", ">", ":", "*", "|", "\"", "\0", "\n", "\r"], + "skeletondirectory": "/home/yunohost.app/__APP__/skeleton/{lang}", "mail_smtpmode": "smtp", "mail_smtpport": "25", "mail_smtpauth": 1, diff --git a/config_panel.toml b/config_panel.toml index 85513de..bc433ee 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -13,7 +13,7 @@ services = ["php8.2-fpm"] bind = ":__INSTALL_DIR__/config/config.php" [main.mode.has_internet_connection] - ask = "Enable closed network mode" + ask = "Internet connection available" type = "boolean" bind = ":__INSTALL_DIR__/config/config.php" help = "Is Nextcloud connected to the Internet or running in a closed network?" @@ -51,6 +51,11 @@ services = ["php8.2-fpm"] [main.files] name = "Files" + [main.files.skeleton] + ask = "To configure the default files created for new users, you can do it by logging on nextcloud with an admins account and edit files under `New user default files/default` or if you want to target a specific language `New user default files/FR`." + type = "alert" + style = "info" + [main.files.trashbin_retention_obligation] ask = "Trashbin retention" type = "string" diff --git a/manifest.toml b/manifest.toml index a8200f6..081adb4 100644 --- a/manifest.toml +++ b/manifest.toml @@ -61,7 +61,7 @@ ram.runtime = "512M" [resources.install_dir] [resources.data_dir] - subdirs = ["data"] + subdirs = ["data", "skeleton"] [resources.permissions] main.url = "/" @@ -77,4 +77,4 @@ ram.runtime = "512M" [resources.database] type = "mysql" - \ No newline at end of file + diff --git a/scripts/backup b/scripts/backup index 924f0bd..b7ea68c 100755 --- a/scripts/backup +++ b/scripts/backup @@ -59,6 +59,7 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" #================================================= ynh_backup --src_path="/etc/cron.d/$app" +ynh_backup --src_path="/etc/cron.d/${app}_upgrade_apps" --not_mandatory #================================================= # BACKUP THE MYSQL DATABASE diff --git a/scripts/config b/scripts/config index da44282..bad56e1 100644 --- a/scripts/config +++ b/scripts/config @@ -69,7 +69,7 @@ set__auto_upgrade_apps() { declare -A frequencies=( [daily]="10 00 * * *" [weekly]="10 00 * * 0" [monthly]="10 00 1 * *" ) if [ "$frequencies[$auto_upgrade_apps]" ] then - echo "${frequencies[$auto_upgrade_apps]} $app /usr/bin/php$phpversion --define apc.enable_cli=1 -f $install_dir/occ app:update --all" > /etc/cron.d/nextcloud_upgrade_apps + echo "${frequencies[$auto_upgrade_apps]} $app /usr/bin/php$phpversion --define apc.enable_cli=1 -f $install_dir/occ app:update --all" > /etc/cron.d/${app}_upgrade_apps else ynh_secure_remove --file=/etc/cron.d/nextcloud_upgrade_apps fi diff --git a/scripts/install b/scripts/install index d99a123..da8c244 100755 --- a/scripts/install +++ b/scripts/install @@ -151,6 +151,7 @@ ynh_secure_remove --file="$nc_conf" nc_conf="$install_dir/config.json" ynh_add_config --template="../conf/config.json" --destination="$nc_conf" +cat $nc_conf exec_occ config:import "$nc_conf" # Then remove the config file @@ -171,13 +172,22 @@ exec_occ ldap:test-config '' \ # Define a function to add an external storage # Create the external storage for the given folders and enable sharing create_external_storage() { - local datadir="$1" + local mount_dir="$1" local mount_name="$2" + local group="${3:-}" local mount_id=`exec_occ files_external:create --output=json \ - "$mount_name" 'local' 'null::null' -c "datadir=$data_dir/data" || true` - ! [[ $mount_id =~ ^[0-9]+$ ]] \ - && ynh_print_warn --message="Unable to create external storage" \ - || exec_occ files_external:option "$mount_id" enable_sharing true + "$mount_name" 'local' 'null::null' -c "datadir=$mount_dir" || true` + if ! [[ $mount_id =~ ^[0-9]+$ ]] + then + ynh_print_warn --message="Unable to create external storage" + else + exec_occ files_external:option "$mount_id" enable_sharing true + if [ "$group" != "" ] + then + exec_occ group:list + exec_occ files_external:applicable "$mount_id" --add-group="$group" + fi + fi } # Enable External Storage and create local mount to home folder @@ -261,6 +271,14 @@ create_external_storage "/home/yunohost.multimedia/share" "Shared multimedia" # Allow nextcloud to write into these directories ynh_multimedia_addaccess $app +#================================================= +# EASY SKELETON CONFIGURATION +#================================================ +ynh_script_progression --message="Easying skeleton configuration..." --weight=1 + +cp -a --no-target-directory $install_dir/core/skeleton "/home/yunohost.app/$app/skeleton/default" +create_external_storage "/home/yunohost.app/$app/skeleton" "New users default files" "admins" + #================================================= # GENERIC FINALIZATION #================================================= @@ -272,8 +290,8 @@ chown -R $app:www-data "$install_dir" chown -R $app: "$data_dir" find $install_dir/ -type f -print0 | xargs -r0 chmod 0644 find $install_dir/ -type d -print0 | xargs -r0 chmod 0755 -find $data_dir/data/ -type f -print0 | xargs -r0 chmod 0640 -find $data_dir/data/ -type d -print0 | xargs -r0 chmod 0750 +find $data_dir/ -type f -print0 | xargs -r0 chmod 0640 +find $data_dir/ -type d -print0 | xargs -r0 chmod 0750 chmod 640 "$install_dir/config/config.php" chmod 755 /home/yunohost.app chmod 750 $install_dir diff --git a/scripts/remove b/scripts/remove index d09cafe..331ac86 100755 --- a/scripts/remove +++ b/scripts/remove @@ -31,6 +31,7 @@ ynh_remove_fail2ban_config # Remove a cron file # TODO: Ensure that cron job is not running (How !?) ynh_secure_remove --file="/etc/cron.d/$app" +ynh_secure_remove --file="/etc/cron.d/${app}_upgrade_apps" # Cleaning ACL in home directories for i in $(ls /home); do diff --git a/scripts/restore b/scripts/restore index 90d8fba..db8c157 100755 --- a/scripts/restore +++ b/scripts/restore @@ -58,6 +58,7 @@ fi ynh_script_progression --message="Restoring cron job..." --weight=1 ynh_restore_file --origin_path="/etc/cron.d/$app" +ynh_restore_file --origin_path="/etc/cron.d/${app}_upgrade_apps" --not_mandatory #================================================= # BACKUP THE LOGROTATE CONFIGURATION