1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nextcloud_ynh.git synced 2024-09-03 19:55:57 +02:00
This commit is contained in:
ljf (zamentur) 2024-01-21 23:38:40 +01:00 committed by GitHub
commit 4fb788bcc2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 168 additions and 37 deletions

View file

@ -1,5 +1,6 @@
{
"system": {
"maintenance": false,
"updatechecker": false,
"memcache.local": "\\OC\\Memcache\\APCu",
"integrity.check.disabled": true,
@ -12,8 +13,18 @@
"password": ""
},
"hashing_default_password": true,
"has_internet_connection": true,
"default_phone_region": "",
"default_timezone": "Europe/Paris",
"trashbin_retention_obligation": "auto",
"version_retention_obligation": "auto",
"enable_previews": true,
"defaultapp": "dashboard,files",
"lost_password_link": "",
"localstorage.allowsymlinks": true,
"simpleSignUpLink.shown": false,
"skeletondirectory": "__DATA_DIR__/skeleton/{lang}",
"mail_smtpmode": "smtp",
"mail_smtpport": "25",
"mail_smtpauth": 1,

View file

@ -2,14 +2,96 @@ version = "1.0"
[main]
name = "Nextcloud configuration"
services = ["php8.2-fpm"]
[main.maintenance_mode]
name = "Maintenance mode"
[main.mode]
name = "Modes"
[main.maintenance_mode.maintenance_mode]
[main.mode.maintenance]
ask = "Enable maintenance mode"
type = "boolean"
default = "0"
bind = ":__INSTALL_DIR__/config/config.php"
[main.mode.has_internet_connection]
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?"
[main.localization]
name = "Localization"
[main.localization.default_phone_region]
ask = "Default phone region"
type = "select"
bind = ":__INSTALL_DIR__/config/config.php"
help = "It is required to allow inserting phone numbers in the user profiles starting without the country code (e.g. +49 for Germany)."
[main.localization.default_timezone]
ask = "Default timezone"
type = "select"
bind = ":__INSTALL_DIR__/config/config.php"
help = "The default timezone parameter is only used when the timezone of the user cant be determined."
[main.account]
name = "Account"
[main.account.lost_password_link]
ask = "Lost password link"
type = "url"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Allow to redirect on a custom form to require a password reset (for example to ask you to reset it from this YunoHost webadmin)"
[main.account.logout_url]
ask = "Logout URL"
type = "url"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Redirect on this URL when a user click on 'Logout' action"
[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"
bind = ":__INSTALL_DIR__/config/config.php"
help = "If the trash bin app is enabled (default), this setting defines the policy for when files and folders in the trash bin will be permanently deleted."
[main.files.version_retention_obligation]
ask = "Version retention"
type = "string"
bind = ":__INSTALL_DIR__/config/config.php"
help = "If the versions app is enabled (default), this setting defines the policy for when versions will be permanently deleted."
[main.files.enable_previews]
ask = "Enable previews"
type = "boolean"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Info: Previews of photos and text documents could consume a lot of resources."
[main.apps]
name = "Apps"
[main.apps.auto_upgrade_apps]
ask = "Upgrade apps"
type = "select"
choices.manual = "Manually"
choices.daily = "Daily at 00:10"
choices.weekly = "Weekly at 00:10 on Sunday"
choices.monthly = "Monthly at 00:10 on the 1st"
help = "Keep in mind that upgrade apps could break things in your instance, so you need to strike the right balance between reliability and safety."
[main.apps.defaultapp]
ask = "Default app to display"
type = "tags"
bind = ":__INSTALL_DIR__/config/config.php"
help = "Set the default app to open on login."
[main.php_fpm_config]
name = "PHP-FPM configuration"

View file

@ -61,7 +61,7 @@ ram.runtime = "512M"
[resources.install_dir]
[resources.data_dir]
subdirs = ["data"]
subdirs = ["data", "skeleton"]
[resources.permissions]
main.url = "/"

View file

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

View file

@ -21,21 +21,21 @@ current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__default_phone_region() {
cat << EOF
value: "$(ynh_read_var_in_file --file="$install_dir/config/config.php" --key="default_phone_region")"
choices:
EOF
jq '.[][] | " \"\(.alpha_2)\": \"\(.name)\""' -r /usr/share/iso-codes/json/iso_3166-1.json
get__maintenance_mode() {
# Maintenance mode status
maintenance_mode_status="$(cd "$install_dir" && ynh_exec_as "$app" \
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode)" 2> /dev/null
if echo $maintenance_mode_status | grep -q "disabled"
then
echo "0"
elif echo $maintenance_mode_status | grep -q "enabled"
then
echo "1"
else
ynh_print_err --message="Unexpected output from maintenance status check command."
exit 0
fi
}
get__default_timezone() {
cat << EOF
value: "$(ynh_read_var_in_file --file="$install_dir/config/config.php" --key="default_timezone")"
choices:
EOF
timedatectl list-timezones --no-pager | sed 's/^/ - /g'
}
get__fpm_footprint() {
@ -65,19 +65,17 @@ get__fpm_free_footprint() {
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__maintenance_mode() {
if [ "$maintenance_mode" -eq "0" ]; then
# If maintenance_mode was set to 0, disable maintenance mode
(cd "$install_dir" && ynh_exec_as "$app" \
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode --off)
ynh_print_info "Maintenance mode disabled"
elif [ "$maintenance_mode" -eq "1" ]; then
# If maintenance_mode was set to 1, enable maintenance mode
(cd "$install_dir" && ynh_exec_as "$app" \
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi maintenance:mode --on)
ynh_print_info "Maintenance mode enabled"
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/${app}_upgrade_apps
else
ynh_secure_remove --file=/etc/cron.d/nextcloud_upgrade_apps
fi
ynh_app_setting_set --app=$app --key=maintenance_mode --value="$maintenance_mode"
ynh_app_setting_set --app=$app --key=auto_upgrade_apps --value="$auto_upgrade_apps"
}
set__fpm_footprint() {

View file

@ -4,9 +4,24 @@ source _common.sh
source /usr/share/yunohost/helpers
source _ynh_mysql_connect_as.sh
#=================================================
# INIT STUFF FOR CONFIG PANEL, ETC
#=================================================
phpflags="--define apc.enable_cli=1"
ynh_app_setting_set --app=$app --key=maintenance --value=0
ynh_app_setting_set --app=$app --key=phpflags --value=$phpflags
ynh_app_setting_set --app=$app --key=has_internet_connection --value=1
ynh_app_setting_set --app=$app --key=default_phone_region --value=""
ynh_app_setting_set --app=$app --key=default_timezone --value="Europe/Paris"
ynh_app_setting_set --app=$app --key=lost_password_link --value=""
ynh_app_setting_set --app=$app --key=logout_url --value=""
ynh_app_setting_set --app=$app --key=trashbin_retention_obligation --value="auto"
ynh_app_setting_set --app=$app --key=version_retention_obligation --value="auto"
ynh_app_setting_set --app=$app --key=enable_previews --value=1
ynh_app_setting_set --app=$app --key=auto_upgrade_apps --value="manual"
ynh_app_setting_set --app=$app --key=defaultapp --value="dashboard,files"
#=================================================
# CREATE A MYSQL DATABASE
@ -119,6 +134,7 @@ ynh_secure_remove --file="$nc_conf"
nc_conf="$install_dir/config.json"
ynh_add_config --template="config.json" --destination="$nc_conf"
cat $nc_conf
exec_occ config:import "$nc_conf"
# Then remove the config file
@ -141,11 +157,20 @@ exec_occ ldap:test-config '' \
create_external_storage() {
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=$mount_dir" || true`
! [[ $mount_id =~ ^[0-9]+$ ]] \
&& ynh_print_warn --message="Unable to create external storage" \
|| exec_occ files_external:option "$mount_id" enable_sharing 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
@ -229,6 +254,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 "$data_dir/skeleton/default"
create_external_storage "$data_dir/skeleton" "New users default files" "admins"
#=================================================
# GENERIC FINALIZATION
#=================================================
@ -240,8 +273,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

View file

@ -25,6 +25,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

View file

@ -52,6 +52,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

View file

@ -19,6 +19,10 @@ if [ -z "${phpflags:-}" ]; then
ynh_app_setting_set --app=$app --key=phpflags --value=$phpflags
fi
if [ -z "${auto_upgrade_apps:-}" ]; then
ynh_app_setting_set --app=$app --key=auto_upgrade_apps --value="manual"
fi
# Delete existing ini configuration file (backward compatibility)
if [ -f /etc/php/$YNH_PHP_VERSION/fpm/conf.d/20-$app.ini ]; then
ynh_secure_remove --file=/etc/php/$YNH_PHP_VERSION/fpm/conf.d/20-$app.ini