22import json
33import os
44from pathlib import Path
5+ import re
56import shutil
67import subprocess
78
@@ -31,6 +32,39 @@ def clone_repositories(wia_branch, wvm_branch):
3132 for repo in repos :
3233 subprocess .run (f"git clone { repo ['branch' ]} { repo ['url' ]} { repo ['dest' ]} " , shell = True , check = True )
3334
35+ def extract_stage_from_branch (wia_branch ):
36+ """
37+ Extracts the stage (rc1, beta1, etc.) from the branch name if present.
38+
39+ Args:
40+ wia_branch (str): Branch name of the wazuh-installation-assistant repository
41+
42+ Returns:
43+ str: Stage name (e.g., "rc1", "beta1") or empty string if no stage found
44+ """
45+ # Pattern to match stage indicators: -rc1, -beta1, -rc2, etc.
46+ pattern = r'-(rc\d+|beta\d+|alpha\d+)'
47+ match = re .search (pattern , wia_branch , re .IGNORECASE )
48+
49+ if match :
50+ return match .group (1 )
51+ return ""
52+
53+ def update_wazuh_install_stage (wazuh_install_path , stage ):
54+ """
55+ Updates the last_stage variable in wazuh-install.sh file.
56+
57+ Args:
58+ wazuh_install_path (str): Path to the wazuh-install.sh file
59+ stage (str): Stage name (e.g., "rc1", "beta1")
60+ """
61+ if not stage or not os .path .exists (wazuh_install_path ):
62+ return
63+
64+ # Use sed to replace last_stage="" with last_stage="<stage>"
65+ sed_command = f'sudo sed -i \' s/last_stage=""/last_stage="{ stage } "/g\' { wazuh_install_path } '
66+ subprocess .run (sed_command , shell = True , check = True )
67+
3468def build_wazuh_install (repo_path , wia_branch ):
3569 """
3670 Builds the wazuh-install.sh script and moves it to /tmp
@@ -45,15 +79,22 @@ def build_wazuh_install(repo_path, wia_branch):
4579 os .chdir (repo_path )
4680 subprocess .run (f"git checkout { wia_branch } " , shell = True , check = True )
4781 subprocess .run ("sudo bash builder.sh -i" , shell = True , check = True )
82+
4883 if os .path .exists ("wazuh-install.sh" ):
4984 subprocess .run ("sudo mv wazuh-install.sh /tmp/wazuh-install.sh" , shell = True , check = True )
5085
86+ # Check if wia_branch contains a stage indicator and update the wazuh-install.sh file
87+ stage = extract_stage_from_branch (wia_branch )
88+ if stage :
89+ update_wazuh_install_stage ("/tmp/wazuh-install.sh" , stage )
90+
5191
5292def run_provision_script (wvm_branch , repository , debug ):
5393 """
5494 Runs the provision.sh script
5595
5696 Args:
97+ wvm_branch (str): Branch of the wazuh-virtual-machines repository
5798 repository (str): Production or development repository
5899 debug (str): Debug mode
59100 """
0 commit comments