@@ -13,7 +13,6 @@ This script installs a Grml system (either a running system or ISO[s]) to a USB
1313"""
1414
1515import argparse
16- import fileinput
1716import functools
1817import glob
1918import logging
@@ -1322,22 +1321,27 @@ def handle_grub_config(
13221321
13231322 shortname = get_shortname (grml_flavour )
13241323 for filename in glob .glob (grub_target + "*.cfg" ):
1325- for line in fileinput .input (filename , inplace = True ):
1326- line = line .rstrip ("\r \n " )
1327- if option_re .search (line ):
1328- line = bootid_re .sub ("" , line )
1329- if shortname in filename :
1330- line = live_media_path_re .sub ("" , line )
1331- line = line .rstrip () + f" live-media-path=/live/{ grml_flavour } / "
1332- if bootoptions .strip ():
1333- line = line .replace (f" { bootoptions .strip ()} " , " " )
1334- if line .endswith (bootoptions ):
1335- line = line [: - len (bootoptions )]
1336- line = line .rstrip () + f" bootid={ bootid } { bootoptions } "
1337- for regex in remove_regexes :
1338- line = regex .sub (" " , line )
1339- print (line )
1340- fileinput .close ()
1324+ new_lines = []
1325+ with open (filename , "r+" ) as fh :
1326+ for line in fh .read ().split ("\n " ):
1327+ line = line .rstrip ("\r \n " )
1328+ if option_re .search (line ):
1329+ line = bootid_re .sub ("" , line )
1330+ if shortname in filename :
1331+ line = live_media_path_re .sub ("" , line )
1332+ line = line .rstrip () + f" live-media-path=/live/{ grml_flavour } / "
1333+ if bootoptions .strip ():
1334+ line = line .replace (f" { bootoptions .strip ()} " , " " )
1335+ if line .endswith (bootoptions ):
1336+ line = line [: - len (bootoptions )]
1337+ line = line .rstrip () + f" bootid={ bootid } { bootoptions } "
1338+ for regex in remove_regexes :
1339+ line = regex .sub (" " , line )
1340+ new_lines .append (line )
1341+
1342+ fh .seek (0 )
1343+ fh .truncate ()
1344+ fh .write ("\n " .join (new_lines ))
13411345
13421346
13431347def initial_syslinux_config (target : str | Path ) -> None :
0 commit comments