|
4 | 4 | import logging
|
5 | 5 | import os
|
6 | 6 | import re
|
| 7 | +from enum import Enum |
7 | 8 | import time
|
8 | 9 | from typing import List, Optional, Tuple
|
9 | 10 |
|
|
43 | 44 | cmdline_file = None
|
44 | 45 |
|
45 | 46 |
|
| 47 | +class CpuType(str, Enum): |
| 48 | + PI4 = "Raspberry Pi 4 (BCM2711)" |
| 49 | + PI5 = "Raspberry Pi 5 (BCM2712)" |
| 50 | + Other = "Other" |
| 51 | + |
| 52 | + |
| 53 | +class HostOs(str, Enum): |
| 54 | + Bookworm = "Debian(Raspberry Pi OS?) 12 (Bookworm)" |
| 55 | + Bullseye = "Debian(Raspberry Pi OS?) 11 (Bullseye)" |
| 56 | + Other = "Other" |
| 57 | + |
| 58 | + |
| 59 | +def get_cpu_type() -> CpuType: |
| 60 | + with open("/proc/cpuinfo", "r", encoding="utf-8") as f: |
| 61 | + for line in f: |
| 62 | + if "Raspberry Pi 4" in line: |
| 63 | + return CpuType.PI4 |
| 64 | + if "Raspberry Pi 5" in line: |
| 65 | + return CpuType.PI5 |
| 66 | + return CpuType.Other |
| 67 | + |
| 68 | + |
| 69 | +def get_host_os() -> HostOs: |
| 70 | + os_release = load_file("/etc/os-release") |
| 71 | + if "bookworm" in os_release: |
| 72 | + return HostOs.Bookworm |
| 73 | + if "bullseye" in os_release: |
| 74 | + return HostOs.Bullseye |
| 75 | + return HostOs.Other |
| 76 | + |
| 77 | + |
46 | 78 | # Copyright 2016-2022 Paul Durivage
|
47 | 79 | # Licensed under the Apache License, Version 2.0 (the "License");
|
48 | 80 | # Based on: https://gist.github.com/angstwad/bf22d1822c38a92ec0a9
|
@@ -433,21 +465,34 @@ def main() -> int:
|
433 | 465 | logger.error("Ignoring host computer configuration for now.")
|
434 | 466 | return 0
|
435 | 467 |
|
| 468 | + host_os = get_host_os() |
| 469 | + logger.info(f"Host OS: {host_os}") |
| 470 | + host_cpu = get_cpu_type() |
| 471 | + logger.info(f"Host CPU: {host_cpu}") |
| 472 | + |
436 | 473 | # TODO: parse tag as semver and check before applying patches
|
437 | 474 | patches_to_apply = [
|
438 | 475 | update_startup,
|
439 |
| - update_cgroups, |
440 |
| - update_dwc2, |
441 |
| - update_navigator_overlays, |
442 | 476 | ensure_user_data_structure_is_in_place,
|
443 | 477 | ensure_nginx_permissions,
|
444 | 478 | create_dns_conf_host_link,
|
445 | 479 | ]
|
446 | 480 |
|
447 |
| - logger.info( |
448 |
| - "The following patches will be applied if needed:", |
449 |
| - [patch_to_apply.__name__ for patch_to_apply in patches_to_apply], |
450 |
| - ) |
| 481 | + # this will always be pi4 as pi5 is not supported |
| 482 | + if host_os == HostOs.Bullseye: |
| 483 | + patches_to_apply.extend([update_navigator_overlays]) |
| 484 | + |
| 485 | + if host_cpu == CpuType.PI4 or CpuType.PI5: |
| 486 | + patches_to_apply.extend( |
| 487 | + [ |
| 488 | + update_cgroups, |
| 489 | + update_dwc2, |
| 490 | + ] |
| 491 | + ) |
| 492 | + |
| 493 | + logger.info("The following patches will be applied if needed:") |
| 494 | + for patch in patches_to_apply: |
| 495 | + logger.info(patch.__name__) |
451 | 496 |
|
452 | 497 | patches_requiring_restart = [patch.__name__ for patch in patches_to_apply if patch()]
|
453 | 498 | if patches_requiring_restart:
|
|
0 commit comments