-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·206 lines (185 loc) · 7.38 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·206 lines (185 loc) · 7.38 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
set -e
BOLD="\033[1m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
RED="\033[0;31m"
RESET="\033[0m"
echo ""
echo -e "${BOLD}plaud-sync setup${RESET}"
echo "────────────────────────────────────────"
echo ""
# ── Mode ──────────────────────────────────────────────────────────────────────
echo -e "${BOLD}How do you want to run plaud-sync?${RESET}"
echo " 1) Docker (recommended — isolated, runs in background)"
echo " 2) Native macOS (runs as a LaunchAgent, requires Python 3.12+)"
echo ""
read -rp " Choice [1/2]: " MODE_CHOICE
echo ""
case "$MODE_CHOICE" in
2) RUN_MODE="native" ;;
*) RUN_MODE="docker" ;;
esac
# ── Check dependencies ────────────────────────────────────────────────────────
if [ "$RUN_MODE" = "docker" ]; then
echo "Checking Docker..."
if ! command -v docker &>/dev/null; then
echo -e "${RED}✗ Docker not found.${RESET}"
echo " Install Docker Desktop: https://www.docker.com/products/docker-desktop/"
exit 1
fi
if ! docker compose version &>/dev/null 2>&1 && ! docker-compose version &>/dev/null 2>&1; then
echo -e "${RED}✗ Docker Compose not found.${RESET}"
echo " Docker Compose is bundled with Docker Desktop — make sure it's running."
exit 1
fi
echo -e " ${GREEN}✓ Docker OK${RESET}"
echo ""
else
echo "Checking Python..."
if ! command -v python3 &>/dev/null; then
echo -e "${RED}✗ python3 not found.${RESET}"
echo " Install Python 3.12+: https://www.python.org/downloads/"
exit 1
fi
PY_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
PY_MAJOR=$(echo "$PY_VERSION" | cut -d. -f1)
PY_MINOR=$(echo "$PY_VERSION" | cut -d. -f2)
if [ "$PY_MAJOR" -lt 3 ] || { [ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 10 ]; }; then
echo -e "${RED}✗ Python $PY_VERSION found, need 3.10+.${RESET}"
exit 1
fi
echo -e " ${GREEN}✓ Python $PY_VERSION OK${RESET}"
PYTHON_PATH=$(command -v python3)
echo ""
fi
# ── Token ─────────────────────────────────────────────────────────────────────
echo -e "${BOLD}1. Plaud token${RESET}"
echo " Go to web.plaud.ai → log in → open DevTools Console (F12)"
echo " If Chrome warns 'Don't paste code you don't trust' → type: allow pasting"
echo " Then run:"
echo ""
echo -e " ${YELLOW}localStorage.getItem(\"pld_tokenstr\")${RESET}"
echo ""
read -rp " Paste token here: " PLAUD_TOKEN
echo ""
# ── Obsidian inbox ────────────────────────────────────────────────────────────
echo -e "${BOLD}2. Obsidian inbox path${RESET}"
echo " Absolute path to the folder where recordings should land."
echo " Example: /Users/you/Documents/Obsidian/MyVault/Inbox"
echo ""
read -rp " Inbox path: " OBSIDIAN_INBOX
if [ ! -d "$OBSIDIAN_INBOX" ]; then
echo ""
echo -e " ${YELLOW}⚠ Directory does not exist. Create it? [y/N]${RESET}"
read -rp " " CREATE_DIR
if [[ "$CREATE_DIR" =~ ^[Yy]$ ]]; then
mkdir -p "$OBSIDIAN_INBOX"
echo -e " ${GREEN}✓ Created${RESET}"
fi
fi
echo ""
# ── Sync interval ─────────────────────────────────────────────────────────────
echo -e "${BOLD}3. Sync interval (hours)${RESET}"
read -rp " Check for new recordings every N hours [default: 1]: " INTERVAL
INTERVAL="${INTERVAL:-1}"
echo ""
# ── Write config files ────────────────────────────────────────────────────────
echo "Writing config files..."
mkdir -p state
if [ "$RUN_MODE" = "docker" ]; then
INBOX_IN_CONFIG="/inbox"
STATE_FILE="/app/state/sync_state.json"
else
INBOX_IN_CONFIG="$OBSIDIAN_INBOX"
STATE_FILE="$(pwd)/state/sync_state.json"
fi
cat > config.yaml <<EOF
plaud:
token: "${PLAUD_TOKEN}"
api_domain: "https://api.plaud.ai"
obsidian:
inbox_path: "${INBOX_IN_CONFIG}"
sync:
interval_hours: ${INTERVAL}
state_file: "${STATE_FILE}"
EOF
cat > .env <<EOF
OBSIDIAN_INBOX=${OBSIDIAN_INBOX}
EOF
# ── Native: install deps + LaunchAgent ────────────────────────────────────────
if [ "$RUN_MODE" = "native" ]; then
echo "Installing Python dependencies..."
pip3 install -q -r requirements.txt
echo -e " ${GREEN}✓ Dependencies installed${RESET}"
PLIST_SRC="$(pwd)/deploy/com.plaud.sync.plist"
PLIST_DST="$HOME/Library/LaunchAgents/com.plaud.sync.plist"
SCRIPT_PATH="$(pwd)/plaud_sync.py"
LOG_PATH="$(pwd)/plaud_sync.log"
cat > "$PLIST_SRC" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.plaud.sync</string>
<key>ProgramArguments</key>
<array>
<string>${PYTHON_PATH}</string>
<string>${SCRIPT_PATH}</string>
<string>--config</string>
<string>$(pwd)/config.yaml</string>
</array>
<key>WorkingDirectory</key>
<string>$(pwd)</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>${LOG_PATH}</string>
<key>StandardErrorPath</key>
<string>${LOG_PATH}</string>
</dict>
</plist>
EOF
echo ""
echo -e "${BOLD}Install LaunchAgent? (starts automatically at login)${RESET}"
read -rp " [y/N]: " INSTALL_AGENT
if [[ "$INSTALL_AGENT" =~ ^[Yy]$ ]]; then
cp "$PLIST_SRC" "$PLIST_DST"
launchctl load "$PLIST_DST"
echo -e " ${GREEN}✓ LaunchAgent installed and started${RESET}"
else
echo " Skipped. To install later:"
echo " cp deploy/com.plaud.sync.plist ~/Library/LaunchAgents/"
echo " launchctl load ~/Library/LaunchAgents/com.plaud.sync.plist"
fi
fi
# ── Done ──────────────────────────────────────────────────────────────────────
echo ""
echo -e "${GREEN}────────────────────────────────────────${RESET}"
echo -e "${BOLD}Setup complete.${RESET}"
echo ""
if [ "$RUN_MODE" = "docker" ]; then
echo " Test (no files written):"
echo " docker compose run --rm plaud-sync python plaud_sync.py --test"
echo ""
echo " First sync — pull everything:"
echo " docker compose run --rm plaud-sync python plaud_sync.py --full-sync"
echo ""
echo " Start daemon:"
echo " docker compose up -d"
echo ""
echo " Logs:"
echo " docker compose logs -f"
else
echo " Test (no files written):"
echo " python3 plaud_sync.py --test"
echo ""
echo " First sync — pull everything:"
echo " python3 plaud_sync.py --full-sync"
echo ""
echo " Logs: $(pwd)/plaud_sync.log"
fi
echo ""