Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ Each entry uses the format:
- **api:** Fetches from a private GitHub repo using the GitHub API (requires `GITHUB_TOKEN` environment variable).
- **ghuser:** Fetches public keys from a GitHub user's profile (provide the GitHub username after the colon).

You can also set your GitHub token in the config file using `CONF_GITHUB_TOKEN`.
If `GITHUB_TOKEN` is not set in the environment, the script will use `CONF_GITHUB_TOKEN` from `users.conf`.

**Example `users.conf`:**
```bash
CONF_GITHUB_TOKEN="your_github_token_here"

declare -A USER_KEYS=(
["ubuntu"]="raw:https://example.com/ssh-keys/ubuntu.authorized_keys"
["devuser"]="api:https://api.github.com/repos/yourorg/ssh-keys/contents/keys/devuser.authorized_keys?ref=main"
Expand All @@ -36,7 +41,7 @@ declare -A USER_KEYS=(
## Usage

1. Edit the `users.conf` file to define users and their key URLs or GitHub usernames.
2. If using the `api` method, export your GitHub token:
2. If using the `api` method, either export your GitHub token or set `CONF_GITHUB_TOKEN` in `users.conf`:
```bash
export GITHUB_TOKEN=your_token_here
```
Expand Down
7 changes: 6 additions & 1 deletion sync-ssh-keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

# shellcheck disable=SC2034 # planned to be used in a future release
SCRIPT_VERSION="0.0.6"
SCRIPT_VERSION="0.0.7"

# === Load user configuration ===
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Expand All @@ -15,6 +15,11 @@ if ! source "$SCRIPT_DIR/users.conf"; then
exit 1
fi

# Load GITHUB_TOKEN from config if set and not already in environment
if [[ -n "${CONF_GITHUB_TOKEN:-}" && -z "${GITHUB_TOKEN:-}" ]]; then
export GITHUB_TOKEN="$CONF_GITHUB_TOKEN"
fi

log_message() {
local TIMESTAMP
TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S')"
Expand Down
3 changes: 3 additions & 0 deletions users.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

CONF_GITHUB_TOKEN="your_github_token_here"

declare -A USER_KEYS=(
["ubuntu"]="raw:https://example.com/ssh-keys/ubuntu.authorized_keys"
["devuser"]="api:https://api.github.com/repos/yourorg/ssh-keys/contents/keys/devuser.authorized_keys?ref=main"
Expand Down