feat: generate gitconfig on the fly before creating container

This commit is contained in:
Pallav Vasa 2025-05-17 09:04:26 +00:00
parent a179a3ad23
commit d7c7686a9e

View File

@ -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" \