diff --git a/apps-disable.sh b/apps-disable.sh index e334a55..54da97b 100755 --- a/apps-disable.sh +++ b/apps-disable.sh @@ -14,14 +14,16 @@ SHIPPED_JSON="${BDIR}/../core/shipped.json" . ${BDIR}/disabled-apps.inc.sh -fail() { - echo "${*}" +# Log fatal error message and exit with failure code +# Usage: log_fatal +log_fatal() { + echo "\033[1;31m[x] Fatal Error: ${*}\033[0m" >&2 exit 1 } main() { if ! which jq 2>&1 >/dev/null; then - fail "Error: jq is required" + log_fatal "jq is required" fi # alwaysEnabled should be the only attribute in this json file which really matters, diff --git a/apps-enable.sh b/apps-enable.sh index baa8d1f..626320a 100755 --- a/apps-enable.sh +++ b/apps-enable.sh @@ -10,27 +10,31 @@ NEXTCLOUD_DIR="${BDIR}/.." . ${BDIR}/enabled-core-apps.inc.sh . ${BDIR}/disabled-apps.inc.sh -ooc() { +execute_occ_command() { php "${NEXTCLOUD_DIR}/occ" \ "${@}" } -fail() { - echo "${*}" +# Log fatal error message and exit with failure code +# Usage: log_fatal +log_fatal() { + echo "\033[1;31m[x] Fatal Error: ${*}\033[0m" >&2 exit 1 } enable_app() { # Enable app and check if it was enabled - # Fail if enabling the app failed + # Return 1 if enabling the app failed, 0 if successful # app_name="${1}" echo "Enable app '${app_name}' ..." - if ! ooc app:enable "${app_name}" + if ! execute_occ_command app:enable "${app_name}" then - fail "Enabling app \"${app_name}\" failed." + echo "ERROR: Enabling app \"${app_name}\" failed." + return 1 fi + return 0 } disable_app() { @@ -40,9 +44,9 @@ disable_app() { app_name="${1}" echo "Disable app '${app_name}' ..." - if ! ooc app:disable "${app_name}" + if ! execute_occ_command app:disable "${app_name}" then - fail "Disable app \"${app_name}\" failed." + log_fatal "Disable app \"${app_name}\" failed." fi } @@ -52,12 +56,14 @@ enable_apps() { apps_dir="${1}" _enabled_apps_count=0 _disabled_apps_count=0 + _failed_apps_count=0 + _failed_apps_list="" if [ ! -d "${apps_dir}" ]; then - fail "Apps directory does not exist: $( readlink -f "${apps_dir}" )" + log_fatal "Apps directory does not exist: $( readlink -f "${apps_dir}" )" fi - _enabled_apps=$(./occ app:list --enabled --output json | jq -j '.enabled | keys | join("\n")') + _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}" )" @@ -81,14 +87,25 @@ enable_apps() { fi echo " - currently disabled - enabling" - enable_app "${app_name}" - _enabled_apps_count=$(( _enabled_apps_count + 1 )) + 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 } @@ -99,7 +116,7 @@ enable_core_apps() { echo "Check required core apps are enabled..." - disabled_apps=$(./occ app:list --disabled --output json | jq -j '.disabled | keys | join("\n")') + 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." @@ -130,7 +147,7 @@ enable_core_apps() { main() { if ! jq --version 2>&1 >/dev/null; then - fail "Error: jq is required" + log_fatal "Error: jq is required" fi echo "Enable all apps in 'apps-external' folder" diff --git a/configure-object-store.sh b/configure-object-store.sh index 19b48e7..ca86ff8 100755 --- a/configure-object-store.sh +++ b/configure-object-store.sh @@ -2,8 +2,10 @@ NEXTCLOUD_ROOT_DIR="/var/www/html" -fail() { - echo "${*}" >/dev/stderr +# Log fatal error message and exit with failure code +# Usage: log_fatal +log_fatal() { + echo "\033[1;31m[x] Fatal Error: ${*}\033[0m" >/dev/stderr exit 1 } @@ -52,39 +54,39 @@ main() { use_path_style_value="false" if [ ! -x "occ" ]; then - fail "occ command not found, are you in Nextcloud's root dir?" + log_fatal "occ command not found, are you in Nextcloud's root dir?" fi if [ -z "${ENC_OBJECT_STORAGE_BUCKET_NAME}" ]; then - fail "ENC_OBJECT_STORAGE_BUCKET_NAME not set" + log_fatal "ENC_OBJECT_STORAGE_BUCKET_NAME not set" fi if [ -z "${ENC_OBJECT_STORAGE_ACCESS_KEY}" ]; then - fail "ENC_OBJECT_STORAGE_ACCESS_KEY not set" + log_fatal "ENC_OBJECT_STORAGE_ACCESS_KEY not set" fi if [ -z "${ENC_OBJECT_STORAGE_SECRET}" ]; then - fail "ENC_OBJECT_STORAGE_SECRET not set" + log_fatal "ENC_OBJECT_STORAGE_SECRET not set" fi if [ -z "${ENC_OBJECT_STORAGE_REGION}" ]; then - fail "ENC_OBJECT_STORAGE_REGION not set" + log_fatal "ENC_OBJECT_STORAGE_REGION not set" fi if [ -z "${ENC_OBJECT_STORAGE_HOSTNAME}" ]; then - fail "ENC_OBJECT_STORAGE_HOSTNAME not set" + log_fatal "ENC_OBJECT_STORAGE_HOSTNAME not set" fi if [ -z "${ENC_OBJECT_STORAGE_PORT}" ]; then - fail "ENC_OBJECT_STORAGE_PORT not set" + log_fatal "ENC_OBJECT_STORAGE_PORT not set" fi if [ -n "${ENC_OBJECT_STORAGE_USE_SSL}" ] && [ "${ENC_OBJECT_STORAGE_USE_SSL}" != "true" ] && [ "${ENC_OBJECT_STORAGE_USE_SSL}" != "false" ]; then - fail "ENC_OBJECT_STORAGE_USE_SSL, if set should either be true or false" + log_fatal "ENC_OBJECT_STORAGE_USE_SSL, if set should either be true or false" fi if [ -n "${ENC_OBJECT_STORAGE_USE_PATH_STYLE}" ] && [ "${ENC_OBJECT_STORAGE_USE_PATH_STYLE}" != "true" ] && [ "${ENC_OBJECT_STORAGE_USE_PATH_STYLE}" != "false" ]; then - fail "ENC_OBJECT_STORAGE_USE_PATH_STYLE, if set should either be true or false" + log_fatal "ENC_OBJECT_STORAGE_USE_PATH_STYLE, if set should either be true or false" fi if [ "${ENC_OBJECT_STORAGE_USE_SSL}" = "false" ]; then @@ -98,7 +100,7 @@ main() { echo "Writing ${config} ..." if ! write_config_file; then - fail "Error writing the object store config: ${config}" + log_fatal "Error writing the object store config: ${config}" fi echo "Object store config written: ${config}" diff --git a/configure-user-oidc.sh b/configure-user-oidc.sh index fcad808..1622257 100755 --- a/configure-user-oidc.sh +++ b/configure-user-oidc.sh @@ -1,7 +1,9 @@ #!/usr/bin/env sh -fail() { - echo "${*}" >/dev/stderr +# Log fatal error message and exit with failure code +# Usage: log_fatal +log_fatal() { + echo "\033[1;31m[x] Fatal Error: ${*}\033[0m" >/dev/stderr exit 1 } @@ -37,49 +39,49 @@ main() { # - ENC_OIDC_SCOPES (space separated list of scopes, usually at least "openid email profile") if [ ! -x "occ" ]; then - fail "occ command not found, are you in Nextcloud's root dir?" + log_fatal "occ command not found, are you in Nextcloud's root dir?" fi if ! jq --version 2>/dev/null 2>&1; then - fail "jq not found" + log_fatal "jq not found" fi if [ -z "${ENC_OIDC_PROVIDER_IDENTIFIER}" ]; then - fail "ENC_OIDC_PROVIDER_IDENTIFIER not set" + log_fatal "ENC_OIDC_PROVIDER_IDENTIFIER not set" fi if [ -z "${ENC_OIDC_CLIENT_ID}" ]; then - fail "ENC_OIDC_CLIENT_ID not set" + log_fatal "ENC_OIDC_CLIENT_ID not set" fi if [ -z "${ENC_OIDC_SECRET}" ]; then - fail "ENC_OIDC_SECRET not set" + log_fatal "ENC_OIDC_SECRET not set" fi if [ -z "${ENC_OIDC_DISCOVERY_URI}" ]; then - fail "ENC_OIDC_DISCOVERY_URI not set" + log_fatal "ENC_OIDC_DISCOVERY_URI not set" fi if [ -z "${ENC_OIDC_EXTRA_CLAIMS}" ]; then - fail "ENC_OIDC_EXTRA_CLAIMS not set" + log_fatal "ENC_OIDC_EXTRA_CLAIMS not set" fi if [ -z "${ENC_OIDC_MAPPING_UID}" ]; then - fail "ENC_OIDC_MAPPING_UID not set" + log_fatal "ENC_OIDC_MAPPING_UID not set" fi if [ -z "${ENC_OIDC_SCOPES}" ]; then - fail "ENC_OIDC_SCOPES not set" + log_fatal "ENC_OIDC_SCOPES not set" fi if ! configure_user_oidc; then - fail "Error creating provider \"${ENC_OIDC_PROVIDER_IDENTIFIER}\" with client ID \"${ENC_OIDC_CLIENT_ID}\" (occ failed)" + log_fatal "Error creating provider \"${ENC_OIDC_PROVIDER_IDENTIFIER}\" with client ID \"${ENC_OIDC_CLIENT_ID}\" (occ failed)" fi provider_id=$( ./occ user_oidc:provider "${ENC_OIDC_PROVIDER_IDENTIFIER}" --output=json | jq --arg "clientId" "${ENC_OIDC_CLIENT_ID}" 'select(.clientId == $clientId).id' 2>/dev/null ) if [ -z "${provider_id}" ]; then - fail "Error creating provider \"${ENC_OIDC_PROVIDER_IDENTIFIER}\" with client ID \"${ENC_OIDC_CLIENT_ID}\": not found" + log_fatal "Error creating provider \"${ENC_OIDC_PROVIDER_IDENTIFIER}\" with client ID \"${ENC_OIDC_CLIENT_ID}\": not found" fi echo "Provider \"${ENC_OIDC_PROVIDER_IDENTIFIER}\" with client ID \"${ENC_OIDC_CLIENT_ID}\" created. Provider ID: ${provider_id}" diff --git a/configure.sh b/configure.sh index b039d07..c415070 100755 --- a/configure.sh +++ b/configure.sh @@ -1,185 +1,302 @@ #!/bin/sh -BDIR="$( dirname "${0}" )" -NEXTCLOUD_DIR="${BDIR}/.." -FAVICON_DIR=$(cd "${NEXTCLOUD_DIR}/apps-custom/nc_theming/img" && pwd) -ADMIN_USERNAME=${ADMIN_USERNAME:-admin} -ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.net} - -. ${BDIR}/disabled-apps.inc.sh +#=============================================================================== +# HiDrive Next Configuration Script +#=============================================================================== +# This script configures a HiDrive Next instance with IONOS-specific settings. +# +# Features: +# - Server basic configuration (lookup server, admin email, search providers) +# - Theming and branding setup for IONOS HiDrive Next +# - App configuration (viewer, sharing, files, DAV) +# - Integration setup (IONOS processes, serverinfo, Collabora) +# - Selective app disabling based on configuration +# - Configuration partials for app paths +# +# Environment Variables: +# - ADMIN_USERNAME: Admin username (default: admin) +# - ADMIN_EMAIL: Admin email (default: admin@example.net) +# - IONOS_PROCESSES_API_URL: API URL for IONOS processes +# - IONOS_PROCESSES_USER: Username for IONOS processes API +# - IONOS_PROCESSES_PASS: Password for IONOS processes API +# - NC_APP_SERVERINFO_TOKEN: Token for serverinfo app +# - COLLABORA_HOST: Collabora server host URL +# - COLLABORA_EDIT_GROUPS: Groups allowed to edit in Collabora +# - COLLABORA_SELF_SIGNED: Set to "true" for self-signed certificates +# +# Usage: ./configure.sh +#=============================================================================== + +# Script configuration and constants +SCRIPT_DIR="$(dirname "${0}")" +readonly SCRIPT_DIR +NEXTCLOUD_DIR="${SCRIPT_DIR}/.." +readonly NEXTCLOUD_DIR +FAVICON_DIR="$(cd "${NEXTCLOUD_DIR}/apps-custom/nc_theming/img" && pwd)" +readonly FAVICON_DIR +readonly ADMIN_USERNAME=${ADMIN_USERNAME:-admin} +readonly ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.net} + +# Load disabled apps configuration +. "${SCRIPT_DIR}/disabled-apps.inc.sh" + +#=============================================================================== +# Utility Functions +#=============================================================================== + +# Execute NextCloud OCC command with error handling +# Usage: execute_occ_command [args...] +execute_occ_command() { + if ! php occ "${@}"; then + log_error "Failed to execute OCC command: ${*}" + return 1 + fi +} -ooc() { - php occ \ - "${@}" +# Log error message to stderr +# Usage: log_error +log_error() { + echo "\033[1;31m[e] Error: ${*}\033[0m" >&2 } -fail() { - echo "${*}" +# Log fatal error message and exit with failure code +# Usage: log_fatal +log_fatal() { + echo "\033[1;31m[x] Fatal Error: ${*}\033[0m" >&2 exit 1 } -checks() { +# Log warning message with yellow color +# Usage: log_warning +log_warning() { + echo "\033[1;33m[w] Warning: ${*}\033[0m" >&2 +} + +# Log info message +# Usage: log_info +log_info() { + echo "[i] ${*}" +} + +# Check if required dependencies are available +# Usage: check_dependencies +check_dependencies() { if ! which php >/dev/null 2>&1; then - fail "Error: php is required" + log_fatal "php is required but not found in PATH" fi } -config_server() { - echo "Configure NextCloud basics" +# Verify HiDrive Next installation status +# Usage: verify_nextcloud_installation +verify_nextcloud_installation() { + log_info "Verifying HiDrive Next installation status..." + _main_status="$( execute_occ_command status 2>/dev/null | grep 'installed: ' | sed -r 's/^.*installed: (.+)$/\1/' )" - ooc config:system:set lookup_server --value="" - ooc user:setting "${ADMIN_USERNAME}" settings email "${ADMIN_EMAIL}" - # array of providers to be used for unified search - ooc config:app:set --value '["files"]' --type array core unified_search.providers_allowed + # Parse validation + if [ "${_main_status}" != "true" ] && [ "${_main_status}" != "false" ]; then + log_info "Error testing Nextcloud install status. This is the output of occ status:" + execute_occ_command status + log_fatal "Nextcloud is not installed, abort" + elif [ "${_main_status}" != "true" ]; then + log_fatal "Nextcloud is not installed, abort" + fi } -config_ui() { - echo "Configure theming" +#=============================================================================== +# Configuration Functions +#=============================================================================== - ooc theming:config name "HiDrive Next" - ooc theming:config slogan "powered by IONOS" - ooc theming:config imprintUrl " " - ooc theming:config privacyUrl " " - ooc theming:config primary_color "#003D8F" - ooc theming:config disable-user-theming yes - ooc theming:config favicon "${FAVICON_DIR}/favicon.ico" - ooc config:app:set theming backgroundMime --value backgroundColor +# Configure basic HiDrive Next server settings +# Usage: configure_server_basics +configure_server_basics() { + log_info "Configuring HiDrive Next server basics..." - IONOS_HOMEPAGE=$(ooc config:system:get ionos_homepage) - if [ -n "${IONOS_HOMEPAGE}" ]; then - ooc theming:config url "${IONOS_HOMEPAGE}" + execute_occ_command config:system:set lookup_server --value="" + execute_occ_command user:setting "${ADMIN_USERNAME}" settings email "${ADMIN_EMAIL}" + # array of providers to be used for unified search + execute_occ_command config:app:set --value '["files"]' --type array core unified_search.providers_allowed +} + +# Configure HiDrive Next theming and branding +# Usage: configure_theming +configure_theming() { + log_info "Configuring HiDrive Next theming..." + + execute_occ_command theming:config name "HiDrive Next" + execute_occ_command theming:config slogan "powered by IONOS" + execute_occ_command theming:config imprintUrl " " + execute_occ_command theming:config privacyUrl " " + execute_occ_command theming:config primary_color "#003D8F" + execute_occ_command theming:config disable-user-theming yes + execute_occ_command theming:config favicon "${FAVICON_DIR}/favicon.ico" + execute_occ_command config:app:set theming backgroundMime --value backgroundColor + + # Set homepage URL if configured + _ionos_homepage=$(execute_occ_command config:system:get ionos_homepage) + if [ -n "${_ionos_homepage}" ]; then + execute_occ_command theming:config url "${_ionos_homepage}" fi } -configure_app_nc_ionos_processes() { - echo "Configure nc_ionos_processes app" +# Configure IONOS processes app with API credentials +# Usage: configure_ionos_processes_app +configure_ionos_processes_app() { + log_info "Configuring nc_ionos_processes app..." + # Check required environment variables if [ -z "${IONOS_PROCESSES_API_URL}" ] || [ -z "${IONOS_PROCESSES_USER}" ] || [ -z "${IONOS_PROCESSES_PASS}" ]; then - echo "\033[1;33mWarning: IONOS_PROCESSES_API_URL, IONOS_PROCESSES_USER or IONOS_PROCESSES_PASS not set, skipping configuration of nc_ionos_processes app\033[0m" - return + log_warning "IONOS_PROCESSES_API_URL, IONOS_PROCESSES_USER or IONOS_PROCESSES_PASS not set, skipping configuration of nc_ionos_processes app" + return 0 fi - ooc config:app:set --value "${IONOS_PROCESSES_API_URL}" --type string nc_ionos_processes ionos_mail_base_url - ooc config:app:set --value "${IONOS_PROCESSES_USER}" --type string nc_ionos_processes basic_auth_user - ooc config:app:set --value "${IONOS_PROCESSES_PASS}" --sensitive --type string nc_ionos_processes basic_auth_pass + execute_occ_command config:app:set --value "${IONOS_PROCESSES_API_URL}" --type string nc_ionos_processes ionos_mail_base_url + execute_occ_command config:app:set --value "${IONOS_PROCESSES_USER}" --type string nc_ionos_processes basic_auth_user + execute_occ_command config:app:set --value "${IONOS_PROCESSES_PASS}" --sensitive --type string nc_ionos_processes basic_auth_pass } -configure_app_serverinfo() { - echo "Configure serverinfo app" +# Configure serverinfo app with authentication token +# Usage: configure_serverinfo_app +configure_serverinfo_app() { + log_info "Configuring serverinfo app..." if [ -z "${NC_APP_SERVERINFO_TOKEN}" ]; then - echo "\033[1;33mWarning: NC_APP_SERVERINFO_TOKEN not set, skipping configuration of serverinfo app\033[0m" - return + log_warning "NC_APP_SERVERINFO_TOKEN not set, skipping configuration of serverinfo app" + return 0 fi - ooc config:app:set serverinfo token --value "${NC_APP_SERVERINFO_TOKEN}" + execute_occ_command config:app:set serverinfo token --value "${NC_APP_SERVERINFO_TOKEN}" } -configure_app_richdocuments() { - ooc app:disable richdocuments +# Configure Collabora/richdocuments integration +# Usage: configure_collabora_app +configure_collabora_app() { + log_info "Configuring Collabora integration..." + # Disable app initially + execute_occ_command app:disable richdocuments - if ! [ "${COLLABORA_HOST}" ] ; then - fail Collabora host is not set + # Validate required environment variables + if ! [ "${COLLABORA_HOST}" ]; then + log_fatal "COLLABORA_HOST environment variable is not set" fi - if ! [ "${COLLABORA_EDIT_GROUPS}" ] ; then - fail Collabora edit groups are not set + if ! [ "${COLLABORA_EDIT_GROUPS}" ]; then + log_fatal "COLLABORA_EDIT_GROUPS environment variable is not set" fi - ooc app:enable richdocuments - ooc config:app:set richdocuments wopi_url --value="${COLLABORA_HOST}" - ooc config:app:set richdocuments public_wopi_url --value="${COLLABORA_HOST}" - ooc config:app:set richdocuments enabled --value='yes' + # Configure and enable Collabora + execute_occ_command app:enable richdocuments + execute_occ_command config:app:set richdocuments wopi_url --value="${COLLABORA_HOST}" + execute_occ_command config:app:set richdocuments public_wopi_url --value="${COLLABORA_HOST}" + execute_occ_command config:app:set richdocuments enabled --value='yes' - if [ "${COLLABORA_SELF_SIGNED}" = "true" ] ; then - ooc config:app:set richdocuments disable_certificate_verification --value="yes" + # Configure SSL certificate verification + if [ "${COLLABORA_SELF_SIGNED}" = "true" ]; then + execute_occ_command config:app:set richdocuments disable_certificate_verification --value="yes" else - ooc config:app:set richdocuments disable_certificate_verification --value="no" + execute_occ_command config:app:set richdocuments disable_certificate_verification --value="no" fi - ooc config:app:set richdocuments edit_groups --value="${COLLABORA_EDIT_GROUPS}" - ooc app:enable richdocuments + execute_occ_command config:app:set richdocuments edit_groups --value="${COLLABORA_EDIT_GROUPS}" + execute_occ_command app:enable richdocuments - ooc richdocuments:activate-config + execute_occ_command richdocuments:activate-config } config_apps() { - echo "Configure apps ..." + log_info "Configure apps ..." - echo "Configure viewer app" - ooc config:app:set --value yes --type string viewer always_show_viewer + log_info "Configure viewer app" + execute_occ_command config:app:set --value yes --type string viewer always_show_viewer - echo "Disable federated sharing" + log_info "Disable federated sharing" # To disable entering the user@host ID of an external Nextcloud instance # in the (uncustomized) search input field of the share panel - ooc config:app:set --value no files_sharing outgoing_server2server_share_enabled - ooc config:app:set --value no files_sharing incoming_server2server_share_enabled - ooc config:app:set --value no files_sharing outgoing_server2server_group_share_enabled - ooc config:app:set --value no files_sharing incoming_server2server_group_share_enabled - ooc config:app:set --value no files_sharing lookupServerEnabled - ooc config:app:set --value no files_sharing lookupServerUploadEnabled - - echo "Configure internal share settings" + execute_occ_command config:app:set --value no files_sharing outgoing_server2server_share_enabled + execute_occ_command config:app:set --value no files_sharing incoming_server2server_share_enabled + execute_occ_command config:app:set --value no files_sharing outgoing_server2server_group_share_enabled + execute_occ_command config:app:set --value no files_sharing incoming_server2server_group_share_enabled + execute_occ_command config:app:set --value no files_sharing lookupServerEnabled + execute_occ_command config:app:set --value no files_sharing lookupServerUploadEnabled + + log_info "Configure internal share settings" # To limit user and group display in the username search field of the # Share panel to list only users with the same group. Groups should not # "see" each other. Users in one contract are part of one group. - ooc config:app:set --value="yes" core shareapi_only_share_with_group_members - ooc config:app:set --value="no" core shareapi_allow_group_sharing - ooc config:app:set --value='["admin"]' core shareapi_only_share_with_group_members_exclude_group_list - - configure_app_nc_ionos_processes - configure_app_serverinfo - configure_app_richdocuments - - echo "Configure files app" - ooc config:app:set --value yes files crop_image_previews - ooc config:app:set --value yes files show_hidden - ooc config:app:set --value yes files sort_favorites_first - ooc config:app:set --value yes files sort_folders_first - ooc config:app:set --value no files grid_view - ooc config:app:set --value no files folder_tree - - echo "Configure DAV" - ooc config:app:set dav system_addressbook_exposed --value="no" + execute_occ_command config:app:set --value="yes" core shareapi_only_share_with_group_members + execute_occ_command config:app:set --value="no" core shareapi_allow_group_sharing + execute_occ_command config:app:set --value='["admin"]' core shareapi_only_share_with_group_members_exclude_group_list + + configure_ionos_processes_app + configure_serverinfo_app + configure_collabora_app + + log_info "Configure files app" + execute_occ_command config:app:set --value yes files crop_image_previews + execute_occ_command config:app:set --value yes files show_hidden + execute_occ_command config:app:set --value yes files sort_favorites_first + execute_occ_command config:app:set --value yes files sort_folders_first + execute_occ_command config:app:set --value no files grid_view + execute_occ_command config:app:set --value no files folder_tree + + log_info "Configure DAV" + execute_occ_command config:app:set dav system_addressbook_exposed --value="no" } -disable_app() { +#=============================================================================== +# App Management Functions +#=============================================================================== + +# Disable a single HiDrive Next app with error handling +# Usage: disable_single_app +disable_single_app() { # Disable app and check if it was disabled # Fail if disabling the app failed # - app_name="${1}" - echo "Disable app '${app_name}' ..." + _app_name="${1}" + if [ -z "${_app_name}" ]; then + log_fatal "App name is required for disable_single_app function" + fi - if ! ooc app:disable "${app_name}" - then - fail "Disable app \"${app_name}\" failed." - fi + log_info "Disabling app '${_app_name}'..." + + if ! execute_occ_command app:disable "${_app_name}" + then + log_fatal "Disable app \"${_app_name}\" failed." + fi } -disable_apps() { - echo "Disable apps" +# Disable multiple apps based on the DISABLED_APPS list +# Usage: disable_configured_apps +disable_configured_apps() { + log_info "Processing app disabling..." - _enabled_apps=$(./occ app:list --enabled --output json | jq -j '.enabled | keys | join("\n")') + _enabled_apps=$(execute_occ_command app:list --enabled --output json | jq -j '.enabled | keys | join("\n")') _disabled_apps_count=0 - for app_name in ${DISABLED_APPS}; do - printf "Checking app: %s" "${app_name}" - if echo "${_enabled_apps}" | grep -q -w "${app_name}"; then + for _app_name in ${DISABLED_APPS}; do + printf "[?] Checking app: %s" "${_app_name}" + if echo "${_enabled_apps}" | grep -q -w "${_app_name}"; then echo " - currently enabled - disabling" - disable_app "${app_name}" - _disabled_apps_count=$(( _disabled_apps_count + 1 )) + disable_single_app "${_app_name}" + _disabled_apps_count=$((_disabled_apps_count + 1)) else echo " - not enabled - skip" fi done - echo "Disabled ${_disabled_apps_count} apps." + log_info "Disabled ${_disabled_apps_count} apps." } -add_config_partials() { - echo "Add config partials ..." +#=============================================================================== +# Configuration Setup Functions +#=============================================================================== - cat >"${BDIR}"/../config/app-paths.config.php <<-'EOF' +# Add HiDrive Next configuration partials for app paths +# Usage: setup_config_partials +setup_config_partials() { + log_info "Setting up configuration partials..." + + cat >"${SCRIPT_DIR}/../config/app-paths.config.php" <<-'EOF' [ @@ -203,26 +320,28 @@ add_config_partials() { EOF } +#=============================================================================== +# Main Execution Function +#=============================================================================== + +# Main function to orchestrate HiDrive Next configuration +# Usage: main [args...] main() { - checks + log_info "Starting HiDrive Next configuration process..." - _main_status="$( ooc status 2>/dev/null | grep 'installed: ' | sed -r 's/^.*installed: (.+)$/\1/' )" + # Perform initial checks + check_dependencies + verify_nextcloud_installation - # Parse validation - if [ "${_main_status}" != "true" ] && [ "${_main_status}" != false ]; then - echo "Error testing Nextcloud install status. This is the output of occ status:" - ooc status - exit 1 - elif [ "${_main_status}" != "true" ]; then - echo "Nextcloud is not installed, abort" - exit 1 - fi - - add_config_partials - config_server + # Execute configuration steps + setup_config_partials + configure_server_basics config_apps - config_ui - disable_apps + configure_theming + disable_configured_apps + + echo "\033[1;32m[i] HiDrive Next configuration completed successfully!\033[0m" } +# Execute main function with all script arguments main "${@}" diff --git a/readme.md b/readme.md index b1b1c5e..1e210b9 100644 --- a/readme.md +++ b/readme.md @@ -11,4 +11,3 @@ make -f IONOS/Makefile build_locally ```bash make -f IONOS/Makefile build_release ``` -