A simple tool which lets you scrape twitter accounts and crosspost them to bluesky accounts! Comes with a CLI and a webapp for managing profiles! Works with images/videos/link embeds/threads.
1#!/usr/bin/env bash
2
3set -euo pipefail
4
5SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6cd "$SCRIPT_DIR"
7
8echo "🔧 Repairing PM2 process environment..."
9
10if ! command -v pm2 >/dev/null 2>&1; then
11 echo "❌ PM2 is not installed or not on PATH."
12 exit 1
13fi
14
15resolve_bun_bin() {
16 if command -v bun >/dev/null 2>&1; then
17 command -v bun
18 return 0
19 fi
20
21 if [[ -x "${HOME}/.bun/bin/bun" ]]; then
22 printf '%s\n' "${HOME}/.bun/bin/bun"
23 return 0
24 fi
25
26 return 1
27}
28
29install_latest_bun() {
30 if command -v curl >/dev/null 2>&1; then
31 curl -fsSL https://bun.sh/install | bash >/dev/null
32 return 0
33 fi
34
35 if command -v wget >/dev/null 2>&1; then
36 wget -qO- https://bun.sh/install | bash >/dev/null
37 return 0
38 fi
39
40 echo "❌ Bun is required, and curl/wget is unavailable for auto-install."
41 echo " Install Bun manually: https://bun.com/docs/installation"
42 exit 1
43}
44
45BUN_BIN="$(resolve_bun_bin || true)"
46if [[ -z "$BUN_BIN" || ! -x "$BUN_BIN" ]]; then
47 echo "📦 Bun not found. Installing latest Bun..."
48 install_latest_bun
49 BUN_BIN="$(resolve_bun_bin || true)"
50fi
51
52if [[ -z "$BUN_BIN" || ! -x "$BUN_BIN" ]]; then
53 echo "❌ Bun could not be resolved after install."
54 exit 1
55fi
56
57if ! "$BUN_BIN" upgrade >/dev/null 2>&1; then
58 echo "⚠️ Bun auto-upgrade failed. Reinstalling latest Bun..."
59 install_latest_bun
60 BUN_BIN="$(resolve_bun_bin || true)"
61fi
62
63if [[ -z "$BUN_BIN" || ! -x "$BUN_BIN" ]]; then
64 echo "❌ Bun could not be resolved after auto-upgrade."
65 exit 1
66fi
67
68PROCESS_NAME="tweets-2-bsky"
69if pm2 describe "twitter-mirror" >/dev/null 2>&1; then
70 PROCESS_NAME="twitter-mirror"
71fi
72
73echo "Found process: $PROCESS_NAME"
74echo "Deleting process..."
75pm2 delete "$PROCESS_NAME" || true
76
77echo "Starting process with fresh environment using Bun binary launcher..."
78pm2 start "$BUN_BIN" --name "$PROCESS_NAME" --cwd "$SCRIPT_DIR" --update-env -- dist/index.js
79
80echo "Saving PM2 list..."
81pm2 save
82
83echo "✅ Repair complete."