Skip to content

Commit

Permalink
python: setup: Use Fstab() in more places
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Chancellor <[email protected]>
  • Loading branch information
nathanchance committed Dec 4, 2024
1 parent 80d29b1 commit 2e8d6c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions python/lib/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,18 +487,16 @@ def setup_mnt_ssd(user_name):
(mnt_point := Path('/mnt/ssd')).mkdir(exist_ok=True, parents=True)
chown(user_name, mnt_point)

fstab, fstab_text = lib.utils.path_and_text('/etc/fstab')
if str(mnt_point) not in fstab_text:
if mnt_point not in (fstab := Fstab()):
partuuid = subprocess.run(['blkid', '-o', 'value', '-s', 'PARTUUID', ssd_partition],
capture_output=True,
check=True,
text=True).stdout.strip()

fstab_line = f"PARTUUID={partuuid}\t{mnt_point}\text4\tdefaults,noatime\t0\t1\n"
fstab[mnt_point] = FstabItem(f"PARTUUID={partuuid}", mnt_point, 'ext4',
'defaults,noatime', '0', '1')
fstab.write()

fstab.write_text(fstab_text + fstab_line, encoding='utf-8')

subprocess.run(['systemctl', 'daemon-reload'], check=True)
subprocess.run(['mount', '-a'], check=True)

if shutil.which('docker'):
Expand Down
8 changes: 4 additions & 4 deletions python/setup/equinix.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def partition_drive(drive_path, mountpoint, username):
check=True,
text=True).stdout.strip()

fstab, fstab_txt = lib.utils.path_and_text('/etc/fstab')
fstab_line = f"UUID={vol_uuid}\t{mountpoint}\text4\tnoatime\t0\t2\n"
fstab.write_text(fstab_txt + fstab_line, encoding='utf-8')
subprocess.run(['systemctl', 'daemon-reload'], check=True)
fstab = lib.setup.Fstab()
fstab[mountpoint] = lib.setup.FstabItem(f"UUID={vol_uuid}", mountpoint, 'ext4', 'noatime', '0',
'2')
fstab.write()

mountpoint.mkdir(exist_ok=True, parents=True)
subprocess.run(['mount', '-a'], check=True)
Expand Down

0 comments on commit 2e8d6c6

Please sign in to comment.