-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapps-enable.sh
More file actions
executable file
·167 lines (133 loc) · 3.99 KB
/
Copy pathapps-enable.sh
File metadata and controls
executable file
·167 lines (133 loc) · 3.99 KB
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
#!/bin/sh
# SPDX-FileCopyrightText: 2025 STRATO GmbH
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# This script assumes to be located in /IONOS as submodule within the Nextcloud server
# repository.
BDIR="$( dirname "${0}" )"
NEXTCLOUD_DIR="${BDIR}/.."
. ${BDIR}/enabled-core-apps.inc.sh
. ${BDIR}/disabled-apps.inc.sh
execute_occ_command() {
php "${NEXTCLOUD_DIR}/occ" \
"${@}"
}
# Log fatal error message and exit with failure code
# Usage: log_fatal <message>
log_fatal() {
echo "\033[1;31m[x] Fatal Error: ${*}\033[0m" >&2
exit 1
}
enable_app() {
# Enable app and check if it was enabled
# Return 1 if enabling the app failed, 0 if successful
#
app_name="${1}"
echo "Enable app '${app_name}' ..."
if ! execute_occ_command app:enable "${app_name}"
then
echo "ERROR: Enabling app \"${app_name}\" failed."
return 1
fi
return 0
}
disable_app() {
# Disable app and check if it was disabled
# Fail if disabling the app failed
#
app_name="${1}"
echo "Disable app '${app_name}' ..."
if ! execute_occ_command app:disable "${app_name}"
then
log_fatal "Disable app \"${app_name}\" failed."
fi
}
enable_apps() {
# Enable app in given directory
#
apps_dir="${1}"
_enabled_apps_count=0
_disabled_apps_count=0
_failed_apps_count=0
_failed_apps_list=""
if [ ! -d "${apps_dir}" ]; then
log_fatal "Apps directory does not exist: $( readlink -f "${apps_dir}" )"
fi
_enabled_apps=$(execute_occ_command app:list --enabled --output json | jq -j '.enabled | keys | join("\n")')
for app in $( find "${apps_dir}" -mindepth 1 -maxdepth 1 -type d | sort); do
app_name="$( basename "${app}" )"
printf "Checking app: %s" "${app_name}"
if echo "${_enabled_apps}" | grep -q -w ${app_name}; then
if echo "${DISABLED_APPS}" | grep -q -w ${app_name}; then
echo " - currently enabled - disabling due to being in DISABLED_APPS"
disable_app "${app_name}"
_disabled_apps_count=$(( _disabled_apps_count + 1 ))
continue
fi
echo " - already enabled - skipping"
else
if echo "${DISABLED_APPS}" | grep -q -w ${app_name}; then
echo " - currently disabled - skipping due to being in DISABLED_APPS"
continue
fi
echo " - currently disabled - enabling"
if enable_app "${app_name}"; then
_enabled_apps_count=$(( _enabled_apps_count + 1 ))
else
_failed_apps_count=$(( _failed_apps_count + 1 ))
if [ -z "${_failed_apps_list}" ]; then
_failed_apps_list="${app_name}"
else
_failed_apps_list="${_failed_apps_list}, ${app_name}"
fi
fi
fi
done
echo
echo "Enabled ${_enabled_apps_count} apps in ${apps_dir}"
echo "Disabled ${_disabled_apps_count} apps in ${apps_dir}"
if [ "${_failed_apps_count}" -gt 0 ]; then
log_fatal "PANIC: Failed to enable ${_failed_apps_count} apps in ${apps_dir}: ${_failed_apps_list}"
fi
echo
}
enable_core_apps() {
# Enable required core apps if they are presently disabled
#
_enabled_apps_count=0
echo "Check required core apps are enabled..."
disabled_apps=$(execute_occ_command app:list --disabled --output json | jq -j '.disabled | keys | join("\n")')
if [ -z "${disabled_apps}" ]; then
echo "No disabled apps found."
exit 0
fi
for app in ${ENABLED_CORE_APPS}; do
printf "Checking core app: %s" "${app}"
if echo "${disabled_apps}" | grep -q -w ${app}; then
if echo "${DISABLED_APPS}" | grep -q -w ${app_name}; then
echo " - currently disabled - skipping due to being in DISABLED_APPS"
continue
fi
echo " - currently disabled - enabling"
enable_app "${app}"
_enabled_apps_count=$(( _enabled_apps_count + 1 ))
else
echo " - already enabled - skip"
fi
done
echo
echo "Enabled ${_enabled_apps_count} core apps."
echo "Done."
}
main() {
if ! jq --version 2>&1 >/dev/null; then
log_fatal "Error: jq is required"
fi
echo "Enable all apps in 'apps-external' folder"
enable_apps "${NEXTCLOUD_DIR}/apps-external"
echo "Enable all apps in 'apps-custom' folder"
enable_apps "${NEXTCLOUD_DIR}/apps-custom"
echo "Enable all apps in 'apps' folder"
enable_core_apps
}
main