From 2ee12b7cd9583216fa61e6fd1337146b1d5633e2 Mon Sep 17 00:00:00 2001 From: Patrck Lewis <4015312+locus313@users.noreply.github.com> Date: Wed, 25 Jun 2025 18:24:20 -0700 Subject: [PATCH 1/2] Add option to load github token from conf file --- README.md | 7 ++++++- sync-ssh-keys.sh | 5 +++++ users.conf | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) 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..e351c81 100644 --- a/sync-ssh-keys.sh +++ b/sync-ssh-keys.sh @@ -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" From 445553f998dbf42c1657b849bf9ae21580bfe4cf Mon Sep 17 00:00:00 2001 From: Patrck Lewis <4015312+locus313@users.noreply.github.com> Date: Wed, 25 Jun 2025 18:25:16 -0700 Subject: [PATCH 2/2] bumb version --- sync-ssh-keys.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync-ssh-keys.sh b/sync-ssh-keys.sh index e351c81..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)"