HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //lib/python3.6/site-packages/cloudinit/config/__pycache__/cc_grub_dpkg.cpython-36.pyc
3

\�me��	@s�UdZddlZddlZddlmZddlmZmZddlm	Z	ddl
mZddlm
Z
mZddlmZdd	lmZd
ZddgZd
ddeeeed�ggd�Ze
ee�Zeje�Zdd�Zed�dd�Zeee	edd�dd�Zeed�dd�ZdS)z5Grub Dpkg: Configure grub debconf installation device�N)�dedent)�subp�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�PER_INSTANCE)�ProcessExecutionErrora�Configure which device is used as the target for grub installation. This module
can be enabled/disabled using the ``enabled`` config key in the ``grub_dpkg``
config dict. This module automatically selects a disk using ``grub-probe`` if
no installation device is specified.

The value which is placed into the debconf database is in the format which the
grub postinstall script expects. Normally, this is a /dev/disk/by-id/ value,
but we do fallback to the plain disk name if a by-id name is not present.

If this module is executed inside a container, then the debconf database is
seeded with empty values, and install_devices_empty is set to true.
ZubuntuZdebianZcc_grub_dpkgz	Grub Dpkgz*Configure grub debconf installation deviceaE            grub_dpkg:
              enabled: true
              # BIOS mode (install_devices needs disk)
              grub-pc/install_devices: /dev/sda
              grub-pc/install_devices_empty: false
              # EFI mode (install_devices needs partition)
              grub-efi/install_devices: /dev/sda
            )�id�name�title�description�distrosZ	frequencyZexamplesZactivate_by_schema_keyscCsld}g}d}d}t�rd}d}y tjdd||gdd	�jj�}Wnptk
r�}z6t|jt�rhtj	d
�nd|j
kr~tj	d�n�WYd
d
}~Xn tk
r�tj
td�YnX|s�tjj|�r�dSy&tjdddd|gdd	�jj�j�}Wn$tk
�rtj
td|�YnXtj	ddj|��dd�|D�}tj	ddj|��|�rXt|�dn|}tj	d|�|S)z�
    Fetches the /dev/disk/by-id device grub is installed to.
    Falls back to plain disk name if no by-id entry is present.
    ��diskz/bootZdevicez	/boot/efiz
grub-probez-tT)Zcapturez'grub-probe' not found in $PATHzfailed to get canonical pathz)grub-probe 'failed to get canonical path'Nz*grub-probe failed to execute for grub_dpkgZudevadm�infoz--rootz--query=symlinkz3udevadm DEVLINKS symlink query failed for disk='%s'z%considering these device symlinks: %s�,cSsg|]}d|kr|�qS)z
disk/by-id�)�.0Zdevrr�"/usr/lib/python3.6/cc_grub_dpkg.py�
<listcomp>zszfetch_idevs.<locals>.<listcomp>z)filtered to these disk/by-id symlinks: %srzselected %s)�
is_efi_bootedr�stdout�stripr
�
isinstance�reason�FileNotFoundError�LOG�debug�stderr�	Exceptionr�logexc�os�path�exists�split�join�sorted)rZdevicesZprobe_targetZprobe_mount�e�idevsrrr�fetch_idevs?sB
r+)�returncCs>ytjjd�Stk
r8}ztjd|�dSd}~XnXdS)z4
    Check if the system is booted in EFI mode.
    z/sys/firmware/efiz7Failed to determine if system is booted in EFI mode: %sFN)r#r$r%�OSErrorr�error)r)rrrr�s
r)r�cfg�cloud�argsr,cCs�|jd|jdi��}|si}|jdd�}tj|�rDtjd||�dSt|�}tjd|�ytjdg|d�Wn0tk
r�}ztjtd	|�WYdd}~XnXdS)
NZ	grub_dpkgz	grub-dpkg�enabledTz*%s disabled by config grub_dpkg/enabled=%sz-Setting grub debconf-set-selections with '%s'zdebconf-set-selections)�dataz6Failed to run debconf-set-selections for grub_dpkg: %s)	�getrZis_falserr�get_debconf_configrr!r")rr/r0r1�mycfgr2Z	dconf_selr)rrr�handle�s
r7)r6r,cCs�t�r*tj|dd�}|dkr"t�}d|Stj|dd�}|dkrFt�}|jd�}|dkr`|}nt|t�sttj|�}t|�j	�}d||fSdS)zd
    Returns the debconf config for grub-pc or
    grub-efi depending on the systems boot mode.
    zgrub-efi/install_devicesNz+grub-pc grub-efi/install_devices string %s
zgrub-pc/install_deviceszgrub-pc/install_devices_emptyz[grub-pc grub-pc/install_devices string %s
grub-pc grub-pc/install_devices_empty boolean %s
)
rrZget_cfg_option_strr+r4r�boolZtranslate_bool�str�lower)r6r*Zidevs_emptyrrrr5�s"



r5) �__doc__Zloggingr#�textwraprZ	cloudinitrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarrZcloudinit.settingsr	Zcloudinit.subpr
ZMODULE_DESCRIPTIONr�metaZ	getLogger�__name__rr+r8rr9�listr7r5rrrr�<module>	s4	
D