91 lines
2.4 KiB
Bash
Executable File
91 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Install Local REST API plugin headless (no GUI needed)
|
|
# This manually installs the plugin files and generates API key
|
|
|
|
set -e
|
|
|
|
VAULT_PATH="/workspace/second-brain"
|
|
PLUGIN_DIR="$VAULT_PATH/.obsidian/plugins/obsidian-local-rest-api"
|
|
API_KEY=$(openssl rand -hex 32)
|
|
|
|
echo "📡 Installing Local REST API plugin (headless)..."
|
|
|
|
# Create plugin directory
|
|
mkdir -p "$PLUGIN_DIR"
|
|
|
|
# Download latest plugin release from GitHub
|
|
RELEASE_URL="https://github.com/coddingtonbear/obsidian-local-rest-api/releases/latest/download"
|
|
|
|
echo "Downloading plugin files..."
|
|
cd "$PLUGIN_DIR"
|
|
|
|
# Download manifest
|
|
curl -s -L "$RELEASE_URL/manifest.json" -o manifest.json
|
|
echo "✓ manifest.json"
|
|
|
|
# Download main.js
|
|
curl -s -L "$RELEASE_URL/main.js" -o main.js
|
|
echo "✓ main.js"
|
|
|
|
# Download styles.css (if available)
|
|
curl -s -L "$RELEASE_URL/styles.css" -o styles.css 2>/dev/null || echo "✓ styles.css (optional, skipped)"
|
|
|
|
# Create data.json with plugin settings and API key
|
|
cat > data.json << EOF
|
|
{
|
|
"api_key": "$API_KEY",
|
|
"allow_origins": "*",
|
|
"port": 27123
|
|
}
|
|
EOF
|
|
echo "✓ data.json (with API key)"
|
|
|
|
# Enable plugin in Obsidian config
|
|
COMMUNITY_PLUGINS_FILE="$VAULT_PATH/.obsidian/community-plugins.json"
|
|
if [ ! -f "$COMMUNITY_PLUGINS_FILE" ]; then
|
|
echo '[]' > "$COMMUNITY_PLUGINS_FILE"
|
|
fi
|
|
|
|
# Add plugin to enabled list
|
|
python3 << PYTHON
|
|
import json
|
|
with open('$COMMUNITY_PLUGINS_FILE', 'r') as f:
|
|
plugins = json.load(f)
|
|
if 'obsidian-local-rest-api' not in plugins:
|
|
plugins.append('obsidian-local-rest-api')
|
|
with open('$COMMUNITY_PLUGINS_FILE', 'w') as f:
|
|
json.dump(plugins, f, indent=2)
|
|
print("✓ Plugin enabled in community-plugins.json")
|
|
PYTHON
|
|
|
|
# Update .env with API key
|
|
ENV_FILE="$VAULT_PATH/.env"
|
|
if [ -f "$ENV_FILE" ]; then
|
|
# Replace existing key
|
|
sed -i "s/^OBSIDIAN_API_KEY=.*/OBSIDIAN_API_KEY=$API_KEY/" "$ENV_FILE"
|
|
else
|
|
# Create new .env
|
|
cat > "$ENV_FILE" << ENVEOF
|
|
OBSIDIAN_API_KEY=$API_KEY
|
|
OBSIDIAN_BASE_URL=http://127.0.0.1:27123
|
|
OBSIDIAN_VERIFY_SSL=false
|
|
OBSIDIAN_ENABLE_CACHE=true
|
|
OBSIDIAN_CACHE_REFRESH_INTERVAL_MIN=10
|
|
MCP_TRANSPORT_TYPE=stdio
|
|
MCP_LOG_LEVEL=info
|
|
ENVEOF
|
|
fi
|
|
echo "✓ .env updated with API key"
|
|
|
|
echo ""
|
|
echo "✅ Local REST API plugin installed!"
|
|
echo ""
|
|
echo "API Key: $API_KEY"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Restart Obsidian: sudo systemctl restart obsidian.service"
|
|
echo "2. Test MCP: /workspace/second-brain/start-mcp.sh"
|
|
echo ""
|
|
echo "Verify plugin:"
|
|
echo " cat $VAULT_PATH/.obsidian/community-plugins.json"
|