o
    S(eØ ã                   @   s„   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 ddlmZ ddlmZ G dd„ deƒZdS )é    N)ÚPIPEÚPopené   )Úget_arch)Úgettextc                   @   s¼  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#dBdC„ Z$dDdE„ Z%dFdG„ Z&dodIdJ„Z'dpdLdM„Z(dNdO„ Z)dPdQ„ Z*dRdS„ Z+dqdUdV„Z,dWdX„ Z-dYdZ„ Z.d[d\„ Z/d]d^„ Z0d_d`„ Z1dadb„ Z2dcdd„ Z3drdfdg„Z4drdhdi„Z5dsdkdl„Z6dmdn„ Z7dKS )tÚDistUpgradeQuirksz•
    This class collects the various quirks handlers that can
    be hooked into to fix/work around issues that the individual
    releases have
    c                 C   sd   || _ |j| _|| _tddgtdd� ¡ d  ¡ | _tƒ | _	d| _
d | _d| _d | _d | _d | _d S )NÚunamez-rT©ÚstdoutÚuniversal_newlinesr   F)Ú
controllerÚ_viewÚconfigr   r   ÚcommunicateÚstripr   r   ÚarchÚextra_snap_spaceÚ_pokeÚ_snapstore_reachableÚ
_snap_listÚ_from_versionÚ_to_version)Úselfr   r   © r   ú?/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeQuirks.pyÚ__init__-   s"   
ÿÿÿ
zDistUpgradeQuirks.__init__c                 C   sÒ   | j jrt d¡ dS | j dd¡}| j dd¡}d| }t| |dƒ}|dur1t d| ¡ |ƒ  d||f }t| |dƒ}|durKt d| ¡ |ƒ  d	||f }t| |dƒ}|durgt d| ¡ |ƒ  dS dS )
a˜  
        Run the specific quirks handler, the follow handlers are supported:
        - PreCacheOpen: run *before* the apt cache is opened the first time
                        to set options that affect the cache
        - PostInitialUpdate: run *before* the sources.list is rewritten but
                             after an initial apt-get update
        - PreDistUpgradeCache: run *right before* the dist-upgrade is
                               calculated in the cache
        - PostDistUpgradeCache: run *after* the dist-upgrade was calculated
                                in the cache
        - StartUpgrade: before the first package gets installed (but the
                        download is finished)
        - PostUpgrade: run *after* the upgrade is finished successfully and
                       packages got installed
        - PostCleanup: run *after* the cleanup (orphaned etc) is finished
        z)not running quirks in partialUpgrade modeNÚSourcesÚToÚFromú%szquirks: running %sz%s%sz	from_%s%s)r   Ú_partialUpgradeÚloggingÚinfor   ÚgetÚgetattrÚdebug)r   Ú
quirksNameÚ
to_releaseÚfrom_releaseÚfuncnameÚfuncr   r   r   Úrun?   s*   

þzDistUpgradeQuirks.runc                 C   ó   t  d¡ dS )z3 run before the apt cache is opened the first time zrunning Quirks.PreCacheOpenN©r!   r%   ©r   r   r   r   ÚPreCacheOpenm   ó   zDistUpgradeQuirks.PreCacheOpenc                 C   s¢   t  d¡ |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  | jj}|  	|¡ |  
¡  d|vr1t  d¡ dS |d jrFtj d¡sBtj d¡rF|  ¡  | jrO|  ¡  dS dS )z2 run after the apt cache is opened the first time z%running Quirks.jammyPostInitialUpdateÚsnapdú'package required for Quirk not in cacheNz/run/snapd.socketz/run/snapd-snap.socket)r!   r%   Ú_get_from_and_to_versionÚ_test_and_fail_on_i386Ú_test_and_fail_on_aufsÚ_test_and_fail_on_power8Ú_test_and_fail_on_pam_tallyr   ÚcacheÚ_test_and_warn_if_ros_installedÚ_fix_missing_nvidia_metapackageÚis_installedÚosÚpathÚexistsÚ_checkStoreConnectivityr   Ú_calculateSnapSizeRequirements©r   r8   r   r   r   ÚjammyPostInitialUpdater   s*   




ÿ
þÿz(DistUpgradeQuirks.jammyPostInitialUpdatec                 C   sˆ   t  d¡ | jj}d|vrt  d¡ d S |d jr | jr |  ¡  d|v r-|d jr-|  ¡  d|v r@|d jrB|  ¡  |  	¡  d S d S d S )Nzrunning Quirks.jammyPostUpgrader1   r2   zubuntu-desktop-raspizlinux-firmware-raspi2)
r!   r%   r   r8   r;   r   Ú_replaceDebsAndSnapsÚ_replace_fkms_overlayÚ_remove_uboot_on_rpiÚ_remove_netplan_match_rpirA   r   r   r   ÚjammyPostUpgrade�   s$   


ÿ

ýz"DistUpgradeQuirks.jammyPostUpgradec                 C   r,   )z run after cleanup zrunning Quirks.PostCleanupNr-   r.   r   r   r   ÚPostCleanupŸ   r0   zDistUpgradeQuirks.PostCleanupc                 C   s>   t  d¡ |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  d S )Nzrunning Quirks.StartUpgrade)r!   r%   Ú_applyPatchesÚ_removeOldApportCrashesÚ_killUpdateNotifierÚ_killKBluetoothÚ_pokeScreensaverÚ_stopDocvertConverterr.   r   r   r   ÚStartUpgrade¤   s   
zDistUpgradeQuirks.StartUpgradec                 C   r,   )z/ run right before calculating the dist-upgrade z"running Quirks.PreDistUpgradeCacheNr-   r.   r   r   r   ÚPreDistUpgradeCache¯   r0   z%DistUpgradeQuirks.PreDistUpgradeCachec                 C   s   t  d¡ |  ¡  dS )z( run after calculating the dist-upgrade z#running Quirks.PostDistUpgradeCacheN)r!   r%   Ú_install_linux_metapackager.   r   r   r   ÚPostDistUpgradeCache¶   s   
z&DistUpgradeQuirks.PostDistUpgradeCachec                 C   sj   t ƒ }ztjddgtjdd�}W n ty   | Y S w | ¡ d  d¡D ]}|r2| | ¡ d ¡ q%|S )z8 return a set of pci ids of the system (using lspci -n) Úlspciz-nTr	   r   Ú
é   )ÚsetÚ
subprocessr   r   ÚOSErrorr   ÚsplitÚadd)r   rS   ÚpÚliner   r   r   Ú_get_pci_ids¼   s   
ÿÿ€zDistUpgradeQuirks._get_pci_idsc                    s´   t  ¡ }z| dˆ jj ¡ ¡ d ˆ _| dˆ jj ¡ ¡ d ˆ _W d S  t	yY   t
‡ fdd„| d¡D ƒˆ jjƒ ¡ d ˆ _t
‡ fdd„| d¡D ƒˆ jjƒ ¡ d ˆ _Y d S w )Nr   r   c                 3   ó$   � | ]}|j ˆ jjkr|jV  qd S ©N)Úseriesr   ÚfromDistÚversion©Ú.0Úrr.   r   r   Ú	<genexpr>Ó   ó   € ÿÿz=DistUpgradeQuirks._get_from_and_to_version.<locals>.<genexpr>Úobjectc                 3   r^   r_   )r`   r   ÚtoDistrb   rc   r.   r   r   rf   ×   rg   )Údistro_infoÚUbuntuDistroInforb   r   ra   rY   r   ri   r   ÚAttributeErrorÚnextÚget_all)r   Údir   r.   r   r3   É   s(   ÿ
ÿýýýýûz*DistUpgradeQuirks._get_from_and_to_versionc                 C   s¤   d}t j |¡rdt jvrd S tjg d¢tt jdƒd�}|dkr't 	d¡ d S t |g¡}t 	d||f ¡ |dkrN| j
 td	ƒtd
ƒ¡}|sP| j ¡  d S d S d S )Nz/usr/lib/nux/unity_support_testÚDISPLAY)Úpsz-Czunity-panel-serviceÚw)r
   r   z5_test_and_warn_for_unity_3d_support: no unity runningz6_test_and_warn_for_unity_3d_support '%s' returned '%s'zBYour graphics hardware may not be fully supported in Ubuntu 14.04.aS  Running the 'unity' desktop environment is not fully supported by your graphics hardware. You will maybe end up in a very slow environment after the upgrade. Our advice is to keep the LTS version for now. For more information see https://wiki.ubuntu.com/X/Bugs/UpdateManagerWarningForUnity3D Do you still want to continue with the upgrade?)r<   r=   r>   ÚenvironrW   ÚcallÚopenÚdevnullr!   r%   r   ÚaskYesNoQuestionÚ_r   Úabort)r   ÚUNITY_SUPPORT_TESTÚreturn_codeÚresr   r   r   Ú#_test_and_warn_for_unity_3d_supportÛ   s6   
ÿÿÿÿýòz5DistUpgradeQuirks._test_and_warn_for_unity_3d_supportc                 C   sN   g d¢}|   ¡ }t|ƒ |¡r#| j tdƒtdƒ¡}|s%| j ¡  d S d S d S )N)z	8086:7121z	8086:7125z	8086:1132z	8086:3577z	8086:2562z	8086:3582z	8086:2572zFYour graphics hardware may not be fully supported in Ubuntu 12.04 LTS.zûThe support in Ubuntu 12.04 LTS for your Intel graphics hardware is limited and you may encounter problems after the upgrade. For more information see https://wiki.ubuntu.com/X/Bugs/UpdateManagerWarningForI8xx Do you want to continue with the upgrade?)r]   rV   Úintersectionr   rw   rx   r   ry   )r   ÚI8XX_PCI_IDSrS   r|   r   r   r   Ú_test_and_warn_on_i8xxü   s   ý
ôz(DistUpgradeQuirks._test_and_warn_on_i8xxc                 C   sœ   |   d¡rJ|  d¡sL| j tdƒtdƒ¡}|s| j ¡  g d¢}t dd 	|¡ ¡ | jj
 dd¡}|D ]}| |¡ q4| jj
 ddd	 	|¡¡ d
S d
S d
S )zi
        Some cards are no longer supported by fglrx. Check if that
        is the case and warn
        ÚfglrxzhUpgrading may reduce desktop effects, and performance in games and other graphically intensive programs.zµThis computer is currently using the AMD 'fglrx' graphics driver. No version of this driver is available that works with your hardware in Ubuntu 10.04 LTS.

Do you want to continue?)zxorg-driver-fglrxzxorg-driver-fglrx-envyzfglrx-kernel-sourcezfglrx-amdccclezxorg-driver-fglrx-devÚlibamdxvba1z	remove %sú, ÚDistroÚPostUpgradePurgeú,N)Ú_checkVideoDriverÚ_supportInModaliasesr   rw   rx   r   ry   r!   r%   Újoinr   ÚgetlistÚappendrV   )r   r|   ÚremovalsÚpostupgradepurgeÚremover   r   r   Ú'_test_and_warn_on_dropped_fglrx_support  s*   
ÿû
þÿáz9DistUpgradeQuirks._test_and_warn_on_dropped_fglrx_supportc                 C   sl   | j dkrd}n| j dkrd}| jdkr4t d¡ tdƒ}td| j |f ƒ}| j ||¡ | j ¡  d	S d	S )
z}
        Test and fail if the package architecture is i386 as we
        have dropped support for this architecture.
        z18.04z
April 2023z19.04zJanuary 2020Úi386zapt architecture is i386ú'Sorry, no more upgrades for this systemzƒThere will not be any further Ubuntu releases for this system's 'i386' architecture.

Updates for Ubuntu %s will continue until %s.N)r   r   r!   Úerrorrx   r   r   ry   )r   Úupdates_endÚsummaryÚmsgr   r   r   r4   =  s   



ýøz(DistUpgradeQuirks._test_and_fail_on_i386c                 C   s>   | j dkr|  ¡ s| j tdƒtdƒ¡ | j ¡  dS dS dS )z~
        Test and fail if the cpu is not a arm v6 or greater,
        from 9.10 on we do no longer support those CPUs
        ÚarmelzNo ARMv6 CPUzþYour system uses an ARM CPU that is older than the ARMv6 architecture. All packages in karmic were built with optimizations requiring ARMv6 as the minimal architecture. It is not possible to upgrade your system to a new Ubuntu release with this hardware.N)r   Ú_checkArmCPUr   r’   rx   r   ry   r.   r   r   r   Ú_test_and_fail_on_non_arm_v6Q  s   
þ	õz.DistUpgradeQuirks._test_and_fail_on_non_arm_v6c                 C   sP   dD ]#}t j |¡r%t d¡ tdƒ}td| ƒ}| j ||¡ | j ¡  qdS )zé
        Test and fail if docker has aufs storage driver available
        as it is deprecated after 20.04. Even if no containers are
        currently running aufs, the upgrade could break existing
        container images.
        )z+/var/snap/docker/common/var-lib-docker/aufsz/var/lib/docker/aufszDocker config uses aufszISorry, this storage driver is not supported in kernels for newer releaseszÜThere will not be any further Ubuntu releases that provide kernel support for the aufs storage driver.

Please ensure that none of your containers are using the aufs storage driver, remove the directory %s and try again.N)	r<   r=   r>   r!   r’   rx   r   r   ry   )r   Úaufs_dirr”   r•   r   r   r   r5   c  s   
û
€óz(DistUpgradeQuirks._test_and_fail_on_aufsc              	   C   sº   t  d¡D ]U}|dv rqtt j d|¡ƒ�=}| ¡ }t d|tj¡rKt	 
d¡ tdƒ}tdƒd tdƒ }| j 
||¡ | j ¡  	 W d	  ƒ  d	S W d	  ƒ n1 sUw   Y  qd	S )
aÂ  
        Test and fail if pam_tally or pam_tally2 appears in the system's
        PAM config for any service.  These modules have been dropped as
        obsolete, so references to them in the config will break services
        on upgrade.  The libpam-modules package has a preinst that will also
        enforce this, but we want to enforce at the start of the upgrade
        before we get halfway through an apt transaction.  LP: #1977493
        z
/etc/pam.d)zcommon-accountzcommon-authzcommon-passwordzcommon-sessionzcommon-session-noninteractivez^[^#]*pam_tallyzpam_tally* in usez<You are using pam_tally or pam_tally2 in your configuration.aN  The pam_tally and pam_tally2 modules have been removed from PAM. You are using one of these modules in your PAM configuration in /etc/pam.d. You must remove the uses of these modules before PAM can be upgraded; including these modules in your PAM configuration after the upgrade will stop users from being able to log into the system.z

z@Consider the pam_faillock module as a replacement for pam_tally.N)r<   Úlistdirru   r=   r‰   ÚreadÚreÚsearchÚ	MULTILINEr!   r’   rx   r   r   ry   )r   ÚfÚcontentr”   r•   r   r   r   r7   y  s*   

ùø

íþ€ùz-DistUpgradeQuirks._test_and_fail_on_pam_tallyc                 C   sÂ   | j dkrdS d}| jdkrd}n| jdkrd}tdƒ�;}| ¡ }t d	|tj¡rOt d
¡ t	dƒ}t	d| j|f ƒ}| j
 ||¡ | j ¡  W d  ƒ dS W d  ƒ dS 1 sZw   Y  dS )a#  
        Test and fail if running on a POWER8 processor. Starting with Ubuntu
        22.04, ppc64el is compiled for POWER9 processors. Prior to 22.04 it
        was/is compiled for POWER8 processors. Hence POWER8 processors are not
        able to run, install or upgrade to jammy.
        Úppc64elNÚ z20.04z
April 2025z21.10z	July 2022ú/proc/cpuinfoz^cpu\s*:\s*POWER8zPOWER8 processor detectedr‘   z€There will not be any further Ubuntu releases for this system's POWER8 processor.

Updates for Ubuntu %s will continue until %s.)r   r   ru   r›   rœ   r�   rž   r!   r’   rx   r   r   ry   )r   r“   rŸ   Úcpuinfor”   r•   r   r   r   r6   Ÿ  s(   




ýõ"ýz*DistUpgradeQuirks._test_and_fail_on_power8c                 C   s`   z	t  dd¡ W dS  ty/   t d¡ | j tdƒtdƒ¡}|s'| j 	¡  | j 
¡  Y dS w )zd
        upstart and vserver environments are not a good match, warn
        if we find one
        r   r   zno init foundzNo init availablea  Your system appears to be a virtualised environment without an init daemon, e.g. Linux-VServer. Ubuntu 10.04 LTS cannot function within this type of environment, requiring an update to your virtual machine configuration first.

Are you sure you want to continue?N)r<   ÚkillrX   r!   Úwarningr   rw   rx   r   ry   ÚprocessEvents©r   r|   r   r   r   Ú_test_and_warn_if_vserver¼  s   
þ
ôz+DistUpgradeQuirks._test_and_warn_if_vserverc                 C   s˜   t ƒ }dD ]}| t d| ¡¡ qd}|D ]}|r n|D ]}| |j¡r0|js,|jr.d} nqq|rH| j 	t
dƒt
dƒ¡}|sJ| j ¡  dS dS dS )z¿
        Test and warn if ROS is installed. A given ROS release only
        supports specific Ubuntu releases, and can cause the upgrade
        to fail in an overly-cryptic manner.
        )Úcatkinzrosboost-cfgÚroscleanzros-environmentzros-workspacezros-[^\-]+-%sFTz-The Robot Operating System (ROS) is installeda	  It appears that ROS is currently installed. Each ROS release is very strict about the versions of Ubuntu it supports, and Ubuntu upgrades can fail if that guidance isn't followed. Before continuing, please either uninstall ROS, or ensure the ROS release you have installed supports the version of Ubuntu to which you're upgrading.

For ROS 1 releases, refer to REP 3:
https://www.ros.org/reps/rep-0003.html

For ROS 2 releases, refer to REP 2000:
https://www.ros.org/reps/rep-2000.html

Are you sure you want to continue?N)rV   rZ   rœ   ÚcompileÚmatchÚnamer;   Úmarked_installr   rw   rx   r   ry   )r   r8   Úros_package_patternsÚpackage_nameÚros_is_installedÚpkgÚpatternr|   r   r   r   r9   Ò  s2   ÿý€þðz1DistUpgradeQuirks._test_and_warn_if_ros_installedc                 C   sl   t  d¡ tj d¡st  d¡ dS tdƒ�}| ¡ }W d  ƒ n1 s%w   Y  t 	d|tj
¡r4dS dS )zE
        parse /proc/cpuinfo and search for ARMv6 or greater
        zchecking for ARM CPU versionr£   zcannot open /proc/cpuinfo ?!?FNz^Processor\s*:\s*ARMv[45]T)r!   r%   r<   r=   r>   r’   ru   r›   rœ   r�   rž   )r   rŸ   r¤   r   r   r   r—     s   



ÿÿzDistUpgradeQuirks._checkArmCPUc                 C   sZ   t  d¡ tj d¡st  d¡ dS tdƒ�}| ¡ }W d  ƒ |S 1 s&w   Y  |S )z„
        read /sys/class/dmi/id/sys_vendor in case there are
        system specific issues with upgrading e.g LP: #1928434
        zchecking for system vendorz/sys/class/dmi/id/sys_vendorz(cannot open /sys/class/dmi/id/sys_vendorr¢   N)r!   r%   r<   r=   r>   r’   ru   r›   )r   rŸ   Úvendorr   r   r   Ú_readDMIVendor  s   




ÿþz DistUpgradeQuirks._readDMIVendorc                 C   ó,   t j d¡rt d¡ t ddg¡ dS dS )z, /etc/init.d/apparmor stop (see bug #559433)z/etc/init.d/apparmorz/etc/init.d/apparmor stopÚstopN©r<   r=   r>   r!   r%   rW   rt   r.   r   r   r   Ú_stopApparmor  ó   
þzDistUpgradeQuirks._stopApparmorc                 C   r·   )z5 /etc/init.d/docvert-converter stop (see bug #450569)z/etc/init.d/docvert-converterz"/etc/init.d/docvert-converter stopr¸   Nr¹   r.   r   r   r   rN   #  r»   z'DistUpgradeQuirks._stopDocvertConverterc                 C   ó,   t j d¡rt d¡ t g d¢¡ dS dS )zkill update-notifierú/usr/bin/killallzkilling update-notifier)Úkillallú-qzupdate-notifierNr¹   r.   r   r   r   rK   )  s   
þz%DistUpgradeQuirks._killUpdateNotifierc                 C   r¼   )z3killall kblueplugd kbluetooth (riddel requested it)r½   zkilling kblueplugd kbluetooth4)r¾   r¿   Ú
kblueplugdÚkbluetooth4Nr¹   r.   r   r   r   rL   0  r»   z!DistUpgradeQuirks._killKBluetoothc              	   C   s„   t j d¡r>t j d¡r@t d¡ d}|d7 }|d7 }ztj|dd�| _	t
 | j¡ W d S  ttfy=   t d	¡ Y d S w d S d S )
Nz/usr/bin/xdg-screensaverrp   z$setup poke timer for the screensaverzwhile true;z3 do /usr/bin/xdg-screensaver reset >/dev/null 2>&1;z sleep 30; doneT)Úshellz failed to setup screensaver poke)r<   r=   r>   rs   r#   r!   r%   rW   r   r   ÚatexitÚregisterÚ_stopPokeScreensaverrX   Ú
ValueErrorÚ	exception)r   Úcmdr   r   r   rM   6  s   
ÿ
ÿ÷z"DistUpgradeQuirks._pokeScreensaverc                 C   sN   d}| j d ur%z| j  ¡  | j  ¡ }W n ty!   t d¡ Y nw d | _ |S )NFzfailed to stop screensaver poke)r   Ú	terminateÚwaitrX   r!   rÇ   r¨   r   r   r   rÅ   C  s   

ÿz&DistUpgradeQuirks._stopPokeScreensaverc              
   C   sv   z dD ]}t   d| ¡D ]}t d||f ¡ t |¡ qqW dS  ty: } zt d| ¡ W Y d}~dS d}~ww )z: remove old apport crash files and whoopsie control files )z.crashz.uploadz	.uploadedz/var/crash/*%szremoving old %s file '%s'z+error during unlink of old crash files (%s)N)Úglobr!   r%   r<   ÚunlinkÚ	Exceptionr¦   )r   ÚextrŸ   Úer   r   r   rJ   N  s   þÿ€ÿz)DistUpgradeQuirks._removeOldApportCrashesc                 C   sZ  d}t j ¡ }d|d< tg d¢tt|dd� ¡ }t d|d tj¡r'd| _	d	S t d
|d tj¡rxt
 d¡ d}| jj}d|v rU|d jrU|d jj d¡sUt
 d¡ d}|rltdƒ}tdƒ}| j ||¡ | j ¡  n6| j tdƒtdƒ¡}n*d|d v r�t
 d¡ | j tdƒtdƒ¡}nd|d v r�d}t
 d¡ nt
 d¡ |s«| j ¡  d	S d	S )z: check for connectivity to the snap store to install snapsFzC.UTF-8ÚLANG)Úsnapr%   ÚconnectivityT)r
   ÚstderrÚenvr   z	^ \* PASSr   Nz^ \*.*unreachablezNo snap store connectivityÚlxdz1:zlxd is installedz#Connection to the Snap Store faileda�  You have the package lxd installed but your system is unable to reach the Snap Store. lxd is now provided via a snap and the release upgrade will fail if snapd is not functional. Please make sure you're connected to the Internet and update any firewall or proxy settings as needed so that you can reach api.snapcraft.io. If you are an enterprise with a firewall setup you may want to configure a Snap Store proxy.zConnection to Snap Store failedzÅYour system does not have a connection to the Snap Store. For the best upgrade experience make sure that your system can connect to api.snapcraft.io.
Do you still want to continue with the upgrade?zerror: unknown commandr   z snap debug command not availablezOutdated snapd packagez»Your system does not have the latest version of snapd. Please update the version of snapd on your system to improve the upgrade experience.
Do you still want to continue with the upgrade?zerror: access deniedzNot running as root!z-Unhandled error connecting to the snap store.)r<   rs   Úcopyr   r   r   rœ   r�   rž   r   r!   r’   r   r8   r;   Ú	candidaterb   Ú
startswithrx   r   ry   rw   )r   r|   Úsnap_envÚ	connectedÚold_lxd_deb_installedr8   r”   r•   r   r   r   r?   X  sX   

þþ

ÿ
þ
þ
ÿz)DistUpgradeQuirks._checkStoreConnectivityc                 C   s0  dd l }dd l}ddlm} |  ¡  | j tdƒ¡ | j 	¡ D ]v\}}|d dkr*qdd|d |d	 d
œ}g |gdœ}|j
jdt| |¡dd�d�}| dd¡ | dd¡ | d| j¡ z|j
 |¡ ¡ }	| |	¡}
t|
d d d d d ƒ}W n t|tfy�   t d| ¡ Y qw |  j|7  _qd S )Nr   )ÚURLErrorz"Calculating snap size requirementsÚcommandÚinstallzupgrade-size-checkÚdownloadúsnap-idÚchannel)zinstance-keyÚactionrà   rá   )ÚcontextÚactionsz)https://api.snapcraft.io/v2/snaps/refreshúutf-8©Úencoding)ÚurlÚdatazSnap-Device-SeriesÚ16zContent-typezapplication/jsonzSnap-Device-ArchitectureÚresultsrÑ   ÚsizezFailed fetching size of snap %s)ÚjsonÚurllib.requestÚurllib.errorrÜ   Ú_prepare_snap_replacement_datar   ÚupdateStatusrx   r   ÚitemsÚrequestÚRequestÚbytesÚdumpsÚ
add_headerr   Úurlopenr›   ÚloadsÚintÚKeyErrorrÆ   r!   r%   r   )r   rí   ÚurllibrÜ   rÑ   Úsnap_objectrâ   ré   ÚreqÚresponser"   rì   r   r   r   r@   ˜  sB   üþþ
 þæz0DistUpgradeQuirks._calculateSnapSizeRequirementsc              	   C   s>  | j  tdƒ¡ | j ¡ D ]�\}}|d }|dkr-| j  td| ƒ¡ d|d|d |g}n'|dkrA| j  td	| ƒ¡ d||g}n| j  td
| ƒ¡ d|d|d |g}z| j  ¡  tj|tjdd�}| j  ¡  W n tj	y|   t
 d||f ¡ Y qw |jdkr‹t
 d||f ¡ |dkrœ|d rœ| jj |d ¡ qdS )z? install a snap and mark its corresponding package for removal zProcessing snap replacementsrÝ   Úrefreshzrefreshing snap %srÑ   z	--channelrá   rŽ   zremoving snap %szinstalling snap %sT)r
   Úcheckz%s of snap %s failedr   z%s of snap %s succeededrÞ   ÚdebN)r   rñ   rx   r   rò   r§   rW   r+   r   ÚCalledProcessErrorr!   r%   Ú
returncoder   Úforced_obsoletesr‹   )r   rÑ   rý   rÝ   Ú	popenargsÚprocr   r   r   rC   À  sB   
ÿ
ÿ
ýþ
€æz&DistUpgradeQuirks._replaceDebsAndSnapsc                 C   s�   t  d¡ d}tdƒ�}| ¡ }W d  ƒ n1 sw   Y  t d|tj¡r)d}|sFt  d¡ tdƒ}td	ƒ}| j	 ||¡ | j
 ¡  dS dS )
z check PAE in /proc/cpuinfo Ú	_checkPaer   r£   Nz^flags\s+:.* pae r   zno pae in /proc/cpuinfozPAE not enabledzôYour system uses a CPU that does not have PAE enabled. Ubuntu only supports non-PAE systems up to Ubuntu 12.04. To upgrade to a later version of Ubuntu, you must enable PAE (if this is possible) see:
http://help.ubuntu.com/community/EnablingPAE)r!   r%   ru   r›   rœ   r�   rž   r’   rx   r   r   ry   )r   ÚpaerŸ   r¤   r”   r•   r   r   r   r  á  s   


ÿ
÷zDistUpgradeQuirks._checkPaec                 C   s†   d}t j |¡s
dS t|ƒ�}| ¡ }W d  ƒ n1 sw   Y  |D ]}| d¡d  ¡ }| ¡  d¡r@| 	d| ¡r@ dS q$dS )	z2 check if the given driver is in use in xorg.conf z/etc/X11/xorg.confFNú#r   Údriverz"%s"T)
r<   r=   r>   ru   Ú	readlinesrY   r   ÚlowerrØ   Úendswith)r   r®   ÚXORGrŸ   Úlinesr\   Úsr   r   r   r‡   õ  s   

ÿÿ€z#DistUpgradeQuirks._checkVideoDriverú	./patchesc           
   	   C   sn  t j |¡st d¡ dS t  |¡D ]¢}d|vr t d| ¡ qt d| ¡ | dd¡\}}}| dd¡}t d	|||f ¡ t j |¡sNt d
| ¡ qt 	¡ }t
|dƒ�}| | ¡ ¡ W d  ƒ n1 siw   Y  | ¡ |kr|t d| ¡ q| ¡ |krŠt d| ¡ qddlm}	 z|	|t j ||¡|ƒ t d| ¡ W q ty´   t d| ¡ Y qw dS )z¯
        helper that applies the patches in patchdir. the format is
        _path_to_file.md5sum and it will apply the diff to that file if the
        md5sum matches
        zno patchdirNÚ.zskipping '%s' (no '.')z'check if patch '%s' needs to be appliedrU   rx   ú/ztarget for '%s' is '%s' -> '%s'ztarget '%s' does not existÚrbz%already at target hash, skipping '%s'z(unexpected target md5sum, skipping: '%s'r   )Úpatchzapplied '%s' successfullyzed failed for '%s')r<   r=   r>   r!   r%   rš   ÚrsplitÚreplaceÚhashlibÚmd5ru   Úupdater›   Ú	hexdigestr¦   ÚDistUpgradePatcherr  r‰   r"   rÍ   rÇ   )
r   ÚpatchdirrŸ   Úencoded_pathÚmd5sumÚresult_md5sumr=   r  Úfdr  r   r   r   rI     sH   
ÿÿÿÿÝzDistUpgradeQuirks._applyPatchesNc           	      C   s¾   |s|   ¡ }|| jjvs| jj| jst d¡ dS | jj| }|  |jj¡D ].\}}|D ]'}t 	d|¡}|rTd| 
d¡| 
d¡f }| ¡ |v rTt d| ¡   dS q-q't d	| ¡ dS )
zß
        Check if pkgname will work on this hardware

        This helper will check with the modaliasesdir if the given
        pkg will work on this hardware (or the hardware given
        via the lspci argument)
        zcan not find '%s' in cacheFzpci:v0000(.+)d0000(.+)sv.*z%s:%sr   rU   z%found system pciid '%s' in modaliasesTz4checking for %s support in modaliases but none found)r]   r   r8   r×   r!   r¦   Ú!_parse_modaliases_from_pkg_headerÚrecordrœ   r­   Úgroupr  r%   )	r   ÚpkgnamerS   r³   ÚmoduleÚ
pciid_listÚpciidÚmÚmatchidr   r   r   rˆ   3  s2   	ÿ

ÿÿ€ùÿz&DistUpgradeQuirks._supportInModaliasesc                 C   sd   d|vrg S g }|d   d¡D ] }| d¡}|sq|  d¡\}}| |dd„ |  d¡D ƒf¡ q|S )z. return a list of (module1, (pciid, ...), ...)Ú
Modaliasesú)rƒ   ú(c                 S   ó   g | ]}|  ¡ ‘qS r   )r   )rd   Úxr   r   r   Ú
<listcomp>]  ó    zGDistUpgradeQuirks._parse_modaliases_from_pkg_header.<locals>.<listcomp>r†   )rY   r   r‹   )r   Ú	pkgrecordÚmodulesr*  r'  Úpciidsr   r   r   r#  R  s   
 z3DistUpgradeQuirks._parse_modaliases_from_pkg_headerc                 C   sÒ   t  d¡ | jj}d|vrt  d¡ d S |d js%|d js%t  d¡ d S z4dd l}|j ¡ }|D ]}d|j	v rAt  d¡  W d S q1t  
d¡ | d	d
| jjdgd¡ | ¡  W d S  tyh   t  d¡ Y d S w )NÚ_add_extras_repositoryzubuntu-extras-keyringz-no ubuntu-extras-keyring, no need to add repoz2ubuntu-extras-keyring not installed/marked_installr   zextras.ubuntu.comz*found extras.ubuntu.com, no need to add itz/no extras.ubuntu.com, adding it to sources.listr  zhttp://extras.ubuntu.com/ubuntuÚmainz!Third party developers repositoryzerror adding extras.ubuntu.com)r!   r%   r   r8   r¯   Ú	installedÚaptsources.sourceslistÚsourceslistÚSourcesListÚurir"   rZ   ri   ÚsaverÍ   rÇ   )r   r8   Ú
aptsourcesÚsourcesÚentryr   r   r   r6  `  s6   


ÿ



þ

þÿz(DistUpgradeQuirks._add_extras_repositoryc                 C   sp   z(| j j}d|v r |d jr#d|v r&t d¡ | dd¡ W dS W dS W dS W dS  ty7   t d¡ Y dS w )zÂ foomatic-db-gutenprint get removed during the upgrade,
            replace it with the compressed ijsgutenprint-ppds
            (context is foomatic-db vs foomatic-db-compressed-ppds)
        zfoomatic-db-gutenprintzijsgutenprint-ppdszinstalling ijsgutenprint-ppdsz1foomatic-db-gutenprint -> ijsgutenprint-ppds rulez_gutenprint_fixup failedN)r   r8   Úmarked_deleter!   r"   Úmark_installrÍ   rÇ   rA   r   r   r   Ú_gutenprint_fixupz  s    ÿ

þüÿz#DistUpgradeQuirks._gutenprint_fixupr�   c                 C   st   d}t j |¡s8zt  d¡ W n	 ty   Y nw t|dƒ�}| d| ¡ W d  ƒ dS 1 s1w   Y  dS dS )z5 enable multiarch via /etc/dpkg/dpkg.cfg.d/multiarch z/etc/dpkg/dpkg.cfg.d/multiarchz/etc/dpkg/dpkg.cfg.d/rr   zforeign-architecture %s
N)r<   r=   r>   ÚmakedirsrX   ru   Úwrite)r   Úforeign_archÚcfgrŸ   r   r   r   Ú_enable_multiarch‹  s   ÿ"ÿûz#DistUpgradeQuirks._enable_multiarchc                 C   sz   t  d¡}| |¡}| |¡}|r+|r+d| d¡| d¡f }d| d¡| d¡f }t d||f ¡ tj ||¡dkS )z# copied from ubuntu-drivers common z(.+)-([0-9]+)-(.+)ú%s-%sr   rU   zComparing %s with %sr   )	rœ   r¬   r­   r%  r!   r%   ÚaptÚapt_pkgÚversion_compare)r   Úterm1Úterm2r´   Úmatch1Úmatch2r   r   r   Ú_is_greater_than–  s   



ÿ
ÿz"DistUpgradeQuirks._is_greater_thanc                 C   sÞ   |rdpd}t  d¡}t  d¡}d}d}|D ]V}d|jv rld|jvrl|js(|jrl| |j¡}	|	rl|jjd }
d|	 d	¡|	 d
¡f }|  	||¡rl|}| |
¡}d|
v rc|rcd||	 d¡| d	¡f }qd||	 d¡f }q|S )zb Get the linux headers or linux metapackage
            copied from ubuntu-drivers-common
        z-headersr¢   zlinux-image-(.+)-([0-9]+)-(.+)z
linux-(.+)zlinux-imageÚextraÚSourcerI  r   rU   z-lts-zlinux%s-%s-%sé   z
linux%s-%s)
rœ   r¬   r®   r;   r¯   r­   r×   r$  r%  rQ  )r   r8   ÚheadersÚsuffixr´   Úsource_patternÚmetapackagerb   r³   r­   ÚsourceÚcurrent_versionÚmatch_sourcer   r   r   Ú_get_linux_metapackage¦  sD   

ÿÿ
ÿÿ
	ýþ€z(DistUpgradeQuirks._get_linux_metapackagec                 C   s^   | j j}|  |d¡}||vrt d| ¡ dS || js-t d| ¡ d}| ||¡ dS dS )zo Ensure the linux metapackage is installed for the newest_kernel
            installed. (LP: #1509305)
        Fz$linux metapackage (%s) not availableNz installing linux metapackage: %sz8linux metapackage may have been accidentally uninstalled)r   r8   r\  r!   r"   r;   rB  )r   r8   Úlinux_metapackageÚreasonr   r   r   rQ   Ö  s   ÿ
ÿüz,DistUpgradeQuirks._install_linux_metapackagec           
         s–  d}| j j‰ dD ]U}|D ]P\}}t d||f ¡ |ˆ v r\ˆ | jr\|rAt d||f ¡ d| }ˆ j||d|d�sAt d| ¡ t d	||f ¡ d
| }ˆ j||dd�s\t d|¡ qqtj ˆ ¡}|D ]^\}}|ˆ v rÄˆ | jrÄ|r¶|ˆ vr¨‡ fdd„|D ƒ}t	dƒ}t	d||d 
|¡f ƒ}	t |¡ ˆ  ¡  | j ||	¡ | j  ¡  n| ˆ | ¡ | ˆ | ¡ | ˆ | ¡ | ˆ | ¡ qf| ¡  dS )zÌ
        Ensure python is removed, before it can produce a conflict with any
        other package and the python-is-python2 package is installed instead,
        if python-minimal was installed.
        ))z
python-dbgzpython2-dbg)z
python-doczpython2-doc)zpython-minimalzpython-is-python2)z
python-devzpython-dev-is-python2)zlibpython-devN)zlibpython-stdlibN)zlibpython-dbgN)FTzchecking for %s (auto_inst=%s)z&installing %s because %s was installedz%s was installed on the systemF)Úauto_fixÚ	auto_instzfailed to install %sz)removing %s because %s is being installedz#%s is being installed on the system)r_  zfailed to remove %sc                    s&   g | ]\}}|ˆ v rˆ | j r|‘qS r   )r;   )rd   ÚoldÚnew©r8   r   r   r1    s
    ÿ
ÿz@DistUpgradeQuirks._install_python_is_python2.<locals>.<listcomp>zuniverse component not enabledaÿ  You have the package %s installed which is a python2 package. python2 has been deprecated in Ubuntu 20.04 LTS and is now available from the universe component of the Ubuntu archive. To ensure any existing third party code you have installed continues to work the release upgrade process would install %s for you. However, the universe component of the archive is not enabled on this system. For the upgrade process to proceed you should either enable the universe component in /etc/apt/sources.list or remove %srƒ   N)r   r8   r!   r"   r;   rB  Úmark_removerJ  ÚProblemResolverrx   r‰   Ú_stopAptResolverLogr   r’   ry   ÚclearÚprotectrŽ   Úresolve)
r   Úreplacementsr`  ra  rb  r^  ÚsolverÚold_instr”   r•   r   rc  r   Ú_install_python_is_python2é  sZ   ÿÿ
ÿÿ€ñó
€z,DistUpgradeQuirks._install_python_is_python2c                 C   sH   | j js tjj d¡s"d}|d7 }t |¡ tjj dd¡ dS dS dS )z] ensure that on a desktop install recommends are installed
            (LP: #759262)
        zApt::Install-Recommendsz%Apt::Install-Recommends was disabled,z! enabling it just for the upgradeÚ1N)	r   Ú
serverModerJ  rK  r   Úfind_br!   r¦   rV   )r   r•   r   r   r   Ú+ensure_recommends_are_installed_on_desktops3  s   
ûz=DistUpgradeQuirks.ensure_recommends_are_installed_on_desktopsc                 C   sT   |  dd¡}t|tƒs|g}|D ]}|| jjvrq|r%| jj| jdu r%q dS dS )zˆ Helper function that checks if the given deb2snap entry
            has at least one metapkg which is installed on the system.
        ÚmetapkgNFT)r#   Ú
isinstanceÚlistr   r8   r;   )r   Údeb2snap_entryÚmetapkg_listrr  r   r   r   Ú_is_deb2snap_metapkg_installed>  s   
z0DistUpgradeQuirks._is_deb2snap_metapkg_installedc              
   C   sB  ddl }i | _d| j }d| j }i }i }zmtj tj t¡¡}t	|d dƒ}| 
|¡}| ¡  |d D ]'}	|d |	 }
|  |
¡sBq4|
 dd¡}|
 d|¡}|
 d	|¡}|||f||	< q4|d
 D ] }	|d
 |	 }| dd¡}|  |¡stq`| d|¡}||f||	< q`W n ty› } zt d| ¡ W Y d}~nd}~ww d}tjddgdtjd� ¡ }|rÒdd„ |d  d¡dd… D ƒ}|D ]}	|	|v sÉ|	|v rÊq¿d||f||	< q¿| j tdƒ¡ | ¡ D ]Ž\}	\}}}i }tjdd|	gdtjd� ¡ }| j ¡  t d|d tj¡�r&t d|	 ¡ t d| |d tj¡�s!t d|	 ¡ qÞd|d< n=| jj }|�rB||v�s8|| j!�sBt d||	f ¡ qÞt d|d ¡}|�sUt d |	 ¡ qÞd!|d< ||d< |d |d"< ||d#< || j|	< qÞ| ¡ D ]¬\}	\}}i }tjdd|	gdtjd� ¡ }| j ¡  t d|d tj¡�rt d|	 ¡ t d| |d tj¡�s´t d|	 ¡ �qqd$|d< tjdd%|	gdtjd� ¡ }| j ¡  |d  d¡D ]D}| ¡ }t"|ƒd&k�rá�qÒ|d }|d' }| #|	d( ¡�r| d(¡d }|d)k�r||v�rt d*|	|f ¡ d|d< d+|d#<  n�qÒ|| j|	< �qq| jS ),z» Helper function fetching all required info for the deb-to-snap
            migration: version strings for upgrade (from and to) and the list
            of snaps (with actions).
        r   Nzstable/ubuntu-%sz/deb2snap.jsonre   Úseededr  Úfrom_channelÚ
to_channelÚunseededz%error reading deb2snap.json file (%s)r¢   rÑ   rt  T)r   r
   c                 S   s   g | ]}|  ¡ d  ‘qS )r   )rY   ©rd   r\   r   r   r   r1  }  s    ÿzDDistUpgradeQuirks._prepare_snap_replacement_data.<locals>.<listcomp>rT   r   éÿÿÿÿzChecking for installed snapsr"   z^installed: zSnap %s is installedz^tracking:.*%sz+Snap %s is not tracking the release channelr   rÝ   zFDeb package %s is not installed. Skipping snap package %s installationzsnap-id:\s*(\w*)z'Could not parse snap-id for the %s snaprÞ   rà   rá   rŽ   Úconnectionsé   rU   ú:ú-z9Snap %s is being used by %s. Switching it to stable trackÚstable)$rí   r   r   r   r<   r=   ÚdirnameÚabspathÚ__file__ru   ÚloadÚcloserw  r#   rÍ   r!   r¦   rW   r   r   r   rY   r   rñ   rx   rò   r§   rœ   r�   rž   r%   r   r8   r;   ÚlenrØ   )r   rí   ry  rz  Úseeded_snapsÚunseeded_snapsÚcurrent_pathÚd2s_fileÚd2srÑ   Úseedr  Ú	from_chanÚto_chanÚunseedrÏ   Ú	snap_listÚsnaps_installedrý   Ú	snap_infor8   r­   ÚconnsÚconnÚ	conn_colsÚplugÚslotÚ	plug_snapr   r   r   rð   Q  s  




ú€ÿ
þþÿþþ


ÿÿ
ÿÿþþ


ÿÿþþ


þ€
€z0DistUpgradeQuirks._prepare_snap_replacement_dataú/boot/firmwarec           	   
   C   s   d}z$t j |d¡}t|ddd��}| ¡ }W d   ƒ n1 s w   Y  W n ty7   t d||¡ Y d S w d dd	„ |jd
d�D ƒ¡}||krRt 	d|¡ d S z%t j |d¡}t|ddd��}| 
|¡ W d   ƒ n1 sqw   Y  W n ty’ } zt d|||¡ W Y d }~d S d }~ww z!t|ddd��}| 
|¡ W d   ƒ W d S 1 s­w   Y  W d S  tyÏ } zt d|||¡ W Y d }~d S d }~ww )NzfYou may need to replace the vc4-fkms-v3d overlay with vc4-kms-v3d in config.txt on your boot partitionú
config.txtre   rå   ræ   ú+failed to open boot configuration in %s; %sr¢   c                 s   sP   � | ]#}|  d ¡rd| | d d¡ n|  d¡s| ¡ dkr"d| n|V  qdS )zdtoverlay=vc4-fkms-v3dz0# changed by do-release-upgrade (LP: #1923673)
#zdtoverlay=vc4-kms-v3dzgpu_mem=z	start_x=1z1# disabled by do-release-upgrade (LP: #1923673)
#N)rØ   r  Úrstripr|  r   r   r   rf   ä  s   € øþ
ÿÿÿ
ôz:DistUpgradeQuirks._replace_fkms_overlay.<locals>.<genexpr>T)Úkeependsz3no fkms overlay or camera firmware line found in %szconfig.txt.distUpgraderr   ú0unable to write boot config backup to %s: %s; %sú-unable to write new boot config to %s: %s; %s)r<   r=   r‰   ru   r›   ÚFileNotFoundErrorr!   r’   Ú
splitlinesr¦   rE  ÚIOError)	r   Úboot_dirÚfailure_actionÚboot_config_filenamerŸ   Úboot_configÚ
new_configÚboot_backup_filenameÚexcr   r   r   rD   Ö  s^   ÿ
ÿ€ÿý

óÿÿÿ€ÿ€ý&ÿÿ€ÿz'DistUpgradeQuirks._replace_fkms_overlayc              
      sð  d‰d‰d}|j ˆd�}d‰d‰ d‰z$tj ˆd¡}t|d	d
d��}| ¡ }W d   ƒ n1 s0w   Y  W n tyG   t d||¡ Y d S w ‡ ‡‡‡fdd„}‡‡fdd„}dd„ | 	¡ D ƒ}|||ƒƒ}d dd„ |D ƒ¡}	|	|kr}t 
d|¡ d S z"|d }
t|
dd
d��}| |¡ W d   ƒ n1 s™w   Y  W n tyº } zt d|
||¡ W Y d }~d S d }~ww z!t|dd
d��}| |	¡ W d   ƒ W d S 1 sÕw   Y  W d S  ty÷ } zt d|||¡ W Y d }~d S d }~ww )Nzkernel=vmlinuzz!initramfs initrd.img followkernelz”You may need to replace u_boot_* with vmlinuz, and add {initramfs_line!r} to config.txt on your boot partition; see LP: #1936401 for further details)Úinitramfs_linez0# commented by do-release-upgrade (LP: #1936401)z,# added by do-release-upgrade (LP: #1936401)z5# merged from {} by do-release-upgrade (LP: #1936401)rœ  re   rå   ræ   r�  c                    sÞ   g }d }}| D ]J}|dkr'|  |¡ |s&|  ˆ ¡ |  ˆ¡ |  ˆ¡ d}q| d¡r9|  ˆ¡ |  d| ¡ q| d¡rMd}|  ˆ¡ |  d| ¡ q|  |¡ q|rm|sk|  ˆ ¡ |  d¡ |  ˆ¡ |  ˆ¡ |S | S )NFz[all]Tzdevice_tree_address=r
  zkernel=uboot_rpi_)r‹   rØ   )r  ÚresultÚremoved_ubootÚadded_kernelr\   )Úadded_prefixÚchange_prefixr¬  Úkernel_liner   r   Úreplace_uboot  s6   



€







z=DistUpgradeQuirks._remove_uboot_on_rpi.<locals>.replace_ubootc           	         s&  g }d}d}| D ]„}|  d¡r|rqd}|dv r‡d}|jdd�d }| ˆ |¡¡ tj ˆ |¡}d}t|ddd	��}|D ]}|  d¡rG|rGq=d}| | ¡ ¡ q=W d   ƒ n1 s[w   Y  |d
 }zt 	||¡ W q t
y† } zt d|||¡ W Y d }~qd }~ww | |¡ q|r‘|S | S )NTFr
  )zinclude syscfg.txtzinclude usercfg.txtr   )Úmaxsplitre   rå   ræ   ú.distUpgradez7failed to move included configuration from %s to %s; %s)rØ   rY   r‹   Úformatr<   r=   r‰   ru   rž  Úrenamer¤  r!   r’   )	r  r­  Úskip_commentsÚfound_includesr\   Úincluded_filenamerŸ   Útarget_filenamer«  )r¥  Úmerge_prefixr   r   Úmerge_includesJ  sJ   ÿüÿþ€ÿz>DistUpgradeQuirks._remove_uboot_on_rpi.<locals>.merge_includesc                 S   r/  r   )rž  r|  r   r   r   r1  v  r2  z:DistUpgradeQuirks._remove_uboot_on_rpi.<locals>.<listcomp>r¢   c                 s   s   � | ]}|d  V  qdS )rT   Nr   r|  r   r   r   rf   x  s   € z9DistUpgradeQuirks._remove_uboot_on_rpi.<locals>.<genexpr>z!no u-boot removal performed in %srµ  rr   r   r¡  )r¶  r<   r=   r‰   ru   r›   r¢  r!   r’   r£  r¦   rE  r¤  )r   r¥  r¦  r§  rŸ   r¨  r³  r½  r  r©  rª  r«  r   )r°  r¥  r±  r¬  r²  r¼  r   rE   	  sj   ÿ
ÿ€ÿý,,ÿÿ€ÿ€ý&ÿÿ€ÿz&DistUpgradeQuirks._remove_uboot_on_rpiú/etc/netplanc                 C   s"  d}zdd l }W n ty   t d|¡ Y d S w t d| ¡D ]î}z,tj ||¡}t|ddd��}| 	¡ }|j
||jd�}W d   ƒ n1 sHw   Y  W n ty`   t d	||¡ Y  d S w d
}	z!|d d  ¡ D ]}
|
d d dkr‚d}	|
d= d|
v r‚|
d= qlW n	 ty�   Y q w |	s‘q z"|d }t|ddd��}| |¡ W d   ƒ n1 s­w   Y  W n tyÏ } zt d|||¡ W Y d }~ d S d }~ww z!t|ddd��}|j||d
d� W d   ƒ n1 sëw   Y  W q  t�y } zt d|||¡ W Y d }~ d S d }~ww d S )Nz�You may need to manually edit your netplan config and remove the line "driver: bcmgenet smsc95xx lan78xx". See LP: #1970761 for further detailsr   z!failed to import yaml library. %sz	%s/*.yamlre   rå   ræ   )ÚLoaderz.failed to open netplan configuration in %s; %sFÚnetworkÚ	ethernetsr­   r  zbcmgenet smsc95xx lan78xxTzset-namerµ  rr   z3unable to write netplan config backup to %s: %s; %s)Údefault_flow_stylez0unable to write new netplan config to %s: %s; %s)ÚyamlÚImportErrorr!   r’   rË   r<   r=   r‰   ru   r›   r†  Ú
SafeLoaderr¢  Úvaluesrû   rE  r¤  Údump)r   Únetplan_dirr¦  rÃ  Únetplan_config_fileÚnetplan_config_filenamerŸ   Úorig_contentÚnetplan_yamlÚfile_modifiedÚethÚnetplan_backup_filenamer«  r   r   r   rF   Ž  sŠ   ÿþÿÿþ€ÿý€ûÿÿÿ€þ€üÿ€þ€ü×z+DistUpgradeQuirks._remove_netplan_match_rpic              
   C   s¸  t  d¡ | jj}d|vrt  d¡ d S |d js t  d¡ d S zddlm} W n tyB } zt  d| ¡ W Y d }~d S d }~ww |ƒ }|j	 
¡ }|D ]}d |¡}||v rh|| jrht  d	 |¡¡  d S qMd }|D ]"}d
 |¡}	|	|v r�||	 jr�||	 jr�|}t  d |	|¡¡  nqm|d u r›t  d¡ d S d |¡}
|
|vrÆt  d |
¡¡ tdƒ}td||f ƒ}| j ||¡ | j ¡  d S t  d |
¡¡ ||
  ¡  | d d ¡ d S )Nz7running Quirks._test_and_fix_missing_nvidia_metapackagezubuntu-drivers-commonz&ubuntu-drivers-common not be availablez#ubuntu-drivers-common not installedr   )ÚNvidiaDetectionz&NvidiaDetection can not be imported %sznvidia-driver-{}zpackage {} detected, exit.zlibnvidia-gl-{}zGFound autoremovable package {}, assuming we're missing nvidia-driver-{}z-No autoremovable libnvidia-gl found, exiting.z*Package {} not available in the APT cache!z%NVIDIA driver metapackage unavailablea  Your system has the package libnvidia-gl-%s installed but the corresponding metapackage nvidia-driver-%s is not installed and is not available to be installed. The upgrade process was not able to automatically fix this issue and consequently the upgrade will now exit.z/Installing missing nvidia driver metapackage {})r!   r%   r   r8   r’   r;   ÚNvidiaDetector.nvidiadetectorrÐ  rÄ  ÚdriversÚkeysr¶  Úis_auto_removablerx   r   ry   rB  Úcommit)r   r8   rÐ  rÏ   ÚnvÚversionsrb   r  Úversion_to_fixÚ	nvidia_glÚmissing_metapackager”   r•   r   r   r   r:   É  sn   



€þ

€
ÿþ€

ÿû
ÿz1DistUpgradeQuirks._fix_missing_nvidia_metapackage)r  r_   )r�   )r›  )r¾  )8Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r+   r/   rB   rG   rH   rO   rP   rR   r]   r3   r}   r€   r�   r4   r˜   r5   r7   r6   r©   r9   r—   r¶   rº   rN   rK   rL   rM   rÅ   rJ   r?   r@   rC   r  r‡   rI   rˆ   r#  r6  rC  rH  rQ  r\  rQ   rm  rq  rw  rð   rD   rE   rF   r:   r   r   r   r   r   &   sp    .!)&/
@(!

/
0J 

3 
;r   )rJ  rÃ   rj   rË   r!   r<   rœ   r  rW   r   r   Úutilsr   ÚDistUpgradeGettextr   rx   rh   r   r   r   r   r   Ú<module>   s   