Skip to content

Commit 1af2d08

Browse files
committed
run_qemu.sh: new postinst_append_if_not_found()
This de-duplication allows inserting "generatedfrom" comments and timestamps. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 2aabce9 commit 1af2d08

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

run_qemu.sh

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,14 +1206,7 @@ check_ndctl_dir()
12061206

12071207
prepare_ndctl_build()
12081208
{
1209-
local postinst=mkosi.postinst
1210-
# Until mkosi v18 (commit a28c268996fa), only one postinst script is
1211-
# supported. So, we concatenate. One drawback: you must manually delete
1212-
# qbuild/mkosi.postinst when changing this code below.
1213-
if test -e "$postinst" && grep -q 9b626c647037bc8a "$postinst"; then
1214-
return
1215-
fi
1216-
cat <<- 'EOF' >> "$postinst"
1209+
cat <<- 'EOF' | postinst_append_if_not_found 9b626c647037bc8a
12171210
#!/bin/sh
12181211
# v14: 'systemd-nspawn"; v15: "mkosi"
12191212
printf 'container=%s\n' "$container"
@@ -1227,24 +1220,35 @@ prepare_ndctl_build()
12271220
mkosi-chroot /root/reinstall_ndctl.sh
12281221
fi
12291222
EOF
1230-
chmod +x "$postinst"
12311223
}
12321224

12331225
prepare_shadow_autologin()
12341226
{
1235-
local postinst=mkosi.postinst
1236-
# Until mkosi v18 (commit a28c268996fa), only one postinst script is
1237-
# supported. So, we concatenate. One drawback: you must manually delete
1238-
# qbuild/mkosi.postinst when changing this code below.
1239-
if test -e "$postinst" && grep -q shadow_autologin.sh "$postinst"; then
1240-
return 0
1241-
fi
1242-
cat <<- EOF >> "$postinst"
1227+
cat <<- EOF | postinst_append_if_not_found shadow_autologin.sh
12431228
#!/bin/sh
12441229
trusted_console=$console mkosi-chroot /root/rq/shadow_autologin.sh
12451230
EOF
1246-
chmod +x "$postinst"
1231+
}
12471232

1233+
# Append stdin to the mkosi.postinst script if the $1 argument
1234+
# "watermark" is not already found there. Otherwise discard stdin.
1235+
# WARNING: this function adds comments with a '# ' prefix.
1236+
postinst_append_if_not_found()
1237+
{
1238+
local watermark="$1"
1239+
local _outputf=mkosi.postinst
1240+
# Until mkosi v18 (commit a28c268996fa), only one postinst script is
1241+
# supported. So, we concatenate. One drawback: you must manually delete
1242+
# qbuild/mkosi.postinst when changing run_qemu.sh
1243+
if test -e "$_outputf" && grep -q -e "$watermark" "$_outputf"; then
1244+
cat >/dev/null
1245+
return
1246+
fi
1247+
{ cat
1248+
generatedfrom_header "postinst_append_if_not_found $watermark"
1249+
printf '### -----------------------\n\n'
1250+
} >> "$_outputf"
1251+
chmod +x "$_outputf"
12481252
}
12491253

12501254
setup_gcp_tweaks()

0 commit comments

Comments
 (0)