48 lines
1.6 KiB
Bash
Executable File
48 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# scripts/reset-admin-password.sh
|
|
# Reset a Nextcloud user's password in the running nextcloud-app container.
|
|
#
|
|
# Usage:
|
|
# ./scripts/reset-admin-password.sh [username]
|
|
# NEW_NEXTCLOUD_PASSWORD='new-password' ./scripts/reset-admin-password.sh [username]
|
|
#
|
|
# Default username: admin
|
|
|
|
set -euo pipefail
|
|
|
|
TARGET_USER="${1:-admin}"
|
|
CONTAINER_NAME="${NEXTCLOUD_APP_CONTAINER:-nextcloud-app}"
|
|
|
|
if [ "${TARGET_USER}" = "-h" ] || [ "${TARGET_USER}" = "--help" ]; then
|
|
echo "Usage: ./scripts/reset-admin-password.sh [username]"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " ./scripts/reset-admin-password.sh admin"
|
|
echo " NEW_NEXTCLOUD_PASSWORD='<new-pass>' ./scripts/reset-admin-password.sh admin"
|
|
exit 0
|
|
fi
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "ERROR: docker is required but not installed."
|
|
exit 1
|
|
fi
|
|
|
|
if ! docker ps --format '{{.Names}}' | grep -qx "${CONTAINER_NAME}"; then
|
|
echo "ERROR: Container '${CONTAINER_NAME}' is not running."
|
|
echo "Start the stack first (e.g. docker compose up -d)."
|
|
exit 1
|
|
fi
|
|
|
|
if [ -n "${NEW_NEXTCLOUD_PASSWORD:-}" ]; then
|
|
echo "==> Resetting password for user '${TARGET_USER}' using NEW_NEXTCLOUD_PASSWORD..."
|
|
OC_PASS="${NEW_NEXTCLOUD_PASSWORD}" docker exec --user www-data -e OC_PASS "${CONTAINER_NAME}" \
|
|
php occ user:resetpassword --password-from-env "${TARGET_USER}"
|
|
echo "==> Password reset completed."
|
|
exit 0
|
|
fi
|
|
|
|
echo "==> Interactive password reset for user '${TARGET_USER}'..."
|
|
echo "You will be prompted securely for the new password."
|
|
docker exec -it --user www-data "${CONTAINER_NAME}" php occ user:resetpassword "${TARGET_USER}"
|
|
echo "==> Password reset completed."
|