-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathconfig
170 lines (141 loc) · 6.85 KB
/
config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
php_version=$(ynh_app_setting_get --key=php_version)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__maintenance_mode() {
# Maintenance mode status
maintenance_mode_status="$(cd "$install_dir" && ynh_exec_as_app \
php${php_version} --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_warn "Unexpected output from maintenance status check command."
exit 0
fi
}
get__system_addressbook_exposed() {
echo $(exec_occ config:app:get dav system_addressbook_exposed)
}
get__enable_forward_email() {
ldapEmail=$(exec_occ ldap:show-config "" | grep ldapEmailAttribute)
if [ "$(echo $ldapEmail | grep -Po "maildrop")" = "maildrop" ]
then
echo "1"
else
echo "0"
fi
}
#=================================================
# 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
exec_occ 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
exec_occ maintenance:mode --on
ynh_print_info "Maintenance mode enabled"
fi
ynh_app_setting_set --key=maintenance_mode --value="$maintenance_mode"
}
set__system_addressbook_exposed() {
exec_occ config:app:set dav system_addressbook_exposed --value="$system_addressbook_exposed"
ynh_print_info "System addressbook is exposed: $system_addressbook_exposed"
}
set__enable_notify_push() {
if [ "$enable_notify_push" -eq "0" ]; then
nginx_extra_conf_dir="/etc/nginx/conf.d/$domain.d/$app.d"
ynh_safe_rm "$nginx_extra_conf_dir/notify_push.conf"
ynh_systemctl --service="nginx" --action=reload
# If notify_push is enabled, disable it
if exec_occ app:list | awk '/Enabled/{f=1;next} f' | grep -q -w notify_push; then
exec_occ app:disable notify_push
fi
ynh_config_remove_systemd"${app}-notify-push"
systemctl disable --now "${app}-notify-push-watcher.path"
ynh_safe_rm "/etc/systemd/system/${app}-notify-push-watcher.path"
ynh_config_remove_systemd"${app}-notify-push-watcher"
ynh_print_info "Notify push disabled"
elif [ "$enable_notify_push" -eq "1" ]; then
nginx_extra_conf_dir="/etc/nginx/conf.d/$domain.d/$app.d"
mkdir -p "$nginx_extra_conf_dir"
ynh_config_add --template="notify_push.conf" --destination="$nginx_extra_conf_dir/notify_push.conf"
ynh_systemctl --service="nginx" --action=reload
# If notify_push is disabled, reenable it
if exec_occ app:list | awk '/Disabled/{f=1;next} f' | grep -q -w notify_push; then
exec_occ app:enable notify_push
# If notify_push is not installed, install it
elif ! exec_occ app:list | awk '/Enabled/{f=1;next} /Disabled/{f=0} f' | grep -q -w notify_push; then
exec_occ app:install notify_push
fi
exec_occ config:app:set notify_push base_endpoint --value https://$domain${path_url%/}/push
case $YNH_ARCH in
amd64) arch="x86_64";;
arm64) arch="aarch64";;
armel|armhf) arch="armv7";;
esac
ynh_config_add --template="watcher.path" --destination="/etc/systemd/system/${app}-notify-push-watcher.path"
ynh_config_add_systemd --service="${app}-notify-push-watcher" --template="watcher.service"
systemctl enable --now ${app}-notify-push-watcher.path
ynh_config_add_systemd --service="${app}-notify-push"
count=0
while ! ynh_exec_as_app php${php_version} --define apc.enable_cli=1 $install_dir/cron.php && [[ $count -lt 30 ]]
do
sleep 1
count=$((count + 1))
done
ynh_systemctl --service="${app}-notify-push-watcher" --action=restart
ynh_systemctl --service="${app}-notify-push" --action=restart --wait_until="Push daemon for Nextcloud clients." --log_path="systemd"
if ! exec_occ notify_push:self-test; then
ynh_print_warn "The High Performance Backend service is still not working properly. Please log in with a user to your NextCloud instance, restart the High Performance Backend service with \"systemctl restart ${app}-notify-push.service\", and run \"sudo -u $app php${php_version} $install_dir/occ notify_push:self-test\" to verify that everything is green."
fi
ynh_print_info "Notify push enabled"
fi
ynh_app_setting_set --key=enable_notify_push --value="$enable_notify_push"
}
set__enable_forward_email() {
if [ "$enable_forward_email" -eq "0" ]; then
exec_occ ldap:set-config "" ldapEmailAttribute "mail"
ynh_replace --match="\$this->updateEmail(\$ldapEntry\[\$attr\]\[1\]);" --replace="\$this->updateEmail(\$ldapEntry\[\$attr\]\[0\]);" --file="$install_dir/apps/user_ldap/lib/User/User.php"
ynh_store_file_checksum --file="$install_dir/apps/user_ldap/lib/User/User.php"
elif [ "$enable_forward_email" -eq "1" ]; then
exec_occ ldap:set-config "" ldapEmailAttribute "maildrop"
ynh_replace --match="\$this->updateEmail(\$ldapEntry\[\$attr\]\[0\]);" --replace="\$this->updateEmail(\$ldapEntry\[\$attr\]\[1\]);" --file="$install_dir/apps/user_ldap/lib/User/User.php"
ynh_store_file_checksum --file="$install_dir/apps/user_ldap/lib/User/User.php"
fi
ynh_app_setting_set --app=$app --key=enable_forward_email --value="$enable_forward_email"
}
#=================================================
# SPECIFIC RUNNERS FOR TOML SHORT KEYS
#=================================================
function run__set_permissions_button() {
local data_dir=$(ynh_app_setting_get --key=data_dir)
ynh_print_info "Set permissions, it may take some time..."
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
chmod 640 "$install_dir/config/config.php"
chmod 755 /home/yunohost.app
chmod 750 $install_dir
}
#=================================================
ynh_app_config_apply() {
_ynh_app_config_apply
ynh_config_add_phpfpm
}
ynh_app_config_run $1