diff --git a/ssh_router.sh b/ssh_router.sh index 455c697..810454a 100755 --- a/ssh_router.sh +++ b/ssh_router.sh @@ -67,10 +67,33 @@ case "$SSH_ORIGINAL_COMMAND" in ;; esac +generate_gitconfig() { + access="$HOME/access.yml" + template="$HOME/gitconfig.template" + user_dir="$HOME/secrets/$PERSON" + + # Extract user fields from YAML + name=$(yq ".\"$PERSON\".name" "$access") + email=$(yq ".\"$PERSON\".email" "$access") + + # Ensure fields are not empty + if [[ -z "$name" || -z "$email" ]]; then + echo "❌ Error: User '$PERSON' not found or missing name/email in $access" + exit 1 + fi + + # Generate .gitconfig + env GIT_NAME="$name" GIT_EMAIL="$email" \ + envsubst <"$template" >"$user_dir/gitconfig" + + echo "✅ .gitconfig created at $user_dir/gitconfig" +} + # Function to start the container if not running start_container_if_needed() { if ! podman container exists "$WORKSPACE"; then log "🚀 Creating container $WORKSPACE..." + generate_gitconfig podman run -dit \ --userns=keep-id \ --name "$WORKSPACE" \