- Added support for equivalent domains in user settings, allowing users to define custom domain groups and exclude specific global groups. - Introduced new migration script to add necessary database columns and a table for global equivalent domains. - Created a Python script to generate seed SQL for global domains, which can be executed to populate the database. - Updated API endpoints to handle equivalent domains, including retrieval and persistence of user-defined settings. - Refactored existing settings handler to remove stubs and implement full functionality for managing equivalent domains.
79 lines
1.7 KiB
Bash
79 lines
1.7 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Seed Vaultwarden/Bitwarden global equivalent domains into Cloudflare D1.
|
|
|
|
This:
|
|
1) Downloads (or reads local) global_domains.json
|
|
2) Generates sql/global_domains_seed.sql
|
|
3) Executes it against a D1 database via wrangler
|
|
|
|
Usage:
|
|
./scripts/seed-global-domains.sh --db <d1_name> [--env <wrangler_env>] [--remote] [--url <raw_json_url>]
|
|
|
|
Examples:
|
|
./scripts/seed-global-domains.sh --db vault1 --remote
|
|
./scripts/seed-global-domains.sh --db vault1 --env dev --remote
|
|
./scripts/seed-global-domains.sh --db vault1 --remote \
|
|
--url https://raw.githubusercontent.com/dani-garcia/vaultwarden/<tag-or-commit>/src/static/global_domains.json
|
|
EOF
|
|
}
|
|
|
|
DB_NAME=""
|
|
ENV_NAME=""
|
|
REMOTE=0
|
|
URL=""
|
|
INPUT=""
|
|
OUTPUT="sql/global_domains_seed.sql"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--db)
|
|
DB_NAME="${2:-}"; shift 2;;
|
|
--env)
|
|
ENV_NAME="${2:-}"; shift 2;;
|
|
--remote)
|
|
REMOTE=1; shift;;
|
|
--url)
|
|
URL="${2:-}"; shift 2;;
|
|
--input)
|
|
INPUT="${2:-}"; shift 2;;
|
|
--output)
|
|
OUTPUT="${2:-}"; shift 2;;
|
|
-h|--help)
|
|
usage; exit 0;;
|
|
*)
|
|
echo "Unknown arg: $1" >&2
|
|
usage
|
|
exit 2;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$DB_NAME" ]]; then
|
|
echo "Missing required --db <d1_name>" >&2
|
|
usage
|
|
exit 2
|
|
fi
|
|
|
|
GEN_ARGS=(--output "$OUTPUT")
|
|
if [[ -n "$INPUT" ]]; then
|
|
GEN_ARGS+=(--input "$INPUT")
|
|
elif [[ -n "$URL" ]]; then
|
|
GEN_ARGS+=(--url "$URL")
|
|
fi
|
|
|
|
python3 scripts/generate-global-domains-seed.py "${GEN_ARGS[@]}"
|
|
|
|
WRANGLER_ARGS=(d1 execute "$DB_NAME" --file "$OUTPUT")
|
|
if [[ -n "$ENV_NAME" ]]; then
|
|
WRANGLER_ARGS+=(--env "$ENV_NAME")
|
|
fi
|
|
if [[ "$REMOTE" -eq 1 ]]; then
|
|
WRANGLER_ARGS+=(--remote)
|
|
fi
|
|
|
|
wrangler "${WRANGLER_ARGS[@]}"
|
|
|
|
|