nextcloud-install/docker/restore-config.sh
2026-06-24 09:23:58 +03:00

77 lines
2.6 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Восстановление / сброс config Nextcloud (NEXTCLOUD_CONFIG_DIR из .env)
# ./restore-config.sh — дополнить недостающие шаблоны, починить права
# ./restore-config.sh --force — сброс config и переустановка через occ
# ./restore-config.sh --web — создать CAN_INSTALL для веб-мастера (без occ)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
# shellcheck source=../lib/common.sh
source "${SCRIPT_DIR}/../lib/common.sh"
drop_root_if_sudo "${SCRIPT_DIR}/restore-config.sh" "$@"
FORCE=false
WEB=false
for arg in "$@"; do
case "${arg}" in
--force|-f) FORCE=true ;;
--web) WEB=true; FORCE=true ;;
-h|--help)
echo "Использование: ./restore-config.sh [--force|--web]"
exit 0
;;
esac
done
[[ -f .env ]] || { echo "[ERROR] Нет .env"; exit 1; }
# shellcheck disable=SC1091
source .env
[[ -n "${NEXTCLOUD_CONFIG_DIR:-}" ]] || { echo "[ERROR] NEXTCLOUD_CONFIG_DIR не задан в .env"; exit 1; }
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
CFG="${NEXTCLOUD_CONFIG_DIR}"
SRC="${SCRIPT_DIR}/config.defaults"
if [[ ! -d "${SRC}" ]]; then
echo "[ERROR] Нет ${SRC}/" >&2
exit 1
fi
if [[ "${FORCE}" == true ]]; then
warn "Сброс config в ${CFG}/"
if [[ -f "${CFG}/config.php" ]]; then
sudo cp -a "${CFG}/config.php" "${CFG}.config.php.bak.$(date +%s)" 2>/dev/null || true
fi
fi
info "Восстановление шаблонов config..."
restore_config_templates "${SRC}" "${CFG}" "${NEXTCLOUD_INSTANCEID}" "${FORCE}"
info "Права www-data на ${CFG}/"
fix_config_permissions "${CFG}"
if docker ps --format '{{.Names}}' | grep -q '^nextcloud-app$'; then
run_compose restart app cron
sleep 5
if [[ "${WEB}" == true ]]; then
info "CAN_INSTALL → веб-мастер установки"
sudo touch "${CFG}/CAN_INSTALL"
sudo chown 33:33 "${CFG}/CAN_INSTALL"
sudo chmod 664 "${CFG}/CAN_INSTALL"
warn "Откройте Nextcloud в браузере и завершите установку вручную."
elif [[ "${FORCE}" == true ]] || ! docker exec nextcloud-app test -s /var/www/html/config/config.php 2>/dev/null; then
info "occ maintenance:install..."
occ_maintenance_install
fix_config_permissions "${CFG}"
fi
else
warn "Контейнер nextcloud-app не запущен — выполните ./start.sh"
fi
info "Готово: ${CFG}/"