-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.sh
More file actions
executable file
·86 lines (68 loc) · 2.82 KB
/
Copy pathpatch.sh
File metadata and controls
executable file
·86 lines (68 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
#
# postiz-linkedin-patch
# Trims LinkedIn OAuth scopes in a running Postiz container so it works
# with just "Sign In with LinkedIn" + "Share on LinkedIn" (no Community
# Management API needed). Also flips prompt=none to prompt=consent for
# first-time connects.
#
# Usage:
# bash patch.sh # patches container named "postiz"
# POSTIZ_CONTAINER=foo bash patch.sh # patches container named "foo"
#
# Idempotent: safe to re-run after a container recreate.
#
# License: MIT
# Source: https://github.com/web-werkstatt/postiz-linkedin-patch
set -euo pipefail
CONTAINER="${POSTIZ_CONTAINER:-postiz}"
FILES=(
"/app/apps/backend/dist/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.js"
"/app/apps/orchestrator/dist/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.js"
)
log() { printf '[postiz-linkedin-patch] %s\n' "$*" >&2; }
fail() { log "ERROR: $*"; exit 1; }
command -v docker >/dev/null 2>&1 || fail "docker not found in PATH"
if ! docker inspect "$CONTAINER" >/dev/null 2>&1; then
fail "container '$CONTAINER' not found (override with POSTIZ_CONTAINER=...)"
fi
if ! docker inspect -f '{{.State.Running}}' "$CONTAINER" 2>/dev/null | grep -q true; then
fail "container '$CONTAINER' is not running"
fi
log "patching container: $CONTAINER"
for F in "${FILES[@]}"; do
if ! docker exec "$CONTAINER" test -f "$F"; then
log "WARN: file not found in container, skipping: $F"
continue
fi
log " -> $F"
# Backup (only if .bak doesn't exist yet — preserves the original
# untouched state across re-runs)
docker exec "$CONTAINER" sh -c "[ -f '$F.bak' ] || cp '$F' '$F.bak'"
# Always restore from .bak first, so re-runs apply patch to original
# bytes and stay idempotent
docker exec "$CONTAINER" sh -c "cp '$F.bak' '$F'"
# 1) Remove the 4 problematic scope lines
docker exec "$CONTAINER" sh -c "sed -i \"/'r_basicprofile'/d; /'rw_organization_admin'/d; /'w_organization_social'/d; /'r_organization_social'/d\" '$F'"
# 2) Replace prompt=none with prompt=consent
docker exec "$CONTAINER" sh -c "sed -i 's|prompt=none|prompt=consent|g' '$F'"
done
log "restarting container: $CONTAINER"
docker restart "$CONTAINER" >/dev/null
log "waiting for container to come back up..."
for _ in $(seq 1 30); do
if docker inspect -f '{{.State.Running}}' "$CONTAINER" 2>/dev/null | grep -q true; then
break
fi
sleep 1
done
log "verifying patch:"
for F in "${FILES[@]}"; do
if ! docker exec "$CONTAINER" test -f "$F"; then
continue
fi
SCOPES=$(docker exec "$CONTAINER" sh -c "grep -A 4 'this.scopes = \[' '$F' | head -7")
PROMPT=$(docker exec "$CONTAINER" sh -c "grep -oE 'prompt=[a-z]*' '$F' | head -1")
printf '\n %s\n%s\n prompt: %s\n' "$F" "$SCOPES" "$PROMPT"
done
log "done. Hard-refresh your Postiz tab and try connecting LinkedIn again."