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#!/bin/bash
2
3set -euo pipefail
4
5SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6cd "$SCRIPT_DIR"
7
8echo "🔄 Tweets-2-Bsky Updater"
9echo "========================="
10
11CONFIG_FILE="$SCRIPT_DIR/config.json"
12CONFIG_BACKUP=""
13
14if [ -f "$CONFIG_FILE" ]; then
15 CONFIG_BACKUP="$(mktemp "${TMPDIR:-/tmp}/tweets2bsky-config.XXXXXX")"
16 cp "$CONFIG_FILE" "$CONFIG_BACKUP"
17 echo "🛡️ Backed up config.json to protect local settings."
18fi
19
20restore_config() {
21 if [ -n "$CONFIG_BACKUP" ] && [ -f "$CONFIG_BACKUP" ]; then
22 cp "$CONFIG_BACKUP" "$CONFIG_FILE"
23 rm -f "$CONFIG_BACKUP"
24 echo "🔐 Restored config.json."
25 fi
26}
27
28trap restore_config EXIT
29
30if ! command -v git >/dev/null 2>&1; then
31 echo "❌ Git is not installed. Please install git to update."
32 exit 1
33fi
34
35if ! command -v npm >/dev/null 2>&1; then
36 echo "❌ npm is not installed. Please install Node.js/npm to update."
37 exit 1
38fi
39
40echo "⬇️ Pulling latest changes..."
41if ! git pull --autostash; then
42 echo "⚠️ Standard pull failed. Attempting to stash local changes and retry..."
43 git stash push -u -m "tweets-2-bsky-update-autostash"
44 if ! git pull; then
45 echo "❌ Git pull failed even after stashing. Resolve conflicts manually and rerun ./update.sh."
46 exit 1
47 fi
48fi
49
50echo "📦 Installing dependencies..."
51npm install
52
53echo "🔧 Verifying native modules..."
54if ! npm run rebuild:native; then
55 echo "⚠️ rebuild:native failed (or missing). Falling back to direct better-sqlite3 rebuild..."
56 if ! npm rebuild better-sqlite3; then
57 npm rebuild better-sqlite3 --build-from-source
58 fi
59fi
60
61echo "🏗️ Building server + web dashboard..."
62npm run build
63
64echo "✅ Update complete!"
65
66if command -v pm2 >/dev/null 2>&1; then
67 PROCESS_NAME="tweets-2-bsky"
68 if pm2 describe twitter-mirror >/dev/null 2>&1; then
69 PROCESS_NAME="twitter-mirror"
70 elif pm2 describe tweets-2-bsky >/dev/null 2>&1; then
71 PROCESS_NAME="tweets-2-bsky"
72 fi
73
74 echo "🔄 Restarting PM2 process '$PROCESS_NAME'..."
75 if ! pm2 restart "$PROCESS_NAME" --update-env >/dev/null 2>&1; then
76 echo "ℹ️ PM2 process '$PROCESS_NAME' not found or restart failed. Recreating..."
77 pm2 delete "$PROCESS_NAME" >/dev/null 2>&1 || true
78 pm2 start dist/index.js --name "$PROCESS_NAME"
79 fi
80 pm2 save
81 echo "✅ PM2 process restarted and saved."
82else
83 echo "⚠️ PM2 not found. Please restart your application manually."
84fi