fix install.zsh
This commit is contained in:
387
install.zsh
387
install.zsh
@@ -1,24 +1,26 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# ./install.zsh $HOST
|
||||
repos_v='{}'
|
||||
function at-repos-env() {
|
||||
host=$1
|
||||
if [ -z "$1" ];then
|
||||
host=syu.is
|
||||
fi
|
||||
host=syu.is
|
||||
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
|
||||
https://github.com/bluesky-social/ozone
|
||||
https://github.com/bluesky-social/jetstream
|
||||
"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"
|
||||
"https://github.com/bluesky-social/ozone"
|
||||
"https://github.com/bluesky-social/jetstream"
|
||||
)
|
||||
services=(
|
||||
"bsky"
|
||||
"plc"
|
||||
"pds"
|
||||
"jetstream"
|
||||
"bgs"
|
||||
"ozone"
|
||||
"social-app"
|
||||
)
|
||||
services=( bsky plc pds jetstream bgs ozone social-app )
|
||||
d=${0:a:h}
|
||||
dh=${0:a:h:h}
|
||||
name=${host%%.*}
|
||||
@@ -26,28 +28,24 @@ function at-repos-env() {
|
||||
dport=5000
|
||||
}
|
||||
|
||||
function at-repos-json() {
|
||||
f=~/.config/atproto/token.json
|
||||
j="{ \"did\": \"did:plc:6qyecktefllvenje24fcxnie\", \"didDoc\": { \"service\": [ { \"serviceEndpoint\": \"https://syu.is\" } ] }, \"handle\": \"ai.syu.is\", \"accessJwt\": \"xxx\" }"
|
||||
if [ ! -f "$f" ];then
|
||||
mkdir -p ~/.config/atproto
|
||||
echo $j >> $f
|
||||
fi
|
||||
echo $f
|
||||
}
|
||||
# Arrays for patch management
|
||||
typeset -a FAILED_PATCHES
|
||||
|
||||
function at-repos-token() {
|
||||
at-repos-json
|
||||
if [ -z "$host" ] && [ -f $f ];then
|
||||
host=`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"`
|
||||
host=${host##*/}
|
||||
fi
|
||||
name=${host%%.*}
|
||||
domain=${host##*.}
|
||||
}
|
||||
# Patch file lists
|
||||
typeset -a PATCH_FILES_CURL
|
||||
PATCH_FILES_CURL=(
|
||||
"4367-atproto-services-bsky-api.diff:https://raw.githubusercontent.com/bluesky-social/atproto/refs/heads/main/services/bsky/api.js:services/bsky/api.js"
|
||||
"4367-atproto-services-pds-index.diff:https://raw.githubusercontent.com/bluesky-social/atproto/refs/heads/main/services/pds/index.js:services/pds/index.js"
|
||||
)
|
||||
|
||||
typeset -a PATCH_FILES
|
||||
PATCH_FILES=(
|
||||
"170-pds-oauth-same-site-fix.patch"
|
||||
"8980-social-app-disable-proxy.diff"
|
||||
"disable-statsig-sdk.diff"
|
||||
"140-social-app-yarn-network-timeout.patch"
|
||||
"130-atproto-ozone-enable-daemon-v2.patch"
|
||||
)
|
||||
|
||||
function at-repos-clone() {
|
||||
if [ ! -d $d/repos ];then
|
||||
@@ -90,18 +88,6 @@ function at-repos-pull() {
|
||||
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-avatar-write() {
|
||||
did_admin=did:plc:6qyecktefllvenje24fcxnie
|
||||
dt=$d/repos/social-app/src
|
||||
@@ -128,155 +114,185 @@ 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"
|
||||
}
|
||||
|
||||
function at-repos-atproto-service-bsky-api-patch() {
|
||||
# https://github.com/itaru2622/bluesky-selfhost-env/blob/master/patching/105-atproto-services-for-docker.diff
|
||||
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/patching/4367-atproto-services-bsky-api.diff
|
||||
echo "applying patch: under ${f} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
# Common patch function with status detection
|
||||
function apply-patch() {
|
||||
local patch_name=$1
|
||||
local target_dir=$2
|
||||
local patch_file=$3
|
||||
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "📝 Patch: ${patch_name}"
|
||||
echo " Target: ${target_dir}"
|
||||
echo " File: ${patch_file}"
|
||||
|
||||
pushd ${target_dir} > /dev/null
|
||||
|
||||
# Check if patch is already applied (reverse dry-run succeeds)
|
||||
if patch --dry-run -p1 -R < ${patch_file} > /dev/null 2>&1; then
|
||||
echo "✅ Already applied - skipping"
|
||||
popd > /dev/null
|
||||
echo ""
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check if patch can be applied (forward dry-run succeeds)
|
||||
if patch --dry-run -p1 < ${patch_file} > /dev/null 2>&1; then
|
||||
echo "🔧 Applying patch..."
|
||||
if patch -p1 < ${patch_file}; then
|
||||
echo "✅ Applied successfully"
|
||||
popd > /dev/null
|
||||
echo ""
|
||||
return 0
|
||||
else
|
||||
echo "❌ Failed to apply"
|
||||
FAILED_PATCHES+=("${patch_name} (${patch_file})")
|
||||
popd > /dev/null
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "⚠️ Cannot apply - file may have been modified"
|
||||
echo " Please check manually"
|
||||
FAILED_PATCHES+=("${patch_name} (${patch_file}) - file modified")
|
||||
popd > /dev/null
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function at-repos-atproto-service-pds-index-patch() {
|
||||
f=$d/repos/atproto/services/pds/index.js
|
||||
curl -sL https://raw.githubusercontent.com/bluesky-social/atproto/refs/heads/main/services/pds/index.js -o $f
|
||||
d_=$d/repos/atproto
|
||||
p_=$d/patching/4367-atproto-services-pds-index.diff
|
||||
echo "applying patch: under ${f} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
# Function to display failed patches summary
|
||||
function show-failed-patches() {
|
||||
if [ ${#FAILED_PATCHES[@]} -eq 0 ]; then
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "✅ All patches applied successfully!"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "⚠️ FAILED PATCHES SUMMARY"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "The following patches could not be applied:"
|
||||
echo ""
|
||||
for failed_patch in "${FAILED_PATCHES[@]}"; do
|
||||
echo " ❌ ${failed_patch}"
|
||||
done
|
||||
echo ""
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
}
|
||||
|
||||
function at-repos-atproto-oauth-same-site-patch() {
|
||||
f=$d/repos/atproto/packages/oauth/oauth-provider/src/router/create-authorization-page-middleware.ts
|
||||
d_=$d/repos/atproto
|
||||
p_=$d/patching/170-pds-oauth-same-site-fix.patch
|
||||
echo "applying patch: under ${f} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
# Helper function for applying patches
|
||||
function patch-apply() {
|
||||
local name=$1
|
||||
local target=$2
|
||||
local patch_file=$3
|
||||
apply-patch "${name}" "$d/repos/${target}" "$d/patching/${patch_file}"
|
||||
}
|
||||
|
||||
function at-repos-social-app-agent-patch() {
|
||||
f=$d/repos/social-app/src/state/session/agent.ts
|
||||
p_=$d/patching/8980-social-app-disable-proxy.diff
|
||||
d_=$d/repos/social-app
|
||||
echo "applying patch: under ${f} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
# Helper function for patches with curl download
|
||||
function patch-apply-with-curl() {
|
||||
local name=$1
|
||||
local target=$2
|
||||
local patch_file=$3
|
||||
local download_url=$4
|
||||
local download_target=$5
|
||||
|
||||
curl -sL "${download_url}" -o "$d/repos/${target}/${download_target}"
|
||||
apply-patch "${name}" "$d/repos/${target}" "$d/patching/${patch_file}"
|
||||
}
|
||||
|
||||
function at-repos-social-app-disable-external-services-patch() {
|
||||
f=$d/repos/social-app/src/state/geolocation/const.ts
|
||||
p_=$d/patching/8980-social-app-disable-external-services.diff
|
||||
d_=$d/repos/social-app
|
||||
echo "applying patch: under ${f} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
}
|
||||
# Auto-apply patches from list
|
||||
function at-repos-patch-apply-all() {
|
||||
# Apply curl patches
|
||||
for patch_info in "${PATCH_FILES_CURL[@]}"; do
|
||||
local filename="${patch_info%%:*}"
|
||||
local rest="${patch_info#*:}"
|
||||
local download_url="${rest%%:*}"
|
||||
local download_target="${rest#*:}"
|
||||
|
||||
function at-repos-social-app-statsig-patch() {
|
||||
f=$d/repos/social-app/src/lib/statsig/statsig.tsx
|
||||
p_=$d/patching/disable-statsig-sdk.diff
|
||||
d_=$d/repos/social-app
|
||||
echo "applying patch: under ${f} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
}
|
||||
local title="${filename%.*}"
|
||||
local repo=""
|
||||
|
||||
function at-repos-social-app-dockerfile-yarn-timeout-patch() {
|
||||
f=$d/repos/social-app/Dockerfile
|
||||
p_=$d/patching/140-social-app-yarn-network-timeout.patch
|
||||
d_=$d/repos/social-app
|
||||
echo "applying patch: under ${f} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
}
|
||||
# Determine repo from filename
|
||||
if [[ $filename == *"atproto"* ]]; then
|
||||
repo="atproto"
|
||||
elif [[ $filename == *"pds"* ]]; then
|
||||
repo="atproto"
|
||||
fi
|
||||
|
||||
function at-repos-atproto-service-ozone-api-patch() {
|
||||
f=$d/repos/atproto/services/ozone/api.js
|
||||
d_=$d/repos/atproto
|
||||
p_=$d/patching/130-atproto-ozone-enable-daemon-v2.patch
|
||||
echo "applying patch: under ${f} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
patch-apply-with-curl "$title" "$repo" "$filename" "$download_url" "$download_target"
|
||||
done
|
||||
|
||||
# Apply regular patches
|
||||
for filename in "${PATCH_FILES[@]}"; do
|
||||
local title="${filename%.*}"
|
||||
local repo=""
|
||||
|
||||
# Determine repo from filename
|
||||
if [[ $filename == *"social-app"* || $filename == *"statsig"* ]]; then
|
||||
repo="social-app"
|
||||
elif [[ $filename == *"atproto"* ]]; then
|
||||
repo="atproto"
|
||||
elif [[ $filename == *"pds"* ]]; then
|
||||
repo="atproto"
|
||||
fi
|
||||
|
||||
patch-apply "$title" "$repo" "$filename"
|
||||
done
|
||||
}
|
||||
|
||||
function at-repos-ozone-patch() {
|
||||
#DOMAIN=syu.is
|
||||
cd $d/repos
|
||||
d_=$d/repos/ozone
|
||||
rm -rf ${d_}
|
||||
p_=$d/patching/120-ozone-runtimeEnvVars.diff
|
||||
git clone https://github.com/bluesky-social/ozone
|
||||
cd ${d_}
|
||||
pushd ${d_}
|
||||
echo "applying patch: under ${d_} for ${p_}"
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
|
||||
p_=$d/patching/122-ozone-enable-daemon.diff
|
||||
echo "applying patch: under ${d_} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
apply-patch "Ozone enable daemon" "${d_}" "$d/patching/122-ozone-enable-daemon.diff"
|
||||
|
||||
p_=$d/patching/130-ozone-skip-did-check.patch
|
||||
echo "applying patch: under ${d_} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
if [ -f "$d/patching/150-ozone-plc-fix.patch" ]; then
|
||||
apply-patch "Ozone plc fix" "${d_}" "$d/patching/150-ozone-plc-fix.patch"
|
||||
fi
|
||||
|
||||
p_=$d/patching/150-ozone-plc-fix.patch
|
||||
echo "applying patch: under ${d_} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
if [ -f "$d/patching/160-ozone-oauth-redirect-fix.patch" ]; then
|
||||
apply-patch "Ozone oauth redirect fix" "${d_}" "$d/patching/160-ozone-oauth-redirect-fix.patch"
|
||||
fi
|
||||
|
||||
p_=$d/patching/160-ozone-oauth-redirect-fix.patch
|
||||
echo "applying patch: under ${d_} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_}
|
||||
popd
|
||||
# Apply constants fix and do additional sed replacements
|
||||
pushd ${d_} > /dev/null
|
||||
if [ -f "$d/patching/121-ozone-constants-fix.patch" ]; then
|
||||
patch -p1 < "$d/patching/121-ozone-constants-fix.patch" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
p_=$d/patching/121-ozone-constants-fix.patch
|
||||
echo "applying patch: under ${d_} for ${p_}"
|
||||
pushd ${d_}
|
||||
patch -p1 < ${p_} || true
|
||||
# Replace process.env with env()
|
||||
sed -i 's/process\.env\.\(NEXT_PUBLIC_[A-Z_]*\)/env('\''\1'\'')/g' lib/constants.ts
|
||||
sed -i 's/process\.env\.NODE_ENV/env('\''NODE_ENV'\'')/g' lib/constants.ts
|
||||
sed -i 's/process\.env\.\(NEXT_PUBLIC_[A-Z_]*\)/env('\''\1'\'')/g' lib/constants.ts 2>/dev/null || true
|
||||
sed -i 's/process\.env\.NODE_ENV/env('\''NODE_ENV'\'')/g' lib/constants.ts 2>/dev/null || true
|
||||
# Add missing SOCIAL_APP_DOMAIN constant after SOCIAL_APP_URL
|
||||
sed -i '/^export const SOCIAL_APP_URL =/,/^$/{ /^$/a\
|
||||
export const SOCIAL_APP_DOMAIN =\
|
||||
env('\''NEXT_PUBLIC_SOCIAL_APP_DOMAIN'\'') || '\''bsky.app'\''\
|
||||
|
||||
}' lib/constants.ts
|
||||
}' lib/constants.ts 2>/dev/null || true
|
||||
# Fix multiline process.env patterns
|
||||
sed -i '/^export const NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS = process\.env$/,/^ : 7$/ {
|
||||
s/^export const NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS = process\.env$/export const NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS = env('\''NEXT_PUBLIC_NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS'\'')/
|
||||
/^ \.NEXT_PUBLIC_NEW_ACCOUNT_MARKER_THRESHOLD_IN_DAYS$/d
|
||||
}' lib/constants.ts
|
||||
}' lib/constants.ts 2>/dev/null || true
|
||||
sed -i '/^export const YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS = process\.env$/,/^ : 30$/ {
|
||||
s/^export const YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS = process\.env$/export const YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS = env('\''NEXT_PUBLIC_YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS'\'')/
|
||||
/^ \.NEXT_PUBLIC_YOUNG_ACCOUNT_MARKER_THRESHOLD_IN_DAYS$/d
|
||||
}' lib/constants.ts
|
||||
}' lib/constants.ts 2>/dev/null || true
|
||||
sed -i '/^export const HIGH_PROFILE_FOLLOWER_THRESHOLD = process\.env$/,/^ : Infinity$/ {
|
||||
s/^export const HIGH_PROFILE_FOLLOWER_THRESHOLD = process\.env$/export const HIGH_PROFILE_FOLLOWER_THRESHOLD = env('\''NEXT_PUBLIC_HIGH_PROFILE_FOLLOWER_THRESHOLD'\'')/
|
||||
/^ \.NEXT_PUBLIC_HIGH_PROFILE_FOLLOWER_THRESHOLD$/d
|
||||
}' lib/constants.ts
|
||||
}' lib/constants.ts 2>/dev/null || true
|
||||
# Fix parseInt() to handle undefined by adding || ''
|
||||
sed -i "s/parseInt(env('\([^']*\)'))/parseInt(env('\1') || '0')/g" lib/constants.ts
|
||||
popd
|
||||
sed -i "s/parseInt(env('\([^']*\)'))/parseInt(env('\1') || '0')/g" lib/constants.ts 2>/dev/null || true
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
function at-repos-build-docker-atproto() {
|
||||
@@ -312,6 +328,10 @@ function at-repos-push-docker() {
|
||||
service=${services[$i]}
|
||||
docker tag at-${service}:latest localhost:${dport}/${service}:latest
|
||||
docker push localhost:${dport}/${service}:latest
|
||||
if [ "$service" == "ozone" ]];then
|
||||
docker tag at-${service}-web:latest localhost:${dport}/${service}-web:latest
|
||||
docker push localhost:${dport}/${service}-web:latest
|
||||
fi
|
||||
done
|
||||
else
|
||||
docker tag at-${1}:latest localhost:${dport}/${1}:latest
|
||||
@@ -326,38 +346,51 @@ function at-repos-pull-docker() {
|
||||
}
|
||||
|
||||
at-repos-env
|
||||
case "$1" in
|
||||
pull)
|
||||
at-repos-clone
|
||||
at-repos-pull
|
||||
exit
|
||||
;;
|
||||
patch)
|
||||
at-repos-social-app-avatar-write
|
||||
at-repos-patch-apply-all
|
||||
at-repos-ozone-patch
|
||||
show-failed-patches
|
||||
exit
|
||||
;;
|
||||
build)
|
||||
at-repos-build-docker-atproto $2
|
||||
exit
|
||||
;;
|
||||
push)
|
||||
at-repos-push-docker $2
|
||||
exit
|
||||
;;
|
||||
reset)
|
||||
at-repos-push-reset
|
||||
exit
|
||||
;;
|
||||
down)
|
||||
cd $d;docker compose down
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
|
||||
case "`cat /etc/hostname`" in
|
||||
at)
|
||||
at-repos-pull-docker
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
if [ "$1" = "r" ];then
|
||||
at-repos-push-reset
|
||||
exit
|
||||
fi
|
||||
at-repos-clone
|
||||
at-repos-pull
|
||||
at-repos-social-app-icon
|
||||
at-repos-social-app-icon-origin
|
||||
at-repos-social-app-avatar-write
|
||||
at-repos-social-app-agent-patch
|
||||
at-repos-social-app-disable-external-services-patch
|
||||
at-repos-social-app-statsig-patch
|
||||
at-repos-social-app-dockerfile-yarn-timeout-patch
|
||||
at-repos-atproto-service-bsky-api-patch
|
||||
at-repos-atproto-service-pds-index-patch
|
||||
at-repos-atproto-oauth-same-site-patch
|
||||
at-repos-atproto-service-ozone-api-patch
|
||||
at-repos-patch-apply-all
|
||||
at-repos-ozone-patch
|
||||
if [ -n "$1" ];then
|
||||
at-repos-build-docker-atproto $1
|
||||
at-repos-push-docker $1
|
||||
exit
|
||||
fi
|
||||
show-failed-patches
|
||||
at-repos-build-docker-atproto
|
||||
at-repos-push-docker
|
||||
cd $d; docker compose down
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user