#!/usr/bin/env bash
set -euo pipefail

APP_DIR="${1:-/home/response/amocrm-telegram.response.by}"
SECRETS_DIR="${2:-/home/response/.secrets}"
ENV_FILE="${3:-$SECRETS_DIR/amocrm-telegram.env}"

chmod 755 "$APP_DIR"
find "$APP_DIR" -type d -exec chmod 755 {} \;
find "$APP_DIR" -type f -exec chmod 644 {} \;
chmod 755 "$APP_DIR/APPLY_PERMISSIONS.sh"
mkdir -p "$SECRETS_DIR"
chmod 700 "$SECRETS_DIR"
if [[ -f "$ENV_FILE" ]]; then
  chmod 600 "$ENV_FILE"
fi

echo "Permissions applied."
