diff --git a/apps-enable.sh b/apps-enable.sh index 59aafbd..a3b8694 100755 --- a/apps-enable.sh +++ b/apps-enable.sh @@ -7,6 +7,8 @@ BDIR="$( dirname "${0}" )" NEXTCLOUD_DIR="${BDIR}/.." +. ${BDIR}/enabled-core-apps.inc.sh + ooc() { php "${NEXTCLOUD_DIR}/occ" \ "${@}" @@ -17,31 +19,84 @@ fail() { exit 1 } +enable_app() { + # Enable app and check if it was enabled + # Fail if enabling the app failed + # + app_name="${1}" + echo "Enable app '${app_name}' ..." + + if ! ooc app:enable "${app_name}" + then + fail "Enabling app \"${app_name}\" failed." + fi +} + enable_apps() { # Enable app in given directory # apps_dir="${1}" + _enabled_apps_count=0 if [ ! -d "${apps_dir}" ]; then fail "Apps directory does not exist: $( readlink -f "${apps_dir}" )" fi - echo "Enable apps in folder ${apps_dir} ..." + _enabled_apps=$(./occ 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}" )" - echo "Enable app '${app_name}' ..." + printf "Checking app: %s" "${app_name}" - if ! ooc app:enable "${app_name}" - then - fail "Enabling app \"${app_name}\" failed." + if echo "${_enabled_apps}" | grep -q -w ${app_name}; then + echo " - already enabled - skipping" + else + echo " - currently disabled - enabling" + enable_app "${app_name}" + _enabled_apps_count=$(( _enabled_apps_count + 1 )) fi done } +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=$(./occ 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 + echo "Checking core app: ${app}" + if echo "${disabled_apps}" | grep -q -w ${app}; then + echo " - currently disabled - enabling" + enable_app "${app}" + _enabled_apps_count=$(( _enabled_apps_count + 1 )) + fi + done + + echo "Enabled ${_enabled_apps_count} core apps." + echo "Done." +} + main() { + if ! jq --version 2>&1 >/dev/null; then + fail "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" + + enable_core_apps } main diff --git a/enabled-core-apps.inc.sh b/enabled-core-apps.inc.sh new file mode 100644 index 0000000..8ad4547 --- /dev/null +++ b/enabled-core-apps.inc.sh @@ -0,0 +1,19 @@ +# List of ./apps to be always enabled. +# Managed as include file so that it can be used in various scripts. +export ENABLED_CORE_APPS="admin_audit +cloud_federation_api +dav +federatedfilesharing +files +files_sharing +files_trashbin +lookup_server_connector +oauth2 +provisioning_api +settings +sharebymail +theming +twofactor_backupcodes +user_status +webhook_listeners +"