feat: generate gitconfig on the fly before creating container
This commit is contained in:
parent
a179a3ad23
commit
d7c7686a9e
@ -67,10 +67,33 @@ case "$SSH_ORIGINAL_COMMAND" in
|
|||||||
;;
|
;;
|
||||||
esac
|
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
|
# Function to start the container if not running
|
||||||
start_container_if_needed() {
|
start_container_if_needed() {
|
||||||
if ! podman container exists "$WORKSPACE"; then
|
if ! podman container exists "$WORKSPACE"; then
|
||||||
log "🚀 Creating container $WORKSPACE..."
|
log "🚀 Creating container $WORKSPACE..."
|
||||||
|
generate_gitconfig
|
||||||
podman run -dit \
|
podman run -dit \
|
||||||
--userns=keep-id \
|
--userns=keep-id \
|
||||||
--name "$WORKSPACE" \
|
--name "$WORKSPACE" \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user