44import collections
55import os
66import re
7+ import textwrap
78import xml .etree .ElementTree as ET
89
910import ssg .ansible
@@ -206,8 +207,10 @@ def load_all_remediations(self, benchmark):
206207 def generate_profile_remediation_script (self , profile_el ):
207208 if self .language == "ansible" :
208209 output = self .create_output_ansible (profile_el )
209- else :
210+ elif self . language in ( "bash" , "hummingbird" ) :
210211 output = self .create_output_linear (profile_el )
212+ else :
213+ raise ValueError ("Unknown language %s" % self .language )
211214 file_path = self .get_output_file_path (profile_el )
212215 with open (file_path , "wb" ) as f :
213216 f .write (output .encode ("utf-8" ))
@@ -261,6 +264,18 @@ def create_output_linear(self, profile):
261264 header = self .create_header (profile )
262265 output .append (header )
263266 total = len (selected_rules )
267+ if self .language == "hummingbird" :
268+ newroot_assign = textwrap .dedent (
269+ """
270+ # The first argument is the root directory of the system
271+ NEWROOT="$1"
272+ if [[ -z "$NEWROOT" ]] ; then
273+ echo "Missing required NEWROOT argument" >&2
274+ exit 1
275+ fi
276+ """
277+ )
278+ output .append (newroot_assign )
264279 current = 1
265280 for rule_id in self .remediations :
266281 if rule_id not in selected_rules :
@@ -272,6 +287,8 @@ def create_output_linear(self, profile):
272287 elif self .language == "hummingbird" :
273288 rule_remediation = self .generate_hummingbird_rule_remediation (
274289 rule_id , refinements )
290+ else :
291+ raise ValueError ("Unknown language %s" % self .language )
275292 output .append (rule_remediation )
276293 current += 1
277294 return "" .join (output )
@@ -293,7 +310,7 @@ def create_header(self, profile):
293310 elif self .language == "hummingbird" :
294311 shebang_with_newline = "#!/usr/bin/env bash\n "
295312 remediation_type = "Bash Remediation Script for building Project Hummingbird container images"
296- how_to_apply = "# $ ./ remediation-script.sh\n "
313+ how_to_apply = "# RUN remediation-script.sh ${NEWROOT} \n "
297314 profile_title = profile .find ("./{%s}title" % XCCDF12_NS ).text
298315 description = profile .find ("./{%s}description" % XCCDF12_NS ).text
299316 commented_profile_description = comment (description )
0 commit comments