@@ -1206,14 +1206,7 @@ check_ndctl_dir()
1206
1206
1207
1207
prepare_ndctl_build ()
1208
1208
{
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
1217
1210
#!/bin/sh
1218
1211
# v14: 'systemd-nspawn"; v15: "mkosi"
1219
1212
printf 'container=%s\n' "$container"
@@ -1227,24 +1220,35 @@ prepare_ndctl_build()
1227
1220
mkosi-chroot /root/reinstall_ndctl.sh
1228
1221
fi
1229
1222
EOF
1230
- chmod +x " $postinst "
1231
1223
}
1232
1224
1233
1225
prepare_shadow_autologin ()
1234
1226
{
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
1243
1228
#!/bin/sh
1244
1229
trusted_console=$console mkosi-chroot /root/rq/shadow_autologin.sh
1245
1230
EOF
1246
- chmod +x " $postinst "
1231
+ }
1247
1232
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 "
1248
1252
}
1249
1253
1250
1254
setup_gcp_tweaks ()
0 commit comments