Created
October 15, 2020 05:02
-
-
Save lauhayden/4ab710d445a7ab80708297dd81dac7ed to your computer and use it in GitHub Desktop.
Kernel update script for Pop!_OS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
"""Script to copy initrd.img and vmlinuz.efi from /boot/ to /boot/efi where | |
systemd-boot looks for them. | |
""" | |
import glob | |
import os | |
import shutil | |
import sys | |
INITRD_GLOB = "/boot/initrd.img-*" | |
VMLINUZ_GLOB = "/boot/vmlinuz-*" | |
EFI_INITRD_PATH = "/boot/efi/EFI/Pop_OS-mainline/initrd.img" | |
EFI_VMLINUZ_PATH = "/boot/efi/EFI/Pop_OS-mainline/vmlinuz.efi" | |
def find_newest(l): | |
newest = (0, 0, 0) | |
newest_path = "" | |
for entry in l: | |
version = tuple(map(int, entry.split("-")[1].split("."))) | |
if version > newest: | |
newest = version | |
newest_path = entry | |
return newest, newest_path | |
if os.getuid() != 0: | |
print("Error: need root permissions!") | |
sys.exit(1) | |
initrds = glob.glob(INITRD_GLOB) | |
vmlinuzs = glob.glob(VMLINUZ_GLOB) | |
if len(initrds) != len(vmlinuzs): | |
print("Error: different number of initrd.img and vmlinuz found!") | |
sys.exit(1) | |
print(f"Found {len(initrds)} kernel versions.") | |
vi, pi = find_newest(initrds) | |
vv, pv = find_newest(vmlinuzs) | |
if vi != vv: | |
print(f"Error: Newest initrd.img version ({vi}) does not match vmlinuz version ({vv})!") | |
sys.exit(1) | |
print(f"Newest kernel version: {'.'.join(map(str, vi))}") | |
print(f"Copying {pi} -> {EFI_INITRD_PATH}...") | |
shutil.copyfile(pi, EFI_INITRD_PATH) | |
print(f"Copying {pv} -> {EFI_VMLINUZ_PATH}...") | |
shutil.copyfile(pv, EFI_VMLINUZ_PATH) | |
print("Done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment