From 9a99ba9d89fb148427bde759050b78e594a820e4 Mon Sep 17 00:00:00 2001 From: syui Date: Sat, 6 Dec 2025 15:09:39 +0900 Subject: [PATCH] add bgs --- install.zsh | 65 ++++++++++++++++++++++++ patching/190-bgs-disable-ratelimit.patch | 12 +++++ 2 files changed, 77 insertions(+) create mode 100644 patching/190-bgs-disable-ratelimit.patch diff --git a/install.zsh b/install.zsh index 59eec59..bba3815 100755 --- a/install.zsh +++ b/install.zsh @@ -21,6 +21,11 @@ function at-repos-env() { "ozone" "social-app" ) + handles=( + "syui.syui.ai" + "ai.syui.ai" + "apple.syu.is" + ) d=${0:a:h} dh=${0:a:h:h} name=${host%%.*} @@ -45,6 +50,7 @@ PATCH_FILES=( "disable-statsig-sdk.diff" "140-social-app-yarn-network-timeout.patch" "130-atproto-ozone-enable-daemon-v2.patch" + "190-bgs-disable-ratelimit.patch" ) function at-repos-clone() { @@ -114,6 +120,7 @@ function at-repos-social-app-avatar-write() { grep -R $did_admin .|cut -d : -f 1|sort -u|xargs sed -i "s/${did_admin}/${did}/g" } + # Common patch function with status detection function apply-patch() { local patch_name=$1 @@ -240,6 +247,8 @@ function at-repos-patch-apply-all() { repo="atproto" elif [[ $filename == *"pds"* ]]; then repo="atproto" + elif [[ $filename == *"indigo"* || $filename == *"bgs"* ]]; then + repo="indigo" fi patch-apply "$title" "$repo" "$filename" @@ -345,6 +354,58 @@ function at-repos-pull-docker() { docker compose up -d --pull always } +function at-repos-reset-bgs-db() { + dp=at-database-1 + BGS_ADMIN_KEY=`cat $d/envs/bgs | grep BGS_ADMIN_KEY | cut -d '=' -f 2` + + echo "🛑 Stopping BGS..." + docker compose stop bgs + + echo "🗑️ Cleaning data..." + sudo rm -rf $d/data/bgs/* + + echo "♻️ Resetting Databases..." + docker exec -i $dp psql -U postgres -c "DROP DATABASE IF EXISTS bgs;" + docker exec -i $dp psql -U postgres -c "CREATE DATABASE bgs;" + docker exec -i $dp psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE bgs TO postgres;" + + docker exec -i $dp psql -U postgres -c "DROP DATABASE IF EXISTS carstore;" + docker exec -i $dp psql -U postgres -c "CREATE DATABASE carstore;" + docker exec -i $dp psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE carstore TO postgres;" + + echo "🚀 Starting BGS to initialize tables..." + docker compose up -d bgs + + echo "⏳ Waiting 10s for BGS migration..." + sleep 10 + + echo "⚙️ Updating Slurp Config..." + docker exec -i $dp psql -U postgres -d bgs -c "UPDATE slurp_configs SET new_subs_disabled = false, new_pds_per_day_limit = 1000 WHERE id = 1;" + + echo "🔗 Registering Trusted Domain & Resetting Repos..." + # Retry loop for addTrustedDomain as BGS might still be warming up + for i in {1..5}; do + if curl -f -X POST "https://bgs.${host}/admin/pds/addTrustedDomain?domain=${host}" -H "Authorization: Bearer ${BGS_ADMIN_KEY}"; then + echo "✅ Trusted domain registered" + break + fi + echo "Bot failed to contact BGS (attempt $i/5)... waiting 5s" + sleep 5 + done + + for ((i=1; i<=${#handles}; i++)); do + handle=${handles[$i]} + did=`curl -sL "https://${host}/xrpc/com.atproto.repo.describeRepo?repo=${handle}" |jq -r .did` + if [ ! -z "$did" ] && [ "$did" != "null" ]; then + echo "Resetting repo: $handle ($did)" + curl -X POST "https://bgs.${host}/admin/repo/reset?did=${did}" \ + -H "Authorization: Bearer ${BGS_ADMIN_KEY}" + else + echo "Skipping reset for $handle (DID not found)" + fi + done +} + at-repos-env case "$1" in pull) @@ -379,6 +440,10 @@ esac case "`cat /etc/hostname`" in at) + if [ "$1" = "reset-bgs-db" ];then + at-repos-reset-bgs-db + exit + fi at-repos-pull-docker exit ;; diff --git a/patching/190-bgs-disable-ratelimit.patch b/patching/190-bgs-disable-ratelimit.patch new file mode 100644 index 0000000..1a6efae --- /dev/null +++ b/patching/190-bgs-disable-ratelimit.patch @@ -0,0 +1,12 @@ +diff --git a/bgs/fedmgr.go b/bgs/fedmgr.go +index 2235c6e..e69de29 100644 +--- a/bgs/fedmgr.go ++++ b/bgs/fedmgr.go +@@ -342,6 +342,7 @@ var ErrNewSubsDisabled = fmt.Errorf("new subscriptions temporarily disabled") + // Checks whether a host is allowed to be subscribed to + // must be called with the slurper lock held + func (s *Slurper) canSlurpHost(host string) bool { ++ return true + // Check if we're over the limit for new PDSs today + if !s.NewPDSPerDayLimiter.Allow() { + return false