You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.8 KiB

  1. # -*- mode: shell-script -*-
  2. PDS_LOCAL_DATADIR=/var/lib/bluesky
  3. PDS_DATADIR="$SERVICE_DATASTORE$PDS_LOCAL_DATADIR"
  4. PDS_ENV_FILE="$PDS_DATADIR/.env"
  5. bluesky:init() {
  6. local admin_password
  7. init-config-add "
  8. $SERVICE_NAME:
  9. env_file:
  10. - \"$PDS_ENV_FILE\"
  11. "
  12. [ -e "$PDS_ENV_FILE" ] && return
  13. admin_password=$(password:get admin internal) || {
  14. err "Failed to get admin password" >&2
  15. return 1
  16. }
  17. mkdir -p "${PDS_ENV_FILE%/*}"
  18. if ! plc_key=$(openssl ecparam --name secp256k1 --genkey --noout --outform DER 2>&1); then
  19. err "Failed to generate PLC key" >&2
  20. e "$plc_key" | prefix " $GRAY|$NORMAL " >&2
  21. return 1
  22. fi
  23. if ! plc_key=$(set -o pipefail
  24. echo "$plc_key" |
  25. tail --bytes=+8 |
  26. head --bytes=32 |
  27. xxd --plain --cols 32 2>&1
  28. ); then
  29. err "Failed to extract PLC key" >&2
  30. e "$plc_key" | prefix " $GRAY|$NORMAL " >&2
  31. return 1
  32. fi
  33. if ! jwt_secret=$(openssl rand -hex 16); then
  34. err "Failed to generate JWT secret" >&2
  35. e "$jwt_secret" | prefix " $GRAY|$NORMAL " >&2
  36. return 1
  37. fi
  38. cat > "$PDS_ENV_FILE" <<EOF
  39. PDS_JWT_SECRET=${jwt_secret}
  40. PDS_ADMIN_PASSWORD=${admin_password}
  41. PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX=${plc_key}
  42. PDS_DATA_DIRECTORY=${PDS_LOCAL_DATADIR}
  43. PDS_BLOBSTORE_DISK_LOCATION=${PDS_LOCAL_DATADIR}/blocks
  44. PDS_BLOB_UPLOAD_LIMIT=52428800
  45. PDS_DID_PLC_URL=https://plc.directory
  46. PDS_BSKY_APP_VIEW_URL=https://api.bsky.app
  47. PDS_BSKY_APP_VIEW_DID=did:web:api.bsky.app
  48. PDS_REPORT_SERVICE_URL=https://mod.bsky.app
  49. PDS_REPORT_SERVICE_DID=did:plc:ar7c4by46qjdydhdevvrndac
  50. PDS_CRAWLERS=https://bsky.network
  51. LOG_ENABLED=true
  52. EOF
  53. if email_from=$(options-get "email-from" 2>/dev/null) && [ -n "$email_from" ]; then
  54. echo "PDS_EMAIL_FROM_ADDRESS=${email_from}" >> "$PDS_ENV_FILE"
  55. fi
  56. }