From 0074de5f6eccb75dad814527813eba3524bb22e0 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 1 Sep 2025 18:41:24 +0100 Subject: [PATCH] builder, sysprep: Use quoted string literals in a few places This change was automated using the script in: https://github.com/libguestfs/libguestfs/commit/02b64d5cec1ac0a6f7627d5489996de4474a67f6 However I manually only picked a few of the changes suggested by the script. (cherry picked from commit 624df48b3d14d2e5420d758a425bcae509cfe318) --- builder/templates/make-template.ml | 62 ++++++++++++++--------------- sysprep/sysprep_operation_script.ml | 5 ++- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/builder/templates/make-template.ml b/builder/templates/make-template.ml index 73a55bd45..515c3da8b 100755 --- a/builder/templates/make-template.ml +++ b/builder/templates/make-template.ml @@ -535,8 +535,7 @@ and make_kickstart_common ks_filename os arch = | _ -> bpf "install\n"; ); - bpf "\ -text + bpf {|text reboot lang en_US.UTF-8 keyboard us @@ -544,7 +543,7 @@ network --bootproto dhcp rootpw builder firewall --enabled --ssh timezone --utc America/New_York -"; +|}; (match os with | RHEL (ver, _) when ver <= 4 -> @@ -586,19 +585,19 @@ mouse generic | CentOS ((3|4|5|6) as major, _) | RHEL ((3|4|5|6) as major, _) -> let bootfs = if major <= 5 then "ext2" else "ext4" in let rootfs = if major <= 4 then "ext3" else "ext4" in - bpf "\ + bpf {| zerombr clearpart --all --initlabel part /boot --fstype=%s --size=512 --asprimary part swap --size=1024 --asprimary part / --fstype=%s --size=1024 --grow --asprimary -" bootfs rootfs; +|} bootfs rootfs; | Alma _ | CentOS _ | CentOSStream _ | RHEL _ | Fedora _ -> - bpf "\ + bpf {| zerombr clearpart --all --initlabel --disklabel=gpt autopart --type=plain -"; +|}; | _ -> assert false (* cannot happen, see caller *) ); bpf "\n"; @@ -753,16 +752,16 @@ and make_unattend_iso os arch = * file called \Windows\Panther\Setupact.log (NB: * not \Windows\Setupact.log) *) - fprintf chan " - - - + fprintf chan {| + + + true @@ -772,18 +771,18 @@ and make_unattend_iso os arch = - + 0 true - + 1 Primary 300 - + 2 Primary true @@ -791,7 +790,7 @@ and make_unattend_iso os arch = - + 1 1 @@ -799,7 +798,7 @@ and make_unattend_iso os arch = true - + 2 2 @@ -828,11 +827,11 @@ and make_unattend_iso os arch = - + en-US @@ -841,7 +840,7 @@ and make_unattend_iso os arch = en-US -" +|} arch product_key arch; close_out chan; @@ -1411,14 +1410,13 @@ baseurl=%s enabled=0 gpgcheck=0 keepcache=0 -" major major baseurl major major srpms; +|} major major baseurl major major srpms; (match optional with | None -> () | Some (name, optionalbaseurl, optionalsrpms) -> let lc_name = String.lowercase_ascii name in - bpf "\ - + bpf {| [rhel%d-%s] name=RHEL %d Server %s baseurl=%s @@ -1432,7 +1430,7 @@ baseurl=%s enabled=0 gpgcheck=0 keepcache=0 -" major lc_name major lc_name optionalbaseurl +|} major lc_name major lc_name optionalbaseurl major lc_name major lc_name optionalsrpms ) ) else ( diff --git a/sysprep/sysprep_operation_script.ml b/sysprep/sysprep_operation_script.ml index fff5e4d51..a91cea26b 100644 --- a/sysprep/sysprep_operation_script.ml +++ b/sysprep/sysprep_operation_script.ml @@ -81,7 +81,7 @@ let rec script_perform (g : Guestfs.guestfs) root side_effects = and run_scripts mp scripts = let sh = "/bin/bash" in let cmd = - sprintf "\ + sprintf {| set -e #set -x cleanup () @@ -91,7 +91,8 @@ cleanup () guestunmount %s ||: exit $status } -trap cleanup INT TERM QUIT EXIT ERR\n" +trap cleanup INT TERM QUIT EXIT ERR +|} (Filename.quote mp) ^ String.concat "\n" scripts in let args = [| sh; "-c"; cmd |] in