fix: add login.sh helper and graceful not-logged-in handling in entrypoint

This commit is contained in:
hermes
2026-04-23 14:32:50 +00:00
parent b8ac794479
commit 8de1a164e1
3 changed files with 75 additions and 36 deletions
+27 -15
View File
@@ -3,25 +3,37 @@ set -e
echo "Starting Obsidian Headless Sync Server..."
# Ensure we are in the vault directory
cd /vault
# 1. Initial Login
# Note: In a fully automated environment, the user will need to provide
# a session token or use 'ob login' interactively once.
# For this container, we assume the user has handled login or we use an environment variable.
if [ -z "$OBSIDIAN_SYNC_TOKEN" ]; then
echo "Warning: OBSIDIAN_SYNC_TOKEN not provided. You may need to run 'docker exec -it <container> ob login' manually once."
else
# Assuming the CLI supports token-based login or we inject the session
echo "Using provided sync token for login..."
# ob login --token $OBSIDIAN_SYNC_TOKEN
# Check if already logged in by testing ob login --status (or equivalent)
echo "Checking login status..."
LOGIN_STATUS=$(ob login 2>&1 || true)
if echo "$LOGIN_STATUS" | grep -qi "not logged in\|unauthorized\|login required\|not authenticated"; then
echo ""
echo "============================================================"
echo " NOT LOGGED IN — Action required!"
echo ""
echo " Run the following command from your host to authenticate:"
echo ""
echo " ./login.sh"
echo ""
echo " Then restart this container:"
echo ""
echo " docker-compose restart"
echo "============================================================"
echo ""
echo "Waiting for login... (sleeping to keep container alive)"
sleep infinity
exit 0
fi
# 2. Setup Sync for the specified vault
echo "Setting up sync for vault: $OBSIDIAN_VAULT_NAME"
ob sync-setup --vault "$OBSIDIAN_VAULT_NAME" --password "$OBSIDIAN_SYNC_PASSWORD" --device-name "$OBSIDIAN_DEVICE_NAME" --path /vault
echo "Login confirmed. Setting up sync for vault: $OBSIDIAN_VAULT_NAME"
ob sync-setup \
--vault "$OBSIDIAN_VAULT_NAME" \
--password "$OBSIDIAN_SYNC_PASSWORD" \
--device-name "$OBSIDIAN_DEVICE_NAME" \
--path /vault
# 3. Start Continuous Sync
echo "Entering continuous sync mode..."
exec ob sync --continuous