Skip to content

Commit

Permalink
more review suggestions: use .format, add header
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhudson committed Jul 18, 2023
1 parent 6d67a2d commit c991568
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions subiquity/server/controllers/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
run_in_thread,
)
from subiquitycore.context import with_context
from subiquitycore.file_util import write_file, generate_config_yaml
from subiquitycore.file_util import (
write_file,
generate_config_yaml,
generate_timestamped_header,
)
from subiquitycore.utils import arun_command, log_process_streams

from subiquity.common.errorreport import ErrorReportKind
Expand Down Expand Up @@ -395,8 +399,10 @@ async def create_rp_boot_entry(self, context, rp):
['lsblk', '-n', '-o', 'UUID', rp.path],
capture=True)
uuid = cp.stdout.decode('ascii').strip()
conf = grub_reset_conf.replace("#UUID#", uuid)
conf = conf.replace("#PARTITION#", str(rp.number))
conf = grub_reset_conf.format(
HEADER=generate_timestamped_header(),
PARTITION=rp.number,
UUID=uuid)
with open(self.tpath('etc/grub.d/99_reset'), 'w') as fp:
os.chmod(fp.fileno(), 0o755)
fp.write(conf)
Expand Down Expand Up @@ -655,12 +661,15 @@ async def stop_unattended_upgrades(self):
"""

grub_reset_conf = """\
#!/bin/bash -e
#!/bin/sh
{HEADER}
set -e
cat << EOF
menuentry "Restore Ubuntu to factory state" {
search --no-floppy --hint '(hd0,#PARTITION#)' --set --fs-uuid #UUID#
linux /casper/vmlinuz uuid=#UUID# nopersistent
search --no-floppy --hint '(hd0,{PARTITION})' --set --fs-uuid {UUID}
linux /casper/vmlinuz uuid={UUID} nopersistent
initrd /casper/initrd
}
EOF
Expand Down

0 comments on commit c991568

Please sign in to comment.