From bb602d8e845bafa90c043f082f3ee35571679b49 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20OLIVIER?= <cedric3.olivier@orange.com>
Date: Fri, 18 Apr 2025 12:19:20 +0200
Subject: [PATCH] fix: allow installation of missing package awk

---
 templates/gitlab-ci-docker.yml | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/templates/gitlab-ci-docker.yml b/templates/gitlab-ci-docker.yml
index 2458cfa..17b6e7f 100644
--- a/templates/gitlab-ci-docker.yml
+++ b/templates/gitlab-ci-docker.yml
@@ -352,6 +352,30 @@ stages:
     fi
   }
 
+  function maybe_install_awk() {
+    if ! command -v awk > /dev/null
+    then
+      if command -v apt-get > /dev/null
+      then
+        # Debian
+        apt-get update
+        apt-get install --no-install-recommends --yes --quiet awk
+      elif command -v apk > /dev/null
+      then
+        # Alpine
+        apk add --no-cache gawk
+      elif command -v dnf > /dev/null
+      then 
+        # Fedora
+        dnf install -y -q awk
+      else
+        log_error "... didn't find any supported package manager to install awk"
+        exit 1
+      fi
+    fi
+  }
+
+
   function unscope_variables() {
     _scoped_vars=$(env | awk -F '=' "/^scoped__[a-zA-Z0-9_]+=/ {print \$1}" | sort)
     if [[ -z "$_scoped_vars" ]]; then return; fi
@@ -684,6 +708,7 @@ stages:
   }
 
   function init_workspace() {
+    maybe_install_awk
     install_custom_ca_certs
     unscope_variables
     eval_all_secrets
-- 
GitLab