diff --git a/README.md b/README.md index ae270b8..f506b46 100644 --- a/README.md +++ b/README.md @@ -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" @@ -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 ``` diff --git a/sync-ssh-keys.sh b/sync-ssh-keys.sh index 29d02bf..c3c9a26 100644 --- a/sync-ssh-keys.sh +++ b/sync-ssh-keys.sh @@ -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)" @@ -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')" diff --git a/users.conf b/users.conf index d803988..cf6703c 100644 --- a/users.conf +++ b/users.conf @@ -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"