o S(e@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl m Z ddl mZGdddeZdS)N)PIPEPopen)get_arch)gettextc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?Z"d@dAZ#dBdCZ$dDdEZ%dFdGZ&dodIdJZ'dpdLdMZ(dNdOZ)dPdQZ*dRdSZ+dqdUdVZ,dWdXZ-dYdZZ.d[d\Z/d]d^Z0d_d`Z1dadbZ2dcddZ3drdfdgZ4drdhdiZ5dsdkdlZ6dmdnZ7dKS)tDistUpgradeQuirksz This class collects the various quirks handlers that can be hooked into to fix/work around issues that the individual releases have cCsd||_|j|_||_tddgtddd|_t|_ d|_ d|_ d|_ d|_ d|_d|_dS)Nunamez-rTstdoutuniversal_newlinesrF) controller_viewconfigrr communicatestriprrarchextra_snap_space_poke_snapstore_reachable _snap_list _from_version _to_version)selfr rr?/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeQuirks.py__init__-s"  zDistUpgradeQuirks.__init__cCs|jjr tddS|jdd}|jdd}d|}t||d}|dur1td||d||f}t||d}|durKtd||d ||f}t||d}|durgtd||dSdS) 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 modeNSourcesToFrom%szquirks: running %sz%s%sz from_%s%s)r _partialUpgradelogginginforgetgetattrdebug)r quirksName to_release from_releasefuncnamefuncrrrrun?s*       zDistUpgradeQuirks.runcCtddS)z3 run before the apt cache is opened the first time zrunning Quirks.PreCacheOpenNr!r%rrrr PreCacheOpenmzDistUpgradeQuirks.PreCacheOpencCstd||||||jj}| || d|vr1tddS|dj rFt j dsBt j drF||jrO|dSdS)z2 run after the apt cache is opened the first time z%running Quirks.jammyPostInitialUpdatesnapd'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_installedospathexists_checkStoreConnectivityr_calculateSnapSizeRequirementsrr8rrrjammyPostInitialUpdaters*       z(DistUpgradeQuirks.jammyPostInitialUpdatecCstd|jj}d|vrtddS|djr |jr |d|vr-|djr-|d|vr@|djrB|| dSdSdS)Nzrunning Quirks.jammyPostUpgrader1r2zubuntu-desktop-raspizlinux-firmware-raspi2) r!r%r r8r;r_replaceDebsAndSnaps_replace_fkms_overlay_remove_uboot_on_rpi_remove_netplan_match_rpirArrrjammyPostUpgrades$      z"DistUpgradeQuirks.jammyPostUpgradecCr,)z run after cleanup zrunning Quirks.PostCleanupNr-r.rrr PostCleanupr0zDistUpgradeQuirks.PostCleanupcCs>td||||||dS)Nzrunning Quirks.StartUpgrade)r!r% _applyPatches_removeOldApportCrashes_killUpdateNotifier_killKBluetooth_pokeScreensaver_stopDocvertConverterr.rrr StartUpgrades  zDistUpgradeQuirks.StartUpgradecCr,)z/ run right before calculating the dist-upgrade z"running Quirks.PreDistUpgradeCacheNr-r.rrrPreDistUpgradeCacher0z%DistUpgradeQuirks.PreDistUpgradeCachecCstd|dS)z( run after calculating the dist-upgrade z#running Quirks.PostDistUpgradeCacheN)r!r%_install_linux_metapackager.rrrPostDistUpgradeCaches  z&DistUpgradeQuirks.PostDistUpgradeCachecCsjt}z tjddgtjdd}Wn ty|YSw|ddD] }|r2||dq%|S)z8 return a set of pci ids of the system (using lspci -n) lspciz-nTr r )set subprocessrrOSErrorrsplitadd)rrSplinerrr _get_pci_idss zDistUpgradeQuirks._get_pci_idscst}z|djjd_|djjd_WdSt yYt fdd| dDjjd_t fdd| dDjjd_YdSw)Nrrc3$|] }|jjjkr|jVqdSN)seriesr fromDistversion.0rr.rr z=DistUpgradeQuirks._get_from_and_to_version..objectc3r^r_)r`r toDistrbrcr.rrrfrg) distro_infoUbuntuDistroInforbr rarYrrirAttributeErrornextget_all)rdirr.rr3s(  z*DistUpgradeQuirks._get_from_and_to_versioncCsd}tj|r dtjvrdStjgdttjdd}|dkr't ddSt|g}t d||f|dkrN|j t d t d }|sP|j dSdSdS) Nz/usr/lib/nux/unity_support_testDISPLAY)psz-Czunity-panel-servicew)r rz5_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.aSRunning 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>environrWcallopendevnullr!r%r askYesNoQuestion_r abort)rUNITY_SUPPORT_TEST return_coderesrrr#_test_and_warn_for_unity_3d_supports6     z5DistUpgradeQuirks._test_and_warn_for_unity_3d_supportcCsNgd}|}t||r#|jtdtd}|s%|jdSdSdS)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.zThe 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 rwrxr ry)r I8XX_PCI_IDSrSr|rrr_test_and_warn_on_i8xxs  z(DistUpgradeQuirks._test_and_warn_on_i8xxcCs|drJ|dsL|jtdtd}|s|jgd}tdd ||jj dd}|D]}| |q4|jj ddd |d Sd Sd 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.zThis 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?)zxorg-driver-fglrxzxorg-driver-fglrx-envyzfglrx-kernel-sourcezfglrx-amdccclezxorg-driver-fglrx-dev libamdxvba1z remove %s, DistroPostUpgradePurge,N)_checkVideoDriver_supportInModaliasesr rwrxr ryr!r%joinrgetlistappendrV)rr|removalspostupgradepurgeremoverrr'_test_and_warn_on_dropped_fglrx_supports*    z9DistUpgradeQuirks._test_and_warn_on_dropped_fglrx_supportcCsl|jdkrd}n|jdkrd}|jdkr4tdtd}td|j|f}|j|||jd Sd S) z} Test and fail if the package architecture is i386 as we have dropped support for this architecture. z18.04z April 2023z19.04z January 2020i386zapt architecture is i386'Sorry, no more upgrades for this systemzThere will not be any further Ubuntu releases for this system's 'i386' architecture. Updates for Ubuntu %s will continue until %s.N)rrr!errorrxr r ry)r updates_endsummarymsgrrrr4=s    z(DistUpgradeQuirks._test_and_fail_on_i386cCs>|jdkr|s|jtdtd|jdSdSdS)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 CPUzYour 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 rrxr ryr.rrr_test_and_fail_on_non_arm_v6Qs  z.DistUpgradeQuirks._test_and_fail_on_non_arm_v6cCsPdD]#}tj|r%tdtd}td|}|j|||jqdS)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/aufszDocker config uses aufszISorry, this storage driver is not supported in kernels for newer releaseszThere 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!rrxr r ry)raufs_dirrrrrrr5cs   z(DistUpgradeQuirks._test_and_fail_on_aufsc CstdD]U}|dvr qttjd|=}|}td|tjrKt dt d}t ddt d}|j |||j  Wd d SWd n1sUwYqd 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)zcommon-accountz common-authzcommon-passwordzcommon-sessionzcommon-session-noninteractivez^[^#]*pam_tallyzpam_tally* in usezrrurrrr)rrrrrrrs     zDistUpgradeQuirks._checkArmCPUcCsZtdtjdstddStd }|}Wd|S1s&wY|S)z read /sys/class/dmi/id/sys_vendor in case there are system specific issues with upgrading e.g LP: #1928434 zchecking for system vendorz/sys/class/dmi/id/sys_vendorz(cannot open /sys/class/dmi/id/sys_vendorrN)r!r%r<r=r>rrur)rrvendorrrr_readDMIVendors      z DistUpgradeQuirks._readDMIVendorcC,tjdrtdtddgdSdS)z, /etc/init.d/apparmor stop (see bug #559433)z/etc/init.d/apparmorz/etc/init.d/apparmor stopstopNr<r=r>r!r%rWrtr.rrr _stopApparmor  zDistUpgradeQuirks._stopApparmorcCr)z5 /etc/init.d/docvert-converter stop (see bug #450569)z/etc/init.d/docvert-converterz"/etc/init.d/docvert-converter stoprNrr.rrrrN#rz'DistUpgradeQuirks._stopDocvertConvertercC,tjdrtdtgddSdS)zkill update-notifier/usr/bin/killallzkilling update-notifier)killall-qzupdate-notifierNrr.rrrrK)s  z%DistUpgradeQuirks._killUpdateNotifiercCr)z3killall kblueplugd kbluetooth (riddel requested it)rzkilling kblueplugd kbluetooth4)rr kblueplugd kbluetooth4Nrr.rrrrL0rz!DistUpgradeQuirks._killKBluetoothc Cstjdr>tjdr@tdd}|d7}|d7}ztj|dd|_ t |j WdSt tfy=td YdSwdSdS) Nz/usr/bin/xdg-screensaverrpz$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>rsr#r!r%rWrratexitregister_stopPokeScreensaverrX ValueError exception)rcmdrrrrM6s   z"DistUpgradeQuirks._pokeScreensavercCsNd}|jdur%z |j|j}Wnty!tdYnwd|_|S)NFzfailed to stop screensaver poke)r terminatewaitrXr!rrrrrrCs   z&DistUpgradeQuirks._stopPokeScreensaverc Csvz dD]}td|D]}td||ft|q qWdSty:}ztd|WYd}~dSd}~ww)z: remove old apport crash files and whoopsie control files )z.crashz.uploadz .uploadedz/var/crash/*%szremoving old %s file '%s'z+error during unlink of old crash files (%s)N)globr!r%r<unlink Exceptionr)rextrerrrrJNs z)DistUpgradeQuirks._removeOldApportCrashescCsZd}tj}d|d<tgdtt|dd}td|dtjr'd|_ d Std |dtjrxt d d}|j j }d |vrU|d jrU|d jjd sUt dd}|rltd}td}|j |||j n6|jtdtd}n*d|dvrt d|jtdtd}nd|dvrd}t dnt d|s|j d Sd S)z: check for connectivity to the snap store to install snapsFzC.UTF-8LANG)snapr% connectivityT)r stderrenvr z ^ \* PASSrNz^ \*.*unreachablezNo snap store connectivitylxdz1:zlxd is installedz#Connection to the Snap Store failedaYou 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.zConnection to Snap Store failedzYour 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?zerror: unknown commandrz snap debug command not availablezOutdated snapd packagezYour 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?zerror: access deniedzNot running as root!z-Unhandled error connecting to the snap store.)r<rscopyrrrrrrrr!rr r8r; candidaterb startswithrxr ryrw)rr|snap_env connectedold_lxd_deb_installedr8rrrrrr?XsX           z)DistUpgradeQuirks._checkStoreConnectivityc Cs0ddl}ddl}ddlm}||jtd|j D]v\}}|ddkr*qdd|d|d d }g|gd }|j j d t | |d dd}|dd|dd|d|jz|j |} || } t| ddddd} Wnt|tfytd|Yqw|j| 7_qdS)Nr)URLErrorz"Calculating snap size requirementscommandinstallzupgrade-size-checkdownloadsnap-idchannel)z instance-keyactionrr)contextactionsz)https://api.snapcraft.io/v2/snaps/refreshutf-8encoding)urldatazSnap-Device-Series16z Content-typezapplication/jsonzSnap-Device-ArchitectureresultsrsizezFailed fetching size of snap %s)jsonurllib.request urllib.errorr_prepare_snap_replacement_datar updateStatusrxritemsrequestRequestbytesdumps add_headerrurlopenrloadsintKeyErrorrr!r%r) rrurllibrr snap_objectrrreqresponser"rrrrr@sB      z0DistUpgradeQuirks._calculateSnapSizeRequirementsc Cs>|jtd|jD]\}}|d}|dkr-|jtd|d|d|d|g}n'|dkrA|jtd |d||g}n|jtd |d|d|d|g}z|jtj|tjd d }|jWntj y|t d ||fYq w|j dkrt d||f|dkr|dr|j j|dq dS)z? install a snap and mark its corresponding package for removal zProcessing snap replacementsrrefreshzrefreshing snap %srz --channelrrzremoving snap %szinstalling snap %sT)r checkz%s of snap %s failedrz%s of snap %s succeededrdebN)r rrxrrrrWr+rCalledProcessErrorr!r% returncoder forced_obsoletesr)rrrr popenargsprocrrrrCsB     z&DistUpgradeQuirks._replaceDebsAndSnapscCstdd}td }|}Wdn1swYtd|tjr)d}|sFtdtd}td }|j |||j dSdS) z check PAE in /proc/cpuinfo _checkPaerrNz^flags\s+:.* pae rzno pae in /proc/cpuinfozPAE not enabledzYour 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%rurrrrrrxr r ry)rpaerrrrrrrrs    zDistUpgradeQuirks._checkPaecCsd}tj|s dSt| }|}Wdn1swY|D]}|dd}|dr@| d|r@dSq$dS) z2 check if the given driver is in use in xorg.conf z/etc/X11/xorg.confFN#rdriverz"%s"T) r<r=r>ru readlinesrYrlowerrendswith)rrXORGrlinesr\srrrrs    z#DistUpgradeQuirks._checkVideoDriver ./patchesc Csntj|s tddSt|D]}d|vr td|qtd||dd\}}}|dd}td |||ftj|sNtd |qt }t |d }| | Wdn1siwY| |kr|td |q| |krtd |qddlm} z| |tj|||td|Wqtytd|YqwdS)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.zskipping '%s' (no '.')z'check if patch '%s' needs to be appliedrUrx/ztarget for '%s' is '%s' -> '%s'ztarget '%s' does not existrbz%already at target hash, skipping '%s'z(unexpected target md5sum, skipping: '%s'r)patchzapplied '%s' successfullyzed failed for '%s')r<r=r>r!r%rrsplitreplacehashlibmd5ruupdater hexdigestrDistUpgradePatcherrrr"rr) rpatchdirr encoded_pathmd5sum result_md5sumr=rfdrrrrrIsH         zDistUpgradeQuirks._applyPatchesNc Cs|s|}||jjvs|jj|jstddS|jj|}||jjD].\}}|D]'}t d|}|rTd| d| df}| |vrTt d|dSq-q't d |dS) 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) zcan not find '%s' in cacheFzpci:v0000(.+)d0000(.+)sv.*z%s:%srrUz%found system pciid '%s' in modaliasesTz4checking for %s support in modaliases but none found) r]r r8rr!r!_parse_modaliases_from_pkg_headerrecordrrgroupr r%) rpkgnamerSrmodule pciid_listpciidmmatchidrrrr3s2         z&DistUpgradeQuirks._supportInModaliasescCsdd|vrgSg}|ddD] }|d}|sq|d\}}||dd|dDfq|S)z. return a list of (module1, (pciid, ...), ...) Modaliases)r(cSg|]}|qSr)r)rdxrrr ]zGDistUpgradeQuirks._parse_modaliases_from_pkg_header..r)rYrr)r pkgrecordmodulesr*r'pciidsrrrr#Rs  z3DistUpgradeQuirks._parse_modaliases_from_pkg_headercCstd|jj}d|vrtddS|djs%|djs%tddSz4ddl}|j}|D]}d|j vrAtdWdSq1t d| d d |jj d gd | WdStyhtd YdSw)N_add_extras_repositoryzubuntu-extras-keyringz-no ubuntu-extras-keyring, no need to add repoz2ubuntu-extras-keyring not installed/marked_installrzextras.ubuntu.comz*found extras.ubuntu.com, no need to add itz/no extras.ubuntu.com, adding it to sources.listrzhttp://extras.ubuntu.com/ubuntumainz!Third party developers repositoryzerror adding extras.ubuntu.com)r!r%r r8r installedaptsources.sourceslist sourceslist SourcesListurir"rZrisaverr)rr8 aptsourcessourcesentryrrrr6`s6          z(DistUpgradeQuirks._add_extras_repositorycCspz(|jj}d|vr |djr#d|vr&td|ddWdSWdSWdSWdSty7tdYdSw)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) zfoomatic-db-gutenprintzijsgutenprint-ppdszinstalling ijsgutenprint-ppdsz1foomatic-db-gutenprint -> ijsgutenprint-ppds rulez_gutenprint_fixup failedN)r r8 marked_deleter!r" mark_installrrrArrr_gutenprint_fixupzs    z#DistUpgradeQuirks._gutenprint_fixuprcCstd}tj|s8ztdWn tyYnwt|d}|d|WddS1s1wYdSdS)z5 enable multiarch via /etc/dpkg/dpkg.cfg.d/multiarch z/etc/dpkg/dpkg.cfg.d/multiarchz/etc/dpkg/dpkg.cfg.d/rrzforeign-architecture %s N)r<r=r>makedirsrXruwrite)r foreign_archcfgrrrr_enable_multiarchs   "z#DistUpgradeQuirks._enable_multiarchcCsztd}||}||}|r+|r+d|d|df}d|d|df}td||ftj||dkS)z# copied from ubuntu-drivers common z(.+)-([0-9]+)-(.+)%s-%srrUzComparing %s with %sr) rrrr%r!r%aptapt_pkgversion_compare)rterm1term2rmatch1match2rrr_is_greater_thans     z"DistUpgradeQuirks._is_greater_thanc Cs|rdpd}td}td}d}d}|D]V}d|jvrld|jvrl|js(|jrl||j} | rl|jjd} d| d | d f} | | |rl| }|| } d | vrc| rcd || d | d f}qd|| d f}q|S)zb Get the linux headers or linux metapackage copied from ubuntu-drivers-common z-headersrzlinux-image-(.+)-([0-9]+)-(.+)z linux-(.+)z linux-imageextraSourcerIrrUz-lts-z linux%s-%s-%sz linux%s-%s) rrrr;rrrr$r%rQ) rr8headerssuffixrsource_pattern metapackagerbrrsourcecurrent_version match_sourcerrr_get_linux_metapackagesD         z(DistUpgradeQuirks._get_linux_metapackagecCs^|jj}||d}||vrtd|dS||js-td|d}|||dSdS)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 r8r\r!r"r;rB)rr8linux_metapackagereasonrrrrQs  z,DistUpgradeQuirks._install_linux_metapackagec sd}|jjdD]U}|D]P\}}td||f|vr\|jr\|rAtd||fd|}j||d|dsAtd|td ||fd |}j||dd s\td |q qtj}|D]^\}}|vrĈ|jr|r|vrfd d|D}t d}t d||d |f} t| |j || |jn||||||||qf|dS)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)zpython-minimalzpython-is-python2)z python-devzpython-dev-is-python2)z libpython-devN)zlibpython-stdlibN)z libpython-dbgN)FTzchecking for %s (auto_inst=%s)z&installing %s because %s was installedz%s was installed on the systemF)auto_fix auto_instzfailed to install %sz)removing %s because %s is being installedz#%s is being installed on the system)r_zfailed to remove %scs&g|]\}}|vr|jr|qSr)r;)rdoldnewr8rrr1s  z@DistUpgradeQuirks._install_python_is_python2..zuniverse component not enabledaYou 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 %srN)r r8r!r"r;rB mark_removerJProblemResolverrxr_stopAptResolverLogr rryclearprotectrresolve) r replacementsr`rarbr^solverold_instrrrrcr_install_python_is_python2sZ         z,DistUpgradeQuirks._install_python_is_python2cCsH|jjs tjjds"d}|d7}t|tjjdddSdSdS)z] ensure that on a desktop install recommends are installed (LP: #759262) zApt::Install-Recommendsz%Apt::Install-Recommends was disabled,z! enabling it just for the upgrade1N) r serverModerJrKrfind_br!rrV)rrrrr+ensure_recommends_are_installed_on_desktops3s z=DistUpgradeQuirks.ensure_recommends_are_installed_on_desktopscCsT|dd}t|ts|g}|D]}||jjvrq|r%|jj|jdur%qdSdS)z Helper function that checks if the given deb2snap entry has at least one metapkg which is installed on the system. metapkgNFT)r# isinstancelistr r8r;)rdeb2snap_entry metapkg_listrrrrr_is_deb2snap_metapkg_installed>s   z0DistUpgradeQuirks._is_deb2snap_metapkg_installedc CsBddl}i|_d|j}d|j}i}i}zmtjtjt}t |dd}| |}| |dD]'} |d| } | | sBq4| dd} | d|} | d |} | | | f|| <q4|d D] } |d | }| dd} | |stq`| d|} | | f|| <q`Wnty}z td |WYd}~nd}~wwd }tjd dgdtjd}|rdd|ddddD}|D]} | |vs| |vrqd||f|| <q|jtd|D]\} \} }}i}tjd d| gdtjd}|jtd|dtjr&td| td||dtjs!td| qd|d<n=|jj }| rB| |vs8|| j!sBtd| | fqtd|d}|sUtd | qd!|d<| |d<|d|d"<||d#<||j| <q|D]\} \} }i}tjd d| gdtjd}|jtd|dtjrtd| td||dtjstd| qqd$|d<tjd d%| gdtjd}|j|ddD]D}|}t"|d&krq|d}|d'}|#| d(r|d(d}|d)kr||vrtd*| |fd|d<d+|d#<nq||j| <qq|jS),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). rNzstable/ubuntu-%sz/deb2snap.jsonreseededr from_channel to_channelunseededz%error reading deb2snap.json file (%s)rrrtT)r r cSsg|]}|dqS)r)rYrdr\rrrr1}szDDistUpgradeQuirks._prepare_snap_replacement_data..rTrzChecking for installed snapsr"z ^installed: zSnap %s is installedz^tracking:.*%sz+Snap %s is not tracking the release channelrrzFDeb package %s is not installed. Skipping snap package %s installationzsnap-id:\s*(\w*)z'Could not parse snap-id for the %s snaprrrr connectionsrU:-z9Snap %s is being used by %s. Switching it to stable trackstable)$rrrrr<r=dirnameabspath__file__ruloadcloserwr#rr!rrWrrrrYr rrxrrrrrr%r r8r;lenr)rrryrz seeded_snapsunseeded_snaps current_pathd2s_filed2srseedr from_chanto_chanunseedr snap_listsnaps_installedr snap_infor8rconnsconn conn_colsplugslot plug_snaprrrrQs                               z0DistUpgradeQuirks._prepare_snap_replacement_data/boot/firmwarec Csd}z$tj|d}t|ddd }|}Wdn1s wYWnty7td||YdSwddd |jd d D}||krRt d |dSz%tj|d }t|ddd }| |Wdn1sqwYWnt y}ztd|||WYd}~dSd}~wwz!t|ddd}| |WdWdS1swYWdSt y}ztd|||WYd}~dSd}~ww)NzfYou may need to replace the vc4-fkms-v3d overlay with vc4-kms-v3d in config.txt on your boot partition config.txtrerr+failed to open boot configuration in %s; %srcssP|]#}|drd||ddn|ds|dkr"d|n|VqdS)zdtoverlay=vc4-fkms-v3dz0# changed by do-release-upgrade (LP: #1923673) #zdtoverlay=vc4-kms-v3dzgpu_mem=z start_x=1z1# disabled by do-release-upgrade (LP: #1923673) #N)rrrstripr|rrrrfs    z:DistUpgradeQuirks._replace_fkms_overlay..T)keependsz3no fkms overlay or camera firmware line found in %szconfig.txt.distUpgraderr0unable to write boot config backup to %s: %s; %s-unable to write new boot config to %s: %s; %s) r<r=rrurFileNotFoundErrorr!r splitlinesrrEIOError) rboot_dirfailure_actionboot_config_filenamer boot_config new_configboot_backup_filenameexcrrrrDs^      &z'DistUpgradeQuirks._replace_fkms_overlayc sddd}|jd}dddz$tjd}t|d d d  }|}Wdn1s0wYWntyGtd ||YdSwfd d}fdd}dd| D}|||}ddd|D} | |kr}t d|dSz"|d} t| dd d  }| |Wdn1swYWnt y} ztd| | |WYd} ~ dSd} ~ wwz!t|dd d }| | WdWdS1swYWdSt y} ztd|| |WYd} ~ dSd} ~ ww)Nzkernel=vmlinuzz!initramfs initrd.img followkernelzYou 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)rrerrrcsg}d}}|D]J}|dkr'|||s&|||d}q|dr9||d|q|drMd}||d|q||q|rm|sk||d|||S|S)NFz[all]Tzdevice_tree_address=r zkernel=uboot_rpi_)rr)rresult removed_uboot added_kernelr\) added_prefix change_prefixr kernel_linerr replace_uboots6             z=DistUpgradeQuirks._remove_uboot_on_rpi..replace_ubootc s&g}d}d}|D]}|dr|rqd}|dvrd}|jddd}||tj|}d}t|ddd }|D]}|drG|rGq=d}||q=Wdn1s[wY|d }zt ||Wqt y}zt d |||WYd}~qd}~ww||q|r|S|S) NTFr )zinclude syscfg.txtzinclude usercfg.txtr)maxsplitrerr .distUpgradez7failed to move included configuration from %s to %s; %s) rrYrformatr<r=rrurrenamerr!r) rr skip_commentsfound_includesr\included_filenamertarget_filenamer)r merge_prefixrrmerge_includesJsJ z>DistUpgradeQuirks._remove_uboot_on_rpi..merge_includescSr/r)rr|rrrr1vr2z:DistUpgradeQuirks._remove_uboot_on_rpi..rcss|]}|dVqdS)rTNrr|rrrrfxsz9DistUpgradeQuirks._remove_uboot_on_rpi..z!no u-boot removal performed in %srrrrr) rr<r=rrurrr!rrrrEr) rrrrrrrrrrrrr)rrrrrrrrE sj   ,,   &z&DistUpgradeQuirks._remove_uboot_on_rpi /etc/netplanc Cs"d}zddl}Wntytd|YdSwtd|D]}z,tj||}t|ddd}| }|j ||j d}Wdn1sHwYWnt y`td ||YdSwd } z!|d d  D]} | d ddkrd} | d =d| vr| d=qlWn tyYq w| sq z"|d} t| ddd }||Wdn1swYWnty} ztd| | |WYd} ~ dSd} ~ wwz!t|ddd}|j||d dWdn1swYWq ty} ztd|| |WYd} ~ dSd} ~ wwdS)NzYou may need to manually edit your netplan config and remove the line "driver: bcmgenet smsc95xx lan78xx". See LP: #1970761 for further detailsrz!failed to import yaml library. %sz %s/*.yamlrerr)Loaderz.failed to open netplan configuration in %s; %sFnetwork ethernetsrr zbcmgenet smsc95xx lan78xxTzset-namerrrz3unable to write netplan config backup to %s: %s; %s)default_flow_stylez0unable to write new netplan config to %s: %s; %s)yaml ImportErrorr!rrr<r=rrurr SafeLoaderrvaluesrrErdump) r netplan_dirrrnetplan_config_filenetplan_config_filenamer orig_content netplan_yaml file_modifiedethnetplan_backup_filenamerrrrrFs      z+DistUpgradeQuirks._remove_netplan_match_rpic Cstd|jj}d|vrtddS|djs tddSzddlm}WntyB}ztd|WYd}~dSd}~ww|}|j }|D]}d |}||vrh||jrhtd |dSqMd}|D]"}d |} | |vr|| jr|| j r|}td | |nqm|durtd dSd |} | |vrtd | t d} t d||f} |j| | |jdStd | || |dddS)Nz7running Quirks._test_and_fix_missing_nvidia_metapackagezubuntu-drivers-commonz&ubuntu-drivers-common not be availablez#ubuntu-drivers-common not installedr)NvidiaDetectionz&NvidiaDetection can not be imported %sznvidia-driver-{}zpackage {} detected, exit.zlibnvidia-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 r8rr;NvidiaDetector.nvidiadetectorrrdriverskeysris_auto_removablerxr ryrBcommit) rr8rrnvversionsrbr version_to_fix nvidia_glmissing_metapackagerrrrrr:sn           z1DistUpgradeQuirks._fix_missing_nvidia_metapackage)rr_)r)r)r)8__name__ __module__ __qualname____doc__rr+r/rBrGrHrOrPrRr]r3r}rrr4rr5r7r6rr9rrrrNrKrLrMrrJr?r@rCrrrIrr#r6rCrHrQr\rQrmrqrwrrDrErFr:rrrrr&sp.  !)&/    @(!  /  0J   3  ;r)rJrrjrr!r<rrrWrrutilsrDistUpgradeGettextrrxrhrrrrrs