Solved fstab bug

This commit is contained in:
2025-04-02 17:10:39 +02:00
parent 67e09d3b0f
commit c1020e964b
2 changed files with 18 additions and 8 deletions

View File

@@ -34,7 +34,7 @@ pkgmgr install setup-hibernate
Run the script as root: Run the script as root:
```bash ```bash
sudo ./hibernate_setup.py [OPTIONS] sudo ./main.py [OPTIONS]
``` ```
### Options ### Options
@@ -51,19 +51,19 @@ sudo ./hibernate_setup.py [OPTIONS]
Create a 40GB swapfile and configure hibernation interactively: Create a 40GB swapfile and configure hibernation interactively:
```bash ```bash
sudo ./hibernate_setup.py --create-swapfile --swap-size 40 sudo ./main.py --create-swapfile --swap-size 40
``` ```
Preview what would happen without actually doing anything: Preview what would happen without actually doing anything:
```bash ```bash
sudo ./hibernate_setup.py --create-swapfile --swap-size 40 --preview sudo ./main.py --create-swapfile --swap-size 40 --preview
``` ```
Non-interactive, suitable for automation: Non-interactive, suitable for automation:
```bash ```bash
sudo ./hibernate_setup.py --create-swapfile --swap-size 40 --non-interactive sudo ./main.py --create-swapfile --swap-size 40 --non-interactive
``` ```
--- ---

18
main.py
View File

@@ -92,13 +92,23 @@ def update_grub(uuid, offset):
new_lines = lines[:] new_lines = lines[:]
for i, line in enumerate(new_lines): for i, line in enumerate(new_lines):
if line.startswith("GRUB_CMDLINE_LINUX_DEFAULT"): if line.startswith("GRUB_CMDLINE_LINUX_DEFAULT"):
# Remove existing resume and resume_offset entries
line = re.sub(r'resume=UUID=\S+', '', line) line = re.sub(r'resume=UUID=\S+', '', line)
line = re.sub(r'resume_offset=\S+', '', line) line = re.sub(r'resume_offset=\S+', '', line)
new = f'resume=UUID={uuid} resume_offset={offset}' line = re.sub(r'\s+', ' ', line) # Clean up extra spaces
if '"' in line:
new_lines[i] = re.sub(r'"$', f' {new}"', line) # Safely inject new resume info inside quotes
match = re.match(r'^(GRUB_CMDLINE_LINUX_DEFAULT=)(["\'])(.*?)(["\'])$', line.strip())
if match:
prefix, quote, content, _ = match.groups()
content = content.strip()
if not content.endswith(' '):
content += ' '
content += f'resume=UUID={uuid} resume_offset={offset}'
new_lines[i] = f'{prefix}{quote}{content}{quote}\n'
else: else:
new_lines[i] = line.strip() + f' {new}\n' # If the line format is unexpected, append the resume parameters at the end
new_lines[i] = line.strip() + f' resume=UUID={uuid} resume_offset={offset}\n'
break break
if confirm_file_change(GRUB_CONF, new_lines): if confirm_file_change(GRUB_CONF, new_lines):