#!/bin/zsh # ./install.zsh $pds function at-repos-env() { pds=$1 if [ -z "$1" ];then pds=syu.is fi did=did:plc:6qyecktefllvenje24fcxnie icon=https://git.syui.ai/ai/at/raw/branch/main/icons/Logotype.tsx repos=( https://github.com/did-method-plc/did-method-plc https://github.com/bluesky-social/indigo https://github.com/bluesky-social/atproto https://github.com/bluesky-social/social-app https://github.com/bluesky-social/feed-generator ) d=${0:a:h} dh=${0:a:h:h} name=${pds%%.*} domain=${pds##*.} } function at-repos-json() { f=~/.config/atproto/token.json j="{ \"did\": \"${did}\", \"didDoc\": { \"service\": [ { \"serviceEndpoint\": \"https://${pds}\" } ] }, \"handle\": \"ai.${pds}\", \"accessJwt\": \"xxx\" }" if [ ! -f "$f" ];then mkdir -p ~/.config/atproto echo $j >> $f fi echo $f } function at-repos-token() { at-repos-json if [ -z "$pds" ] && [ -f $f ];then pds=`cat $f|jq -r ".didDoc.service.[].serviceEndpoint"` handle=`cat $f|jq -r ".handle"` did=`cat $f|jq -r ".did"` token=`cat $f|jq -r ".token"` pds=${pds##*/} fi name=${pds%%.*} domain=${pds##*.} } function at-repos-clone() { mkdir -p $d/repos cd $d/repos for ((i=1; i<=${#repos}; i++)); do repo=${repos[$i]} echo $repo if [ -d $d/repos/${repo##*/} ] && [ "${repo##*/}" = "social-app" ];then rm -rf $d/repos/${repo##*/} fi if [ ! -d $d/repos/${repo##*/} ];then git clone $repo fi done if [ ! -f $d/repos/feed-generator/Dockerfile ] && [ -f $d/docker/feed/Dockerfile ];then cp -rf $d/docker/feed/Dockerfile $d/repos/feed-generator/ fi } function at-repos-pull() { cd $d/repos for ((i=1; i<=${#repos}; i++)); do repo=${repos[$i]} echo $repo if [ -d $d/repos/${repo##*/} ];then cd $d/repos/${repo##*/} if ! git pull;then cd $d/repos rm -rf $d/repos/${repo##*/} at-repos-clone fi fi done cd $d } function at-repos-social-app-icon() { curl -sL https://raw.githubusercontent.com/bluesky-social/social-app/main/src/view/icons/Logotype.tsx -o $d/repos/social-app/src/view/icons/Logotype.tsx if [ -d $d/icons ];then mkdir -p $d/icons fi cp -rf $d/repos/social-app/src/view/icons/Logotype.tsx $d/icons/ } function at-repos-social-app-icon-origin() { curl -sL $icon -o $d/icons/Logotype.tsx } function at-repos-social-app-write() { did_admin=did:plc:z72i7hdynmk6r22z27h6tvur dt=$d/repos/social-app/src cd $dt t=(bsky.social bsky.app) for tt in "${t[@]}"; do escaped_tt=$(echo "$tt" | sed 's/\./\\./g') grep -R "$escaped_tt" . | cut -d : -f 1 | sort -u | xargs -r sed -i "s/${tt}/${pds}/g" done t=(api public.api public.api.bsky public.bsky) for tt in "${t[@]}"; do grep -R "${tt}\.${pds}" . | cut -d : -f 1 | sort -u | xargs -r sed -i "s/${tt}\.${pds}/bsky.${pds}/g" done t=(cardyb events status) for tt in "${t[@]}"; do grep -R "${tt}\.${pds}" . | cut -d : -f 1 | sort -u | xargs -r sed -i "s/${tt}\.${pds}/${tt}.bsky.app/g" done f=$dt/lib/strings/url-helpers.ts sed -i 's#https://go.bsky.app/redirect?u=${encodeURIComponent(url)}#url#g' $f sed -i 's#`url`#url#g' $f f=$dt/lib/statsig/statsig.tsx sed -i "s#api: 'https://events.bsky.app/v2'#api: 'https://syu.is/events/v2/disabled'#g" $f sed -i "s#initTimeoutMs: 1,#initTimeoutMs: 1, disableAllLogging: true,#g" $f ## cloudflare worker -> /ipcc #f=$dt/state/geolocation.tsx #sed -i 's#https://syu\.is/ipcc#https://bsky\.app/ipcc#g' $f f=$dt/view/icons/Logotype.tsx o=$d/icons/Logotype.tsx cp -rf $o $f f=$dt/view/com/util/UserAvatar.tsx curl -sL https://raw.githubusercontent.com/bluesky-social/social-app/refs/heads/main/src/view/com/util/UserAvatar.tsx -o $f sed -i "s#/img/avatar/plain/#https://bsky.${pds}/img/avatar/plain/#g" $f sed -i "s#/img/avatar_thumbnail/plain/#https://bsky.${pds}/img/avatar/plain/#g" $f sed -i "s#source={{uri: avatar}}#source={{ uri: hackModifyThumbnailPath(avatar, 1 > 0), }}#g" $f grep -R $did_admin .|cut -d : -f 1|sort -u|xargs sed -i "s/${did_admin}/${did}/g" } function at-repos-bsky-patch() { f=$d/repos/atproto/services/bsky/api.js curl -sL https://raw.githubusercontent.com/bluesky-social/atproto/refs/heads/main/services/bsky/api.js -o $f d_=$d/repos/atproto p_=$d_/105-atproto-services-for-docker.diff cd $d_ # https://github.com/itaru2622/bluesky-selfhost-env/blob/master/patching/105-atproto-services-for-docker.diff curl -sLO https://raw.githubusercontent.com/itaru2622/bluesky-selfhost-env/refs/heads/master/patching/105-atproto-services-for-docker.diff echo "applying patch: under ${d_} for ${p_}" pushd ${d_} patch -p1 < ${p_} popd } function at-repos-docker() { cd $d docker compose build $1 && docker compose up -d } at-repos-env at-repos-clone at-repos-pull at-repos-social-app-icon at-repos-social-app-icon-origin at-repos-social-app-write at-repos-bsky-patch at-repos-docker