Add headless vault REST API server (replaces Obsidian Desktop)
This commit is contained in:
Executable
+125
@@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
# Enable Local REST API plugin headless (no GUI needed)
|
||||
# Force-loads plugin by restarting Obsidian and verifying
|
||||
|
||||
set -e
|
||||
|
||||
VAULT="/workspace/second-brain"
|
||||
PLUGIN_ID="obsidian-local-rest-api"
|
||||
PLUGIN_DIR="$VAULT/.obsidian/plugins/$PLUGIN_ID"
|
||||
|
||||
echo "🔌 Enabling Local REST API plugin (headless)..."
|
||||
|
||||
# 1. Verify plugin files exist
|
||||
if [ ! -f "$PLUGIN_DIR/manifest.json" ]; then
|
||||
echo "❌ Plugin files not found in $PLUGIN_DIR"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Plugin files verified"
|
||||
|
||||
# 2. Ensure plugin is in community-plugins.json
|
||||
PLUGINS_FILE="$VAULT/.obsidian/community-plugins.json"
|
||||
if [ ! -f "$PLUGINS_FILE" ]; then
|
||||
echo '["obsidian-local-rest-api"]' > "$PLUGINS_FILE"
|
||||
echo "✓ community-plugins.json created"
|
||||
else
|
||||
# Add plugin if not already there
|
||||
python3 << PYTHON
|
||||
import json
|
||||
with open('$PLUGINS_FILE', 'r') as f:
|
||||
plugins = json.load(f)
|
||||
if '$PLUGIN_ID' not in plugins:
|
||||
plugins.append('$PLUGIN_ID')
|
||||
with open('$PLUGINS_FILE', 'w') as f:
|
||||
json.dump(plugins, f, indent=2)
|
||||
print("✓ Plugin added to community-plugins.json")
|
||||
else:
|
||||
print("✓ Plugin already in community-plugins.json")
|
||||
PYTHON
|
||||
fi
|
||||
|
||||
# 3. Create workspace config if missing
|
||||
mkdir -p "$VAULT/.obsidian"
|
||||
WORKSPACE_FILE="$VAULT/.obsidian/.obsidian.vimrc"
|
||||
if [ ! -f "$VAULT/.obsidian/workspace.json" ]; then
|
||||
cat > "$VAULT/.obsidian/workspace.json" << 'EOF'
|
||||
{
|
||||
"main": {
|
||||
"id": "root",
|
||||
"type": "split",
|
||||
"children": [
|
||||
{
|
||||
"id": "markdown-source-editor",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "markdown",
|
||||
"state": "#"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"right": {
|
||||
"id": "right-sidebar",
|
||||
"type": "sidebar",
|
||||
"children": []
|
||||
},
|
||||
"left": {
|
||||
"id": "left-sidebar",
|
||||
"type": "sidebar",
|
||||
"children": []
|
||||
},
|
||||
"active": "markdown-source-editor"
|
||||
}
|
||||
EOF
|
||||
echo "✓ workspace.json created"
|
||||
fi
|
||||
|
||||
# 4. Ensure plugin settings directory exists
|
||||
PLUGIN_DATA_DIR="$VAULT/.obsidian/plugins/$PLUGIN_ID"
|
||||
mkdir -p "$PLUGIN_DATA_DIR"
|
||||
|
||||
# 5. Create plugin data.json with settings
|
||||
cat > "$PLUGIN_DATA_DIR/data.json" << 'EOF'
|
||||
{
|
||||
"api_key": "generated-at-plugin-load",
|
||||
"allow_origins": "*",
|
||||
"port": 27123
|
||||
}
|
||||
EOF
|
||||
echo "✓ Plugin config created"
|
||||
|
||||
# 6. Kill existing Obsidian processes
|
||||
echo "Restarting Obsidian..."
|
||||
pkill -f "obsidian" || true
|
||||
sleep 2
|
||||
|
||||
# 7. Restart Obsidian via systemd
|
||||
sudo systemctl restart obsidian.service 2>/dev/null || {
|
||||
echo "⚠️ systemctl restart failed, starting manual"
|
||||
DISPLAY=:99 /home/intense/.local/bin/obsidian --no-sandbox /workspace/second-brain/ > /dev/null 2>&1 &
|
||||
}
|
||||
|
||||
echo "✓ Obsidian restarted"
|
||||
|
||||
# 8. Wait for Obsidian to fully start
|
||||
echo "Waiting for Obsidian to load plugin (30 seconds)..."
|
||||
for i in {1..30}; do
|
||||
if netstat -tlnp 2>/dev/null | grep -q 27123 || ss -tlnp 2>/dev/null | grep -q 27123; then
|
||||
echo "✅ Plugin loaded! API listening on port 27123"
|
||||
break
|
||||
fi
|
||||
echo -n "."
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# 9. Test MCP connection
|
||||
echo ""
|
||||
echo "Testing MCP connection..."
|
||||
if timeout 5 /workspace/second-brain/start-mcp.sh 2>&1 | grep -q "Obsidian Local REST API is reachable"; then
|
||||
echo "✅ SUCCESS! MCP server can connect to Local REST API"
|
||||
echo ""
|
||||
echo "Next: Your vault is ready for MCP integration!"
|
||||
else
|
||||
echo "⚠️ Plugin may not have started yet. Wait a few more seconds and try:"
|
||||
echo " cd /workspace/second-brain && ./start-mcp.sh"
|
||||
fi
|
||||
Reference in New Issue
Block a user