summaryrefslogtreecommitdiff
path: root/.config/pacman/bin/linux-lts-versioned-bin-hook
blob: bdda6d5e2e6de8065de9e7f6f8f212b1b1111e9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python

import sys, os, re

boot_dir = '/boot'

lts_vm_files = list(
    filter(
        re.compile(r'vmlinuz-([\d\.\-]+)-lts$').match,
        os.listdir(boot_dir)
    )
)

if not lts_vm_files:
    print(f'No versioned kernel files found in {boot_dir}')
    sys.exit(1)

highest_lts_version_file = lts_vm_files[-1]
version_name = re.search(r'vmlinuz-([\d\.\-]+)-lts$', highest_lts_version_file).group(1)

symlink_map = {
    f'{boot_dir}/initramfs-{version_name}-lts.img': f'{boot_dir}/initramfs-linux-lts.img',
    f'{boot_dir}/initramfs-{version_name}-lts-fallback.img': f'{boot_dir}/initramfs-linux-lts-fallback.img',
    f'{boot_dir}/vmlinuz-{version_name}-lts': f'{boot_dir}/vmlinuz-linux-lts',
}
for src, dst in symlink_map.items():
    os.path.islink(dst) and os.unlink(dst)
    os.symlink(src, dst)

sys.exit(0)