From ca706e7699ba0de89b2668b98a82f8a5a19c67d2 Mon Sep 17 00:00:00 2001 From: Erayd Date: Fri, 13 Apr 2018 12:16:42 +1200 Subject: [PATCH] Better default path handling (#7) * Better handling of default store * Add store name as a settings param --- PROTOCOL.md | 17 ++++++++++------- placeholder.sh | 7 +++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/PROTOCOL.md b/PROTOCOL.md index f62e3ee..5734429 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -63,16 +63,18 @@ Settings are applied using the following priority, highest first: ### Global Settings -| Setting | Description | Default | -| ------- | ---------------------------------------------------- | ------- | -| gpgPath | Optional path to gpg binary | `null` | -| stores | List of password stores with store-specific settings | `null` | +| Setting | Description | Default | +| ------------ | ---------------------------------------------------- | ------- | +| gpgPath | Optional path to gpg binary | `null` | +| defaultStore | Store-specific settings for default store | `{}` | +| stores | List of password stores with store-specific settings | `{}` | ### Store-specific Settings -| Setting | Description | Default | -| ------- | ---------------------------------------------------- | ------- | -| | | | +| Setting | Description | Default | +| ------------ | ---------------------------------------------------- | ------- | +| name | Store name (same as the store key) | | +| path | Path to the password store directory | `""` | ## Actions @@ -99,6 +101,7 @@ is alive, determine the version at startup, and provide per-store defaults.    “version”:    “response”: { "defaultPath": "/path/to/default/store", + "defaultSettings": ,        “storeSettings”: {            “storeName”:        } diff --git a/placeholder.sh b/placeholder.sh index 85d04c9..279ed89 100755 --- a/placeholder.sh +++ b/placeholder.sh @@ -96,6 +96,13 @@ function configure() [ -n "$PASSWORD_STORE_DIR" ] || PASSWORD_STORE_DIR="~/.password-store" OUTPUT="$(jq -n --arg defaultPath "$PASSWORD_STORE_DIR" '.defaultPath = $defaultPath')" + STOREPATH=$(echo "$PASSWORD_STORE_DIR" | sed 's/^~/$HOME/' | envsubst) + if [ -f "$STOREPATH/.browserpass.json" ]; then + OUTPUT=$(jq --arg settings "$(cat "$STOREPATH/.browserpass.json")" '.defaultSettings = $settings' <<< "$OUTPUT") + else + OUTPUT=$(jq '.defaultSettings = ""' <<< "$OUTPUT") + fi + for STORE in "${!STORES[@]}"; do OUTPUT=$(jq --arg store "$STORE" --arg settings "${STORES[$STORE]}" '.storeSettings[$store] = $settings' <<< "$OUTPUT") done