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	Z	d dl
Z
d dlZd dlmZ d dlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZ d dlmZ d dlm Z  dd	l!m"Z" dd
l#m$Z$ ddl%m&Z& ddl'm'Z' d dl(m)Z) d dl(m*Z* e)j+e*_+d dl,m-Z-m.Z. ddl/m0Z0m1Z1 ddl2m3Z4 ddl2m5Z5 d dl3Z3ddl#m6Z6m7Z7m8Z8 ddl9m:Z: dZ;dd„ Z<G dd„ de=ƒZ>G dd„ de?ƒZ@eAdkrôddlBmBZB ejCejDd eBƒ ZEe@eEƒZFeF G¡  eF H¡  dS dS )é    N)ÚNoOptionError)ÚConfigParseré   )Úget)	Úcountry_mirrorÚurl_downloadableÚcheck_and_fix_xbitÚget_archÚiptables_activeÚinside_chrootÚ)get_string_with_no_auth_from_source_entryÚis_child_of_process_nameÚinhibit_sleep)ÚTemplate)Úurlsplit)ÚStep)ÚMyCache)ÚDistUpgradeConfig)ÚDistUpgradeQuirks)Údistinfo)Úsourceslist)ÚSourcesListÚ	is_mirror)Ú
get_distroÚNoDistroTemplateException)Úgettext)Úngettext)ÚCacheExceptionDpkgInterruptedÚCacheExceptionLockingFailedÚNotEnoughFreeSpaceError)Ú
run_apportz/var/run/reboot-requiredc                 C   s4   g d¢}z|  | ¡W S  ty   t|ƒd  Y S w )zB key() function for sorted to ensure "correct" component ordering )ÚmainÚ
restrictedÚuniverseÚ
multiverser   )ÚindexÚ
ValueErrorÚlen)ÚaÚordering© r*   úC/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.pyÚcomponent_ordering_keyN   s   ýr,   c                   @   s   e Zd ZdS )ÚNoBackportsFoundExceptionN)Ú__name__Ú
__module__Ú__qualname__r*   r*   r*   r+   r-   Y   s    r-   c                   @   sŒ  e Zd ZdZdadd„Zdbdd„Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdcdd„Zdd„ Zdd„ Zdd„ Zdddd „Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Zd=d>„ Z d?d@„ Z!dAdB„ Z"dCdD„ Z#dEdF„ Z$dGdH„ Z%dIdJ„ Z&dKdL„ Z'dedMdN„Z(dedOdP„Z)dQdR„ Z*dSdT„ Z+dUdV„ Z,dWdX„ Z-dYdZ„ Z.d[d\„ Z/d]d^„ Z0d_d`„ Z1dS )fÚDistUpgradeControllerz3 this is the controller that does most of the work Nc                 C   sŽ  d}|d ks
|dkrt  ¡ }t j |d¡}|| _|| _t d|¡ t d¡ t	 
d|jj ¡ || _| j tdƒ¡ d | _d | _| jrI| jjd krMd| _n| jj| _t|ƒ| _d| j dd	¡ | _| j d
¡ | j d
dt| jƒ¡ | j d
dd¡ | jr‰| jjr‰| j d
dd¡ | j dd¡| _| j dd¡| _| j dd¡| _tƒ | _ dt j!vr¶t	 
d¡ t"j dd¡ d| _#t$| | jƒ| _%t&ƒ | _'dt j!d< dt j!d< dt  ¡ d t j!d f t j!d< t(dƒ | j )dd ¡}t"j d!t|ƒ¡ t"j d"td#ƒ¡ t"j d$td%ƒ¡ t"j d&d'¡ t"j d(d'¡ t"j d)d*¡ | j *d+d,¡| _+| j ,dd-¡| _-g | _.| j /d.¡r?d/d0„ | j 0d.¡D ƒ| _.d1| _1d | _2d S )2Nz/usr/share/locale/Ú.Úmoúubuntu-release-upgraderzUsing '%s' viewzReading cacheTÚFilesÚ	BackupExtÚOptionsÚwithNetworkÚ
devReleaseÚFalseÚTrueÚSourcesÚFromÚToÚValidOriginÚ"RELEASE_UPGRADE_NO_FORCE_OVERWRITEzenable dpkg --force-overwritezDPkg::Options::z--force-overwriteFÚ1ÚRELEASE_UPGRADE_IN_PROGRESSÚPYCENTRAL_FORCE_OVERWRITEz%s:%sz	/importedÚPATHz./imported/invoke-rc.dÚNetworkÚ
MaxRetrieszAcquire::RetrieszDpkg::MaxArgsi   zDpkg::MaxArgBytesi   zAcquire::http::TimeoutÚ20zAcquire::ftp::TimeoutzApt::Get::List-CleanupÚfalseÚDistroÚForcedObsoletesÚValidMirrorsÚThirdPartyMirrorsc                 S   s   g | ]}|d  ‘qS )r   r*   )Ú.0Úpairr*   r*   r+   Ú
<listcomp>¸   s    z2DistUpgradeController.__init__.<locals>.<listcomp>ií  )3ÚosÚgetcwdÚpathÚjoinÚdatadirÚoptionsr   ÚbindtextdomainÚ
textdomainÚloggingÚdebugÚ	__class__r.   Ú_viewÚupdateStatusÚ_ÚcacheÚfetcherr8   Ú
useNetworkr   Úconfigr   Úsources_backup_extÚadd_sectionÚsetÚstrÚdevel_releaseÚfromDistÚtoDistÚoriginr	   ÚarchÚenvironÚapt_pkgÚ_partialUpgrader   Úquirksr   Úinhibitor_fdr   ÚgetintÚgetlistÚforced_obsoletesÚgetListFromFileÚvalid_mirrorsÚvalid_3p_mirrorsÚhas_sectionÚitemsÚ_aptCronJobPermsÚ_session_bus)ÚselfÚdistUpgradeViewrU   rT   Ú	localedirÚ
maxRetriesr*   r*   r+   Ú__init__`   sp   






ÿ
ÿ
zDistUpgradeController.__init__TFc              
   C   sâ   t  d¡ | jd u r| j d¡ n
| j ¡  | j ¡  d}d}	 z|  |¡W S  tyo } z=|d7 }| j	 
¡  t d¡ t  d| ¡ ||kret  d	| ¡ | j	 td
ƒtdƒ¡ |r`|  ¡  nt d¡ W Y d }~nd }~ww q )NzopenCache()ÚPreCacheOpené   r   Tr   çš™™™™™¹?z'failed to lock the cache, retrying (%i)zCache can not be locked (%s)zUnable to get exclusive lockzThis usually means that another package management application (like apt-get or aptitude) already running. Please close that application first.)rX   rY   r^   rn   ÚrunÚrelease_lockÚunlock_lists_dirÚ
_openCacher   r[   ÚprocessEventsÚtimeÚsleepÚerrorr]   ÚabortÚsysÚexit)rz   ÚlockÚrestore_sources_list_on_failÚMAX_LOCK_RETRIESÚ
lock_retryÚer*   r*   r+   Ú	openCacheÂ   s8   





ÿÿ

€íüzDistUpgradeController.openCachec              	   C   s¸   zt | j| j| j| j ¡ |ƒ| _| j| _W n5 tyJ   t 	d¡ g d¢}t
j d¡dkr2| d¡ | j ¡  |¡ t | j| j| j| j ¡ ƒ| _Y nw | j| j_t dt| jƒ ¡ d S )Nz-dpkg interrupted, calling dpkg --configure -a©ú/usr/bin/dpkgz--configurez-aÚDEBIAN_FRONTENDÚnoninteractiveú--force-confoldz/openCache(), new cache size %i)r   ra   r[   rn   ÚgetOpCacheProgressr^   Ú	apt_cacher   rX   ÚwarningrP   rk   r   ÚappendÚgetTerminalÚcallrm   ÚpartialUpgraderY   r'   )rz   r   Úcmdr*   r*   r+   r…   å   s,   ü


ýú

z DistUpgradeController._openCachec                 C   s$   | j  dd¡}| jjj|v rdS dS )z¹
      Returns True if this view support upgrades over ssh.
      In theory all views should support it, but for savety
      we do only allow text ssh upgrades (see LP: #322482)
      ÚViewÚ
SupportSSHTF)ra   rq   r[   rZ   r.   )rz   Ú	supportedr*   r*   r+   Ú_viewSupportsSSHý   s   z&DistUpgradeController._viewSupportsSSHc                 C   sú   t j d¡}t j |¡s{t j d¡r{tdƒr{|  ¡ s1t d¡ | j	 t
dƒt
dƒ¡ t d¡ dS d	}| j	 t
d
ƒt
dƒ| ¡}|dkrIt d¡ t ddd| dt|ƒg¡}|dkr{t
dƒ}t
dƒ| }tƒ rtd| }|t
dƒ| 7 }| j	 ||¡ dS )zß this will check for server mode and if we run over ssh.
            if this is the case, we will ask and spawn a additional
            daemon (to be sure we have a spare one around in case
            of trouble)
        z"/var/run/release-upgrader-sshd.pidz/procÚsshdzupgrade over ssh not allowedz.Upgrading over remote connection not supportedzÓYou are running the upgrade over a remote ssh connection with a frontend that does not support this. Please try a text mode upgrade with 'do-release-upgrade'.

The upgrade will abort now. Please try without ssh.r   Fiþ  zContinue running under SSH?a  This session appears to be running under ssh. It is not recommended to perform a upgrade over ssh currently because in case of failure it is harder to recover.

If you continue, an additional ssh daemon will be started at port '%s'.
Do you want to continue?z/usr/sbin/sshdz-oz
PidFile=%sz-pr   zStarting additional sshdz¶To make recovery in case of failure easier, an additional sshd will be started on port '%s'. If anything goes wrong with the running ssh you can still connect to the additional one.
z-iptables -I INPUT -p tcp --dport %s -j ACCEPTz¦If you run a firewall, you may need to temporarily open this port. As this is potentially dangerous it's not done automatically. You can open the port with e.g.:
'%s'T)rP   rR   rS   ÚexistsÚisdirr   r£   rX   r‰   r[   r]   r‹   rŒ   ÚaskYesNoQuestionÚ
subprocessr   re   r
   Úinformation)rz   ÚpidfileÚportÚresÚsummaryÚdescrrŸ   r*   r*   r+   Ú	_sshMagic  sP   
ÿþ
ÿ

úþ

þüÿüzDistUpgradeController._sshMagicc                 C   sÄ   ddl m} ddlm} d}| jdks"| jdks"| jdks"| jdkr$d	}|d|d
}| j ¡  |j d¡s@| j ¡  |j d¡r5|jdu rLt	 
d¡ dS | j ¡ }||j|| j| jd}| ¡  dS )zž this is a helper that is run if we are started from a CD
            and we have network - we will then try to fetch a update
            of ourself
        r   )ÚMetaReleaseCore)ÚDistUpgradeFetcherSelfFÚdapperÚhardyÚlucidÚpreciseT)ÚuseDevelopmentReleaseÚforceLTSr   NzNo new dist found)Únew_distÚprogressrU   Úview)ÚMetaReleaser°   r±   Úreleaser[   r†   Ú
downloadedÚwaitr¸   rX   r‰   ÚgetAcquireProgressrU   r‚   )rz   r°   r±   r·   Úmr¹   r_   r*   r*   r+   Ú_tryUpdateSelfC  s2   



ÿ

ÿ


ýz$DistUpgradeController._tryUpdateSelfc           
      C   s0  t  d¡ dg}|D ]‹\}}d| }tj |¡r•tƒ }t|ƒ}| |¡ W d  ƒ n1 s/w   Y  z| dd¡}W n t	yP   t  d||f ¡ Y  dS w z
tj 
d	| ¡}W n tyv }	 zt  d
|	 ¡ W Y d}	~	 dS d}	~	ww ||tj d|¡fvr•t  d|||tj d|¡f ¡  dS q
dS )zº check that /usr/bin/python3 points to the default python version.
            Users tend to modify this symlink, which breaks stuff in obscure
            ways (Ubuntu #75557).
        z_pythonSymlinkCheck run)Úpython3rÂ   z/usr/share/%s/debian_defaultsNÚDEFAULTzdefault-versionz'no default version for %s found in '%s'Fz/usr/bin/%szos.path.realpath failed (%s)z/usr/binz8%s symlink points to: '%s', but expected is '%s' or '%s'T)rX   rY   rP   rR   r¥   ÚSafeConfigParserÚopenÚreadfpr   r   ÚrealpathÚOSErrorr‰   rS   )
rz   Úbinaries_and_dirnamesÚbinaryÚdirnameÚdebian_defaultsra   ÚfÚexpected_defaultÚfs_default_versionr‘   r*   r*   r+   Ú_pythonSymlinkCheckb  s>   

ÿÿý€þÿ€z)DistUpgradeController._pythonSymlinkCheckc              
   C   sx  t jg d¢t jdd ¡ d  ¡  | _}t d| ¡ || jksD|| j	ksDt 
d|| jf ¡ | j 
tdƒtd|| j	f ƒ¡ t d	¡ | jrž| jjržt ¡ d
 }t d| ¡ t dt |d ¡ ¡ tj |d ¡rutj d|d ¡ tj |d ¡r†tj d|d ¡ |d }tj |¡ržt d| ¡ t tj|¡ |  ¡  |  ¡ s»t 
d¡ | j 
tdƒtdƒ¡ t d	¡ z|  ¡  W n tyÛ } zt 
d| ¡ W Y d}~dS d}~ww | j  | j¡sådS | j !¡ | _"| j"rôdtj#d< ndtj#d< |  $¡ st 
d¡ dS d	dl%m&} |D ],}tj |¡r8t '|tj(¡s8t 
d| ¡ | j 
tdƒ| td ƒ| ¡ |  )¡  qdS )!z= initial cache opening, coherence checking, network checking )Úlsb_releasez-cz-sT)ÚstdoutÚuniversal_newlinesr   zlsb-release: '%s'zBad upgrade: '%s' != '%s' zCan not upgradez=An upgrade from '%s' to '%s' is not supported with this tool.r   z
/backportszusing backports in '%s' zhave: %sz/*.udebr”   zDir::Bin::dpkgz/usr/lib/apt/methodszDir::Bin::methodsz/etc/apt/apt.conf.d/01ubuntuzadding config '%s'z%pythonSymlinkCheck() failed, abortingzMYour python3 install is corrupted. Please fix the '/usr/bin/python3' symlink.zopenCache() failed: '%s'NFÚserverÚRELEASE_UPGRADE_MODEÚdesktopzcheckViewDepends() failed)ÚSYSTEM_DIRSz%s not writablezCan not write to '%s'zœIts not possible to write to the system directory '%s' on your system. The upgrade can not continue.
Please make sure that the system directory is writable.)*r¨   ÚPopenÚPIPEÚcommunicateÚstripr¼   rX   rY   rg   rh   r‰   r[   r]   r‹   rŒ   rU   ÚhavePrerequistsrP   rQ   ÚinfoÚglobrR   r¥   rl   ra   rd   Úread_config_filer¯   rÐ   r’   ÚSystemErrorr^   Úcoherence_checkÚneed_server_modeÚ
serverModerk   ÚcheckViewDependsÚDistUpgradeMainr×   ÚaccessÚW_OKrŠ   )rz   r¼   ÚbackportsdirÚconfr‘   r×   Ú	systemdirr*   r*   r+   Úprepare  s‚   
þþþÿÿ

ÿ
€þ



üþ€zDistUpgradeController.preparec                 C   s>   t  d| ¡ | jst  d¡ dS d|j|jf }t|t jƒS )zf
        helper that checks if a sources.list entry points to 
        something downloadable
        zverifySourcesListEntry: %sz(skipping downloadable check (no network)Tz%s/dists/%s/Release)rX   rY   r`   ÚuriÚdistr   )rz   Úentryrì   r*   r*   r+   Ú_sourcesListEntryDownloadableÊ  s   
z3DistUpgradeController._sourcesListEntryDownloadablec                    sª	  |rt  d¡ nt  d¡ ˆ j dd¡}ˆ j ddd¡s!dtjv r(t  d¡ d}d}|d	krëˆ jrët  ˆ j d
d¡¡ ˆ j d
d¡D ]¨}t  d| ¡ |ˆ j	vs~ˆ j	| j
r~tˆ j	| j
jƒdks~ˆ j	| j
rêtˆ j	| j
jƒdkrêˆ j	| j
jd jdkrêt  d| ¡ ztƒ }| ˆ j¡ | d¡ d	}t  d¡ W nK tyç } z?t  d| ¡ t  d¡ d}ddg}d}	ˆ j d|	ˆ j||¡ ˆ j d|	ˆ jd ||¡ ˆ j ddˆ jd ||¡ W Y d }~nd }~ww  nqBˆ j dd¡}
ˆ jg‡ fdd„|
D ƒ }ˆ jg‡ fdd„|
D ƒ }dˆ _g }ˆ jjd d … D ]F}d |jv r#q|j d!¡r,q|j d"¡r5qd#|jv sW|j d$¡sW|j d%¡sW|j d&¡sW|j d'¡rYq| |¡ q|ˆ j_d}i ˆ _i }ˆ jjd d … D ]ý}|j|vrd(||j< |js‰|jr‹qs|j d)¡r¥|j ˆ jkr¥t  d*| ¡ d	|_qs|j d)¡rÑt!j "d+¡}tj# $d,|t! %|j¡d-|j d.f ¡sÏt  d/| ¡ d	|_qsd0ˆ j }|jsø|j d1¡rø|j |krøˆ j|_ d2g|_&t  d3| ¡ qs|js|j d4ˆ j ¡rt  d5¡ d	|_qs|jsDˆ j'rDˆ j'j(d	krDd6ˆ j |j v rDt  d7¡ d6ˆ j |_ | j)t*d8ƒˆ j 7  _)d	|_qs|js‡d9|jv r‡t  d:¡ d;t+ƒ  dfD ],}	t, ,|¡}|	|_ˆ j|_ ˆ  -|¡r…t  .d<|	 ¡ |	|_|j|vrƒd=||j<  nqZt  d>t/|ƒ ¡ ˆ  0|j¡}| pŸˆ  1|j¡}|s¦|rÀd	}|jsÐ|j2d?ksÐd@|jv sÐdAˆ j |j v sÐdBˆ j |j v sÐd#|jv rÒd}|j |v ræt  dCt/|ƒ ¡ ||O }nu|j |v rA||j d(kr||O }t, ,|¡}ˆ j|_ ˆ  -|¡sdD||j< nd=||j< ||j dDkr*d	|_d	ˆ _t  dEt/|ƒ ¡ n1||O }|| 3|j ¡ |_ t  dFt/|ƒ ¡ n|j2d?krIqs|r[d	|_d	ˆ _t  dGt/|ƒ ¡ |j2dkr~dH|jv smdI|jv r~ˆ j4dJvr~t  dKˆ j4 ¡ dL|_dMˆ j dNˆ j dAˆ j fD ]1}ˆ j 5|t6ƒ ¡ |js¼|j |kr¼|j2dkr¼|j&D ]}||vr²q©ˆ j|  |¡ q©qŒqs|j ˆ jkrËˆ j|_ dOt*dPƒˆ j  }t7|j)t8ƒræ| j)| 9dQ¡7  _)n| j)|7  _)d	|_d	ˆ _t  dRt/|ƒ ¡ |rp|j |v r|| 3|j ¡ |_ |j |vrqsdMˆ j dNˆ j dAˆ j fD ]-}ˆ j 5|t6ƒ ¡ |j |krP|j2dkrP|j&D ]}||vrFq=ˆ j|  |¡ q=q$t  dS|j2|j |j&f ¡ d}	d}ˆ j |j2|	|j |j&|¡ qsˆ jjd d … D ]X}|js˜|js˜|j2d?ks˜|j d)¡s˜|j ˆ jkršqz|j ˆ jv rÑˆ jˆ j ˆ j|j   }|rÑt  .dTt/|ƒ ¡ |j& :t;|t<dU¡ t  .dVt/|ƒ ¡ ˆ j|j = qz|S )WNz&rewriteSourcesList() with mirror_checkzrewriteSourcesList()r<   Ú
ComponentsÚAllowThirdPartyFÚ"RELEASE_UPGRADER_ALLOW_THIRD_PARTYz,mirror check skipped, *overriden* via configTrI   ÚBaseMetaPkgszChecking pkg: %sr   r   Únowz)BaseMetaPkg '%s' has no candidate.originsr!   z/get_distro().enable_component("main") succeededz$NoDistroTemplateException raised: %sz]get_distro().enable_component("main") failed, overwriting sources.list instead as last resortz* auto generated by ubuntu-release-upgraderr"   ú http://archive.ubuntu.com/ubuntuÚdebú-updatesz!http://security.ubuntu.com/ubuntuú	-securityÚPocketsc                    ó   g | ]	}d ˆ j |f ‘qS ©z%s-%s)rg   ©rM   Úx©rz   r*   r+   rO     ó    ÿz<DistUpgradeController.rewriteSourcesList.<locals>.<listcomp>c                    rú   rû   )rh   rü   rþ   r*   r+   rO     rÿ   z/extras.ubuntu.comzE## This software is not part of Ubuntu, but is offered by third-partyz5## developers who want to ship their latest software.z/archive.canonical.comzE## Uncomment the following two lines to add software from Canonical'sz## 'partner' repository.zK## This software is not part of Ubuntu, but is offered by Canonical and thez2## respective vendors as a service to Ubuntu usersÚunknownzcdrom:z,disabled '%s' cdrom entry (dist == fromDist)zDir::State::listsz%s/%s%s_%s_%sÚdistsÚReleasez:disabling cdrom source '%s' because it has no Release filez%s-commercialzhttp://archive.canonical.comÚpartnerz transitioned commercial to '%s' z*http://landscape.canonical.com/packages/%sz&commenting landscape.canonical.com outz%s-proposedz2upgrade to development release, disabling proposedz5Not for humans during development stage of release %szold-releases.ubuntu.com/z-upgrade from old-releases.ubuntu.com detectedz"http://%sarchive.ubuntu.com/ubuntuz%transition from old-release.u.c to %sÚpassedzexamining: '%s'zdeb-srcz/security.ubuntu.comz%s-securityz%s-backportsz%entry '%s' is already set to new distÚfailedz)entry '%s' was disabled (no Release file)zentry '%s' updated to new distz&entry '%s' was disabled (unknown dist)zarchive.ubuntu.comzsecurity.ubuntu.com)Úamd64Úi386z-moving %s source entry to 'ports.ubuntu.com' z%http://ports.ubuntu.com/ubuntu-ports/ú%sú
%s-updatesú zdisabled on upgrade to %szUTF-8z(entry '%s' was disabled (unknown mirror)zAdding entry: %s %s %sz)fixing components inconsistency from '%s')Úkeyzto new entry '%s')=rX   rY   ra   rq   ÚgetWithDefaultrP   rk   rš   r`   r^   Ú	candidater'   ÚoriginsÚarchiver   Úget_sourcesÚsourcesÚenable_componentr   Ú	exceptionÚaddrh   rg   Úsources_disabledÚlistrì   ÚlineÚ
startswithr›   Úfound_componentsÚinvalidÚdisabledrí   rl   Úfind_dirrR   r¥   Úuri_to_filenameÚcompsrU   rf   Úcommentr]   r   Úcopyrï   rÝ   r   ÚisMirrorÚisThirdPartyMirrorÚtyper%   rj   Ú
setdefaultrd   Ú
isinstanceÚbytesÚencodeÚextendÚsortedr,   )rz   Úmirror_checkÚsync_componentsÚmain_was_missingÚpkgnameÚdistror‘   r  r  rì   ÚpocketsÚ	fromDistsÚtoDistsÚnew_listrî   ÚfoundToDistÚentry_uri_test_resultsÚlistdirÚcdistÚ
test_entryÚvalidMirrorÚthirdPartyMirrorÚvalidToÚdÚcompÚdisable_commentÚcomponent_diffr*   rþ   r+   ÚrewriteSourcesListØ  sþ  




ÿ
þ

ÿÿ
ý€ó€ÿÿÿÿÿÿÿýÿûÿù


üÿ

ÿÿ


ÿ

û


þ

€ôþ

€€
ÿ
ÿ
€z(DistUpgradeController.rewriteSourcesListc                    s  t  d¡ tˆ jdˆ _ˆ j ˆ j¡ t‡ fdd„ˆ jD ƒƒs3ˆ j 	t
dƒt
dƒˆ j ¡}|s3ˆ  ¡  ˆ jdds¬t  d	¡ ˆ j 	t
d	ƒt
d
ƒˆ jˆ jf ¡}|r¨tˆ jdˆ _ˆ jdds§ˆ jr§t
dƒ}t
dƒˆ jˆ jf }ˆ j 	||¡szˆ  ¡  t  d¡ d}ddg}ˆ j d|ˆ j|¡ ˆ j d|ˆ jd |¡ ˆ j ddˆ jd |¡ nˆ  ¡  ˆ j ¡  z
t ¡ }| ¡  W n: tyõ   t  d¡ tj d¡râˆ j t
dƒt
dƒ¡ t ddg¡ Y dS ˆ j t
dƒt
dƒ¡ t  d¡ Y dS w ˆ jrˆ j t
dƒt
dƒ¡ tƒ   ˆ j¡ dS ) NzupdateSourcesList()©ÚmatcherPathc                 3   s&    | ]}|j d ko|jˆ jkV  qdS )rö   N)r#  rí   rg   )rM   r‘   rþ   r*   r+   Ú	<genexpr>  ó   €$ z:DistUpgradeController.updateSourcesList.<locals>.<genexpr>z!No valid sources.list entry foundzŒWhile scanning your repository information no entry about %s could be found.

An upgrade might not succeed.

Do you want to continue anyway?T)r*  zNo valid mirror foundaW  While scanning your repository information no mirror entry for the upgrade was found. This can happen if you run an internal mirror or if the mirror information is out of date.

Do you want to rewrite your 'sources.list' file anyway? If you choose 'Yes' here it will update all '%s' to '%s' entries.
If you select 'No' the upgrade will cancel.FzGenerate default sources?zAfter scanning your 'sources.list' no valid entry for '%s' was found.

Should default entries for '%s' be added? If you select 'No', the upgrade will cancel.z"Generated new default sources.listrõ   r!   r"   rö   r÷   z"http://security.ubuntu.com/ubuntu/rø   z<Repository information invalid after updating (we broke it!)ú/usr/bin/apport-bugzRepository information invalidzlUpgrading the repository information resulted in a invalid file so a bug reporting process is being started.ú
apport-bugúubuntu-release-upgrader-corez–Upgrading the repository information resulted in a invalid file. To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.ú.Missing apport-bug, bug report not autocreatedzThird party sources disabledz¢Some third party entries in your sources.list were disabled. You can re-enable them after the upgrade with the 'software-properties' tool or your package manager.)!rX   rY   r   rT   r  Úbackuprb   Úanyr[   r§   r]   rg   rŠ   r?  r‰   rh   r`   rÝ   r  Úsaverl   Ú
SourceListÚread_main_listrà   rP   rR   r¥   r¨   rØ   r  r©   Úget_telemetryÚset_using_third_party_sources)rz   r¬   ÚprimÚseconrì   r  r   r*   rþ   r+   ÚupdateSourcesList  s€   
üÿ

õÿÿ
ü

þ€

ÿ	ùÿ
ðÿz'DistUpgradeController.updateSourcesListc                 C   s   t  d¡ g }g }g }g }g }| jD ]9}|jr| |j¡ q|jr(| |j¡ q|jr2| |j¡ q|jr?|j	r?| |j¡ q|jrK|j
rK| |j¡ qt  dd |¡ ¡ t  dd |¡ ¡ t  dd |¡ ¡ t  dd |¡ ¡ t  dd |¡ ¡ d S )Nz$About to apply the following changeszKeep at same version: %sr
  zUpgradable, but held- back: %sz
Remove: %szInstall: %szUpgrade: %s)rX   rY   r^   Úmarked_installr›   ÚnameÚmarked_upgradeÚmarked_deleteÚis_installedÚis_upgradableÚmarked_keeprS   )rz   ÚinstÚupÚrmÚheldÚkeepÚpkgr*   r*   r+   Ú_logChangesr  s$   

€z!DistUpgradeController._logChangesc                 C   s  t  d¡ | j d¡ | jsdS t| jjƒdkr(t  d¡ | j | j	¡ |  
¡  t| jjƒdkrR| jj}tddt|ƒƒ}tdd	t|ƒƒd
 |¡ }| j	 ||¡ dS g }| j dd¡D ]}|| jv rm| j| jrm| |¡ q[t  dd t|ƒ¡ ¡ | j ¡ | _| j | j| j| j¡| _t| jƒdkrœ| j ddd¡ n| j ddd¡ | jr¬| jj| _t  dd t| jƒ¡ ¡ t  dd t| jƒ¡ ¡ dS )NÚdoPostInitialUpdateÚPostInitialUpdateFr   z-packages in reqReinstall state, trying to fixzPackage in inconsistent statezPackages in inconsistent statez±The package '%s' is in an inconsistent state and needs to be reinstalled, but no archive can be found for it. Please reinstall the package manually or remove it from the system.z·The packages '%s' are in an inconsistent state and need to be reinstalled, but no archive can be found for them. Please reinstall the packages manually or remove them from the system.z, rI   ÚMetaPkgszMetaPkgs: %sr
  r7   ÚforeignPkgsr;   r:   úForeign: %súObsolete: %sT)rX   rY   rn   r‚   r^   r'   Úreq_reinstall_pkgsrš   Úfix_req_reinstr[   r’   r   rS   r‰   ra   rq   rV  r›   r)  Ú_getObsoletesPkgsÚobsolete_pkgsÚ_getForeignPkgsri   rg   rh   Úforeign_pkgsrd   rã   ÚinstalledTasksÚtasks)rz   Ú	reqreinstÚheaderr­   Ú	meta_pkgsr^  r*   r*   r+   r`  †  sL   

þö
ö
€
z)DistUpgradeController.doPostInitialUpdatec              
   C   sð   t  d| ¡ | jst  d¡ dS | jj ¡  | j ¡ }d}|d ur%|}n| j 	dd¡}d}||k raz	| j 
|¡ W dS  ttfy` } zt|ƒ}t  d||f ¡ |d	7 }W Y d }~q.d }~ww t  d
¡ |rv| j tdƒtdƒd| ¡ dS )Nz"running doUpdate() (showErrors=%s)zBdoUpdate() will not use the network because self.useNetwork==falseTr   rE   rF   Ú zHIOError/SystemError in cache.update(): '%s'. Retrying (currentRetry: %s)r   zdoUpdate() failed completelyzError during updatezƒA problem occurred during the update. This is usually some sort of network problem, please check your network connection and retry.r  F)rX   rY   r`   r^   Ú_listrL  r[   r¿   ra   rp   Úupdaterà   ÚIOErrorre   r‰   r]   )rz   Ú
showErrorsÚforceRetriesr¹   ÚcurrentRetryr}   Ú	error_msgr‘   r*   r*   r+   ÚdoUpdate¹  s:   

ú€ü
üzDistUpgradeController.doUpdatec                    sF  t j d¡st d¡ dS g d¢}t‡ fdd„|D ƒƒs#t d¡ dS d}td	ƒV}|D ]K}| ¡ }z| ¡ \}}}}}	}
W n t	yY } zt d
||f ¡ W Y d}~q,d}~ww |dkr_q,d}d| d¡v rwt d|¡  W d  ƒ dS q,W d  ƒ n1 s‚w   Y  |s–ˆ j
 tdƒtdƒ¡ dS ˆ j
 tdƒtdƒ¡ dS )z= check that /boot/efi is a mounted partition on an EFI systemz/sys/firmware/efizNot an UEFI systemT)zshim-signedzgrub-efi-amd64zgrub-efi-ia32zgrub-efi-armzgrub-efi-arm64Ú
sicherbootc                 3   s&    | ]}|ˆ j v oˆ j | jV  qd S ©N)r^   rV  )rM   Úblrþ   r*   r+   rB  è  rC  z6DistUpgradeController._checkBootEfi.<locals>.<genexpr>z'UEFI system, but no UEFI grub installedFz/proc/mountsz-line '%s' in /proc/mounts not understood (%s)Nz	/boot/efiÚrwú,zFound writable ESP %sz%EFI System Partition (ESP) not usablezxYour EFI System Partition (ESP) is not mounted at /boot/efi. Please ensure that it is properly configured and try again.zzThe EFI System Partition (ESP) mounted at /boot/efi is not writable. Please mount this partition read-write and try again.)rP   rR   r¥   rX   rY   rI  rÅ   rÛ   Úsplitr&   r[   r‰   r]   )rz   ÚbootloadersÚmountedÚmountsr  ÚwhatÚwhereÚfsrU   r(   Úbr‘   r*   rþ   r+   Ú_checkBootEfiÝ  sJ   


€þðóÿÿ	üÿz#DistUpgradeController._checkBootEfic                 C   s8  t dƒ}t dƒ}t dƒ}t dƒ}t dƒ}t dƒ}t dƒ}| j dd	d
¡r+t d¡ dS |  ¡ }z	| j |¡ W dS  ty› }	 zWt	j 
d¡}
d}|
|d|d|d|d|d|i}|	jD ]/}|dkrc|d7 }|j|v rz||j|j|j|j||j d7 }qY||j|j|j|jdd7 }qY| j ||¡ W Y d}	~	d
S d}	~	ww )z: this checks if we have enough free space on /var and /usrzNot enough free disk spacez¼The upgrade has aborted. The upgrade needs a total of {str_total} free space on disk '{str_dir}'. Please free at least an additional {str_needed} of disk space on '{str_dir}'. {str_remedy}zIRemove temporary packages of former installations using 'sudo apt clean'.z¦You can remove old kernels using 'sudo apt autoremove' and you could also set COMPRESS=xz in /etc/initramfs-tools/initramfs.conf to reduce the size of your initramfs.zbEmpty your trash and remove temporary packages of former installations using 'sudo apt-get clean'.z!Reboot to clean up files in /tmp.rq  Ú	FreeSpaceÚ	SkipCheckFz,free space check skipped via config overrideTúDir::Cache::archivesz/varz/bootú/z/tmpz/usrr
  )Ú	str_totalÚstr_dirÚ
str_neededÚ
str_remedyN)r]   ra   r  rX   rš   Ú _is_apt_btrfs_snapshot_supportedr^   ÚcheckFreeSpacer   rl   r  Úfree_space_required_listÚdirÚformatÚ
size_totalÚsize_neededr[   r‰   )rz   Úerr_sumÚerr_msgÚremedy_archivedirÚremedy_bootÚremedy_rootÚ
remedy_tmpÚ
remedy_usrÚwith_snapshotsr‘   Ú
archivedirÚerr_longÚremedyÚreqr*   r*   r+   Ú_checkFreeSpace  sP   
çû


þ
þ€èz%DistUpgradeController._checkFreeSpacec                 C   sì   | j  tdƒ¡ | j | j | j| j¡sdS | jr!| j | j¡s!dS | j 	¡ }| j  
¡  |  ¡  | j  
¡  |  ¡ s:dS |  ¡ s@dS | j  
¡  | j ¡ | _t| jƒdkro| j ¡  t dd dd„ | jD ƒ¡ ¡ t d| j ¡ | j  
¡  |S )	NúCalculating the changesFr   zdemoted: '%s'r
  c                 S   ó   g | ]}|j ‘qS r*   ©rS  rü   r*   r*   r+   rO   e  ó    z9DistUpgradeController.calcDistUpgrade.<locals>.<listcomp>zfound components: %s)r[   r\   r]   r^   ÚdistUpgraderã   rm   ÚinstallTasksrm  Úget_changesr†   r_  r£  r‡  Úget_installed_demoted_packagesÚinstalled_demotionsr'   ÚsortrX   rY   rS   r  )rz   Úchangesr*   r*   r+   ÚcalcDistUpgradeF  s,   




 
z%DistUpgradeController.calcDistUpgradec                 C   s0   |   ¡ }|sdS | j tdƒ|| j| jj¡}|S )NFz!Do you want to start the upgrade?)r¯  r[   ÚconfirmChangesr]   r¬  r^   Úrequired_download)rz   r®  r¬   r*   r*   r+   ÚaskDistUpgradel  s   ýz$DistUpgradeController.askDistUpgradec                 C   s    t  ¡ }| | j¡otj d¡S )Nz2/var/snap/canonical-livepatch/common/machine-token)Údistro_infoÚUbuntuDistroInfoÚis_ltsrg   rP   rR   Úisfile)rz   Údir*   r*   r+   Ú_isLivepatchEnabledy  s   z)DistUpgradeController._isLivepatchEnabledc                    sZ   t  ¡ }ˆ  ¡ r| ˆ j¡rdS t‡ fdd„| d¡D ƒˆ jƒ}ˆ j d t	dƒ| ¡}|S )NTc                 3   s"    | ]}|j ˆ jkr|jV  qd S r{  )Úseriesrh   Úversion)rM   Úrrþ   r*   r+   rB  ƒ  s   €  z5DistUpgradeController.askLivepatch.<locals>.<genexpr>ÚobjectzdLivepatch security updates are not available for Ubuntu %s. If you upgrade, Livepatch will turn off.)
r³  r´  r¸  rµ  rh   ÚnextÚget_allr[   ÚaskCancelContinueQuestionr]   )rz   r·  rº  r¬   r*   rþ   r+   ÚaskLivepatch}  s    ÿÿz"DistUpgradeController.askLivepatchc                 C   s4   t j d¡rt dt| jƒ ¡ t  dd¡ d S d S )Nú/etc/cron.daily/aptzdisabling apt cron job (%s)i¤  )rP   rR   r¥   rX   rY   Úoctrx   Úchmodrþ   r*   r*   r+   Ú_disableAptCronJob‹  s   ýz(DistUpgradeController._disableAptCronJobc                 C   s,   t j d¡rt d¡ t  d| j¡ d S d S )NrÁ  zenabling apt cron job)rP   rR   r¥   rX   rY   rÃ  rx   rþ   r*   r*   r+   Ú_enableAptCronJob  s   
þz'DistUpgradeController._enableAptCronJobc           
   
   C   s”  |   ¡  d}| j ¡ }| j ddd ¡}|r:zt ¡ d  d¡d }W n   t 	d¡ d}Y | j 
¡  d||f ¡ | j dd	¡}d
}d }||k rŸzt | jj¡}t |¡| _| j | j|¡ W dS  tjjy~ }	 zt d¡ d}|	}W Y d }	~	n%d }	~	w tyž }	 zt d|	|f ¡ |d7 }|	}W Y d }	~	qEd }	~	ww |r­| j tdƒtdƒ¡ nt d¡ | j tdƒtdƒd| ¡ |  ¡  |  ¡  d S )Nr   rI   ÚSlideshowUrlr]   ÚgetdefaultlocaleÚenz%s#locale=%srE   rF   Fzuser canceledTú:IOError in cache.commit(): '%s'. Retrying (currentTry: %s)r   zUpgrade canceledzwThe upgrade will cancel now and the original system state will be restored. You can resume the upgrade at a later time.ú+giving up on fetching after maximum retriesúCould not download the upgradeszThe upgrade has aborted. Please check your Internet connection or installation media and try again. All files downloaded so far have been kept.r  )rÄ  r[   r¿   ra   r  ÚlocalerÇ  r  rX   r  ÚgetHtmlViewrÅ   rp   rl   ÚPackageManagerr^   Ú	_depcacheÚAcquirer_   Ú_fetch_archivesÚaptÚFetchCancelledExceptionrÝ   rt  r‰   r©   r]   rÅ  rŠ   )
rz   rw  Ú	fprogressÚurlÚlangr}   Úuser_canceledr  Úpmr‘   r*   r*   r+   ÚdoDistUpgradeFetching•  sX   

õ
€€û	ÿ
ûz+DistUpgradeController.doDistUpgradeFetchingc                 C   s`   zddl }W n
 ty   Y dS w z
| ¡ }| ¡ }W n   t d¡ Y dS t d| ¡ |S )z' check if apt-btrfs-snapshot is usable r   Nzfailed to check btrfs supportFz!apt btrfs snapshots supported: %s)Úapt_btrfs_snapshotÚImportErrorÚAptBtrfsSnapshotÚsnapshots_supportedrX   r  rY   )rz   rÚ  Ú	apt_btrfsr¬   r*   r*   r+   r  ß  s   ÿ
z6DistUpgradeController._is_apt_btrfs_snapshot_supportedc                 C   sF   |   ¡ sdS ddl}| ¡ }d| j }| |¡}t d||f ¡ dS )z2 create btrfs snapshot (if btrfs layout is there) Nr   zrelease-upgrade-%s-z#creating snapshot '%s' (success=%s))r  rÚ  rÜ  rh   Úcreate_btrfs_root_snapshotrX   rÝ   )rz   rÚ  rÞ  Úprefixr¬   r*   r*   r+   Ú _maybe_create_apt_btrfs_snapshotî  s   

z6DistUpgradeController._maybe_create_apt_btrfs_snapshotc                 C   s¢   i }t jd g|d< dt jd< dD ]}t j |¡||d < t j |¡ qz|  ¡ W |D ]}|| D ]	}t j ||¡ q1q+S |D ]}|| D ]	}t j ||¡ qEq?w )Nzdir::bin::dpkgz	/bin/true)zdpkg::pre-invokezdpkg::pre-install-pkgszdpkg::post-invokezdpkg::post-install-pkgsz::)rl   ra   Ú
value_listÚclearÚdoDistUpgraderd   )rz   ÚbackupsÚlstÚitemr*   r*   r+   ÚdoDistUpgradeSimulationø  s"   
ÿ
ÿÿÿz-DistUpgradeController.doDistUpgradeSimulationc                 C   sà  d}| j  ¡ }| j  | j¡}| j dd¡}| js"| j d¡ |  	¡  d}d }||k rWz| j 
||¡}t d| ¡ W n tyí } z¥t d| ¡ |}tj d¡rªtdƒ}| ¡ }W d   ƒ n1 sfw   Y  t d	| ¡ d
dg}	|	D ]1}
t|ƒ |
¡r©t d¡ |  ¡  tdƒ}|dt|ƒ 7 }|tdƒ7 }| j  tdƒ|¡ |  ¡  qxtdƒ}| js¼tƒ s¼|td| ƒ7 }| j  tdƒ|¡ g d¢}tj d¡dkrÖ| d¡ | j  ¡  |¡ |  ¡  W Y d }~dS d }~w ty } zt d||f ¡ |d7 }|}W Y d }~q&d }~w t yP } z6t !d¡ |}|j"dkrF|  ¡  tdƒ}|dt|ƒ 7 }|tdƒ7 }| j  tdƒ|¡ |  ¡  W Y d }~nd }~ww |  ¡  dS t d¡ | j  tdƒtdƒd| ¡ |  ¡  d S ) Nr   rE   rF   ÚStartUpgradeFzcache.commit() returned %sz#SystemError from cache.commit(): %sz./var/run/ubuntu-release-upgrader-apt-exceptionzfound exception: '%s'z;E:Internal Error, Could not perform immediate configurationz E:Couldn't configure pre-depend z-detected preconfigure error, restorting stateúError during commitz
'%s'
úRestoring original system statezCould not install the upgradeszrThe upgrade has aborted. Your system could be in an unusable state. A recovery will run now (dpkg --configure -a).z·

Please report this bug in a browser at http://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+filebug and attach the files in /var/log/dist-upgrade/ to the bug report.
%sr“   r•   r–   r—   rÉ  r   zcache.commit()é   TrÊ  rË  zdThe upgrade has aborted. Please check your Internet connection or installation media and try again. r  )#r[   r¿   ÚgetInstallProgressr^   ra   rp   rm   rn   r‚   rá  ÚcommitrX   rY   rà   r‰   rP   rR   r¥   rÅ   Úreadre   r  rÅ  r]   rŠ   r    rk   r   r›   rœ   r   rt  rÈ   r  Úerrno)rz   rw  rÔ  Ú	iprogressr}   r¬   r  r‘   rÍ   Úpre_configure_errorsÚpreconf_errorÚmsgrŸ   r*   r*   r+   rä    s”   



ÿþ
€ü
€€
€ô
üz#DistUpgradeController.doDistUpgradec              
   C   s²  t ƒ  d¡ tj tj d¡¡}| jj	D ]!}tj tj 
|j¡¡|kr5zt |j¡ W q ty4   Y qw q|  ¡  | j d¡ | j tj¡ | j tdƒ¡ | j ¡ }| j | j| j| j¡}t dd t |ƒ¡ ¡ t dd t |ƒ¡ ¡ | j !dd	¡D ]}||v rt "d
| ¡ t#ƒ } nq~| j $ddd¡s t d¡ dS | j !dd¡D ]}|| jv r¿| j| j%r¿| j& '| j !|d¡¡ q§t d| j& ¡ | j(rÑ|| j) }n
t#dd„ | j*D ƒƒ}|t#| j&ƒO }| j +¡ }t dd |¡ ¡ |t#|ƒO }| j $ddd¡st d¡ t#ƒ }t d| ¡ t d¡ | j ,¡ }t-|ƒD ]/\}	}
| .|	t/t0|ƒƒ d ¡ |
| j1vrK| j 2¡  | j 3|
|| j&| j1¡sKt d|
¡ qt d¡ | 4¡  | j 5¡ }t dd dd„ |D ƒ¡ ¡ tdƒ}tdƒtdƒg}t0|ƒdkrÉ| j 6||g d|d ¡rÉ| j 7¡ }| j 8| j¡}z	| j 9||¡ W n* t:t;fyÈ } zt "d!| ¡ | j "td"ƒtd#ƒd$| ¡ W Y d }~nd }~ww | j d%¡ | j<s×|  =¡  dS )&NÚPOSTUPGRADErŠ  ÚPostUpgradezSearching for obsolete softwarere  r
  rd  rI   ró   zXthe BaseMetaPkg '%s' is in the obsolete list, something is wrong, ignoring the obsoletesÚRemoveObsoletesTzSkipping obsolete Removalrb  rJ   zforced_obsoletes: %sc                 S   r¥  r*   r¦  )rM   Úpr*   r*   r+   rO   ¨  r§  z7DistUpgradeController.doPostUpgrade.<locals>.<listcomp>zUnused dependencies: %sz0Skipping RemoveObsoletes as stated in the configzremove_candidates: '%s'z Start checking for obsolete pkgsg      Y@z:'%s' scheduled for remove but not safe to remove, skippingz!Finish checking for obsolete pkgsz1The following packages are marked for removal: %sc                 S   r¥  r*   r¦  )rM   r^  r*   r*   r+   rO   Â  r§  zRemove obsolete packages?Ú_KeepÚ_Remover   Fz,cache.commit() in doPostUpgrade() failed: %srê  z[A problem occurred during the clean-up. Please see the below message for more information. r  ÚPostCleanup)>rM  Ú	add_stagerP   rR   rË   rl   ra   r  r_   rw   ÚabspathÚdestfileÚunlinkrÈ   r’   rn   r‚   r[   ÚsetStepr   ÚCLEANUPr\   r]   r^   rh  rj  ri   rg   rh   rX   rY   rS   r)  rq   r‰   rd   r  rV  rr   r(  r`   ri  r¬  Ú_getUnusedDependenciesr˜   Ú	enumeraters  Úfloatr'   rk  r†   ÚtryMarkObsoleteForRemovalÚdonerª  r°  r¿   rí  rî  rà   rt  rm   ÚrunPostInstallScripts)rz   rŸ  rç  Únow_obsoleteÚnow_foreignr^  Úremove_candidatesÚunused_dependenciesr¹   Úir-  r®  r­   ÚactionsrÔ  rñ  r‘   r*   r*   r+   ÚdoPostUpgraden  sž   
ÿÿý
ý
€




€

ÿ
ü€þz#DistUpgradeController.doPostUpgradec                 C   sÈ   | j r| j  ¡  | j  ¡  | j dd¡D ]C}tj |¡s$t 	d| ¡ qt 
d| ¡ zt|ƒ | j ¡ j|gdd W q tyW } zt d||f ¡ W Y d}~qd}~ww | j rb| j  ¡  dS dS )	zý 
        scripts that are run in any case after the distupgrade finished 
        whether or not it was successful

        Cache lock is released during script runs in the event that the
        PostInstallScripts require apt or dpkg changes.
        rI   ÚPostInstallScriptsz!PostInstallScript: '%s' not foundzRunning PostInstallScript: '%s'T)Úhiddenz(got error from PostInstallScript %s (%s)N)r^   rƒ   r„   ra   rq   rP   rR   r¥   rX   rš   rY   r   r[   rœ   r   Ú	Exceptionr‰   Úget_lock)rz   Úscriptr‘   r*   r*   r+   r  Ü  s$   

€ÿÿz+DistUpgradeController.runPostInstallScriptsc                 C   sR   t  d¡ t| dƒr| j | j¡ | j tdƒ¡ | j 	¡  |  
¡  t d¡ dS )z2 abort the upgrade, cleanup (as much as possible) zabort calledr  rë  r   N)rX   rY   Úhasattrr  Úrestore_backuprb   r[   r\   r]   rŠ   r’   r‹   rŒ   rþ   r*   r*   r+   rŠ   ö  s   


zDistUpgradeController.abortc           	      C   s¬   t  |¡D ]G}t d| ¡ |D ];}|d }|d }|d }|| jvr.t d| ¡   dS | j| }t|jddƒ}|dkrKt  |||¡d	krK  d	S qqt d
| ¡ dS )z+ check if a given depends can be satisfied zchecking: '%s' r   r   é   z_checkDep: '%s' not in cacheFrº  NTzdepends '%s' is not satisfied)	rl   Úparse_dependsrX   rY   r^   r‰   ÚgetattrÚ	installedÚ	check_dep)	rz   ÚdepstrÚor_groupÚdepÚdepnameÚverÚoperrY  Úinstverr*   r*   r+   Ú	_checkDep  s$   

€õzDistUpgradeController._checkDepc                 C   s†   t  d¡ d}| j dd¡}| | j | jjjd¡¡ |D ]#}t  d|¡ ||  |¡M }|s@| j 	t
dƒt
d| ƒ¡ t d¡ q|S )	z  check if depends are satisfied zcheckViewDepends()Tr    ÚDependszdepends: '%s'z!Required depends is not installedz/The required dependency '%s' is not installed. r   )rX   rY   ra   rq   r(  r[   rZ   r.   r"  r‰   r]   r‹   rŒ   )rz   r¬   Údependsr  r*   r*   r+   rä     s$   
ÿÿÿ
€z&DistUpgradeController.checkViewDependsc                 C   sÐ   | j  dd¡}d}tj  dd¡}| j  dd¡}||k rT| jdd	 |  ¡  |D ]}|| jvr9t 	d
| ¡ t
|ƒ‚q'|  |¡r@nt d¡ tj  dd¡ |d7 }||k s||kr_t 	d¡ dS tj  d|¡ dS )NÚPreRequistsÚPackagesr   zAcquire::http::No-CacherH   rE   rF   F)ru  zCan not find backport '%s'z>setting a cache control header to turn off caching temporarilyÚtruer   z+pre-requists item is NOT trusted, giving upT)ra   rq   rl   Úfindrp   ry  r’   r^   rX   r‰   r-   Ú_allBackportsAuthenticatedrY   rd   )rz   Úbackportslistr  ÚnoCacher}   r-  r*   r*   r+   Ú_verifyBackports(  s.   
þ

ô
z&DistUpgradeController._verifyBackportsc                 C   s’   t j dd¡dkrt d¡ dS z| j dd¡}|rW dS W n	 ty'   Y nw |D ]}| j| }|js7 dS |jj	D ]}|j
rB nq; dS q*dS )NzAPT::Get::AllowUnauthenticatedFTzIskip authentication check because of APT::Get::AllowUnauthenticated==truerI   ÚAllowUnauthenticated)rl   ra   Úfind_brX   rš   Ú
getbooleanr   r^   r  r  Útrusted)rz   r*  r†  r-  r^  Úcandr*   r*   r+   r)  C  s,   
ÿÿ
ÿþz0DistUpgradeController._allBackportsAuthenticatedc           
      C   s–   |  d¡}t|ƒ\}}}}}d|v r| d¡d }d|||f }| jD ]%}|  d¡}t||ƒr2 dS | d¡d }	| |	¡rHt d| ¡  dS q#dS )	z  check if uri is a known mirror r‹  ú@r   z	%s://%s%sTz//z)found apt-cacher/apt-torrent style uri %sF)Úrstripr   r  rt   r   ÚendswithrX   rY   )
rz   rì   Úraw_uriÚschemeÚnetlocrR   ÚqueryÚfragmentÚmirrorÚmirror_host_partr*   r*   r+   r!  Y  s   




þzDistUpgradeController.isMirrorc                 C   s4   |  d¡}| jD ]}|  d¡}t||ƒr dS qdS )z/ check if uri is an allowed third-party mirror r‹  TF)r3  ru   r   )rz   rì   r:  r*   r*   r+   r"  o  s   



ÿz(DistUpgradeController.isThirdPartyMirrorc                 C   sž   d}t dd}|jD ]B}|js|jrq
|jdkrL|jdkrL|  |j¡rLd|jv rLd| j |j	v rL|j 
d¡sL|j 
d	¡sLd
|j| jf }||vrL||7 }q
|S )z7 get sources.list snippet lines for the current mirror rq  r2   r@  rö   Fr!   r	  zhttp://security.ubuntu.comzhttp://archive.ubuntu.comzdeb %s %s-updates main
)r   r  r  r  r#  r!  rì   r  rg   rí   r  )rz   ÚdumbÚlinesr  rî   Únew_liner*   r*   r+   Ú_getPreReqMirrorLinesx  s(   




ÿ

ÿ
þ€z+DistUpgradeController._getPreReqMirrorLinesc           	   	   C   s¶   t  d| ¡ |  |¡}t|dƒ@}t|ƒ#}|D ]}t|ƒ}|j|d}| |¡ t  d| ¡ qW d  ƒ n1 s<w   Y  W d  ƒ dS W d  ƒ dS 1 sTw   Y  dS )z9 add prerequists based on template into the path outfile z*writing prerequists sources.list at: '%s' Úw)r:  zadding '%s' prerequistsNT)rX   rY   r?  rÅ   r   Úsafe_substituteÚwrite)	rz   ÚtemplateÚoutr<  ÚmirrorlinesÚoutfileÚinfiler  Úoutliner*   r*   r+   Ú_addPreRequistsSourcesList  s   

ü(ÿúúz0DistUpgradeController._addPreRequistsSourcesListc                 C   sÊ  t  d¡ d}tj t ¡ d¡}tj |¡st |¡ | j 	dd¡}d}| j 
d|d| j  ¡r7|d| j  }| j d|¡}tj |¡sMt  d| ¡ d	S tj tj d
¡|¡}tj tj d
¡|¡}|  ||¡ z|  ¡  W n3 ty¢   | j||dd z|  ¡  W Y d	S  ty¡ } zt  d| ¡ W Y d}~Y d	S d}~ww w |D ]B}	| j|	 }
| jj |
j¡}|sÅt  d|	 ¡ t |¡  d	S |jdkrÙt  d|	 ¡ t |¡  d	S t  d|	 ¡ |
jd	d	d q¥d	}z| j | j ¡ | j | j¡¡}W n7 ty } zt  d| ¡ d	}W Y d}~n d}~w t y2 } zt  d| ¡ d	}W Y d}~nd}~ww |d	kr=t  d¡ z
t |¡ W |  "¡ S  t!yd } zt  d| ¡ W Y d}~|  "¡ S d}~ww )z5 download the backports specified in DistUpgrade.cfg zgetRequiredBackports()TÚ	backportsr%  r&  r   z-%szsourceslist not found '%s'FzDir::Etc::sourceparts)r<  zno backport for '%s' foundNzNo candidate for '%s'zNo ver.file_list for '%s'zmarking '%s' for install)Ú	auto_instÚauto_fixzfetch_archives returned '%s'zinstall_archives returned '%s'z,_fetch_archives for backports returned Falsez(failed to unlink pre-requists file: '%s')#rX   rY   rP   rR   rS   rQ   r¥   Úmkdirra   rq   Ú
has_optionrj   r   r‰   rl   r  rI  r,  r-   rš   r^   rÏ  Úget_candidate_verÚ_pkgrÿ  Ú	file_listÚmark_installrî  r[   r¿   rí  rt  rà   r  ÚsetupRequiredBackports)rz   r¬   rè   r*  Úconf_optionÚprereq_templateÚoutpathrF  r‘   r-  r^  r  r*   r*   r+   ÚgetRequiredBackports  s„   


þ€þü	



ÿ€€þ

þ€þz*DistUpgradeController.getRequiredBackportsc                 C   sx   dt jd< t ¡  t dd¡ tjdg }| jr| 	d¡ n| 	d¡ t 
d¡ ttjd	 ƒ t  tjd	 |t j¡ d S )
Nz$/usr/lib/release-upgrader-python-aptÚ
PYTHONPATHz/var/log/dist-upgrade/main.logz&/var/log/dist-upgrade/main_pre_req.logz--have-prerequistsz--with-networkz--without-networkzrestarting upgraderr   )rP   rk   rX   ÚshutdownÚshutilr   r‹   Úargvr`   r›   rÝ   r   Úexecve)rz   Úargsr*   r*   r+   rS  õ  s   
ÿ

z,DistUpgradeController.setupRequiredBackportsc              
   C   sŠ  | j  tdƒ¡ | j  tj¡ |  ¡ sEt d¡ t	j
 d¡r1| j  tdƒtdƒ¡ t ddg¡ n| j  tdƒtdƒ¡ t d	¡ |  ¡  | j d
¡rŠ| jrŠ| jjdkrŠt d¡ |  ¡ sŠt	j
 d¡rv| j  tdƒtdƒ¡ t ddg¡ n| j  tdƒtdƒ¡ t d	¡ |  ¡  |  ¡ s’|  ¡  | jddd |  ¡  |  ¡ s¥|  ¡  z$| j  tj¡ | j  tdƒ¡ |  ¡ s¾|  ¡  |  ¡ sÆ|  ¡  | j  tdƒ¡ | jdd | j ¡ | _| j ¡  | j  dd¡D ][}|| jvs÷| j !| j| ¡sAt d| ¡ || jvrt d| ¡ | j !| j| ¡st d| ¡ | j  tdƒtdƒ| ¡ t	j
 d¡r8t ddg¡ nt d	¡ |  ¡  qæ| j  tdƒ¡ |  "¡ sS|  ¡  |  #¡  | j  tj$¡ | j  tdƒ¡ |  %¡ ss|  &¡  |  ¡  | j  tj'¡ | j  tdƒ¡ |  (¡ s–| j  tdƒtd ƒ¡ |  ¡  | j )¡  d}z| jd!  *¡  d}W n  t+yÈ } zd"t,|ƒv r¾t d#¡ 	 W Y d }~nd }~ww W n t-yØ   |  ¡  Y nw |r | j  tj'¡ | j  tdƒ¡ |  .¡ s | j  /td$ƒtd%ƒ¡ t0 1d¡ | jdd | j ¡ | _| j ¡  | j  tdƒ¡ |  2¡ s6|r2| j  /td$ƒtd%ƒ¡ t0 1d¡ n|  ¡  | j  tj'¡ | j  tdƒ¡ |  .¡ s^|  3¡  | j  /td&ƒtd'ƒ¡ t0 1d¡ |  4¡  t	j
 d(¡rnt	 5d(¡ | j  tj6¡ | j  td)ƒ¡ t7ƒ  8¡  t9ƒ sÃ|  :¡ r³| j  ;¡  t<d*d+d,d-}| =d.¡ W d   ƒ n	1 s¨w   Y  | j  >¡  n| j  ?¡ r¾t d/¡ t0 1d0¡ dS )1NzChecking package managerzself.prepare() failedrD  zPreparing the upgrade failedzXPreparing the system for the upgrade failed so a bug reporting process is being started.rE  rF  z‚Preparing the system for the upgrade failed. To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.rG  r%  Fzneed backportsz$Getting upgrade prerequisites failedzºThe system was unable to get the prerequisites for the upgrade. The upgrade will abort now and restore the original system state.

Additionally, a bug reporting process is being started.zØThe system was unable to get the prerequisites for the upgrade. The upgrade will abort now and restore the original system state.

To report a bug install apport and then execute 'apport-bug ubuntu-release-upgrader'.r   )ru  rv  zUpdating repository informationT)rŽ   rI   ró   z@No '%s' available/downloadable after sources.list rewrite+updatez'%s' was not in the cachez'%s' was not downloadablezInvalid package informationa†  After updating your package information, the essential package '%s' could not be located. This may be because you have no official mirrors listed in your software sources, or because of excessive load on the mirror you are using. See /etc/apt/sources.list for the current list of configured software sources.
In the case of an overloaded mirror, you may want to try the upgrade again later.r¤  ÚFetchingÚ	UpgradingzUpgrade infeasiblezQThe upgrade could not be completed, there were errors during the upgrade process.Úlibc6ÚpkgProblemResolverz'Unable to mark libc6 alone for install.zUpgrade incompletezUThe upgrade has partially completed but there were errors during the upgrade process.úUpgrade completeúKThe upgrade has completed but there were errors during the upgrade process.z:/var/lib/ubuntu-release-upgrader/release-upgrade-availablezSystem upgrade is complete.z/run/launcher-commandzw+zutf-8)Úencodingzaction: reboot
ú/sbin/rebootr   )@r[   r\   r]   r   r   ÚPREPARErë   rX   r‰   rP   rR   r¥   r¨   rØ   rŠ   ra   rv   rU   rÜ   rY   rW  rÀ  ry  r’   r`  ÚMODIFY_SOURCESrQ  r^   râ   rã   rn   Ú+ensure_recommends_are_installed_on_desktopsrq   ÚanyVersionDownloadabler²  Ú_inhibitIdleÚFETCHrÙ  rÅ  ÚINSTALLrè  rã  rR  rà   re   ÚKeyboardInterrupträ  r©   r‹   rŒ   r¯  r  r  rÿ  ÚREBOOTrM  r  r   Ú_inside_WSLÚadviseExitOtherWSLrÅ   rB  ÚadviseRestartWSLÚconfirmRestart)rz   r^  Úlibc6_possibler‘   rÍ   r*   r*   r+   ÚfullUpgrade
  s  
ÿÿ
ÿ
ÿÿ
	

ÿôÿ
€


ÿ

€ý€ÿ
ÿ


ÿ
ÿ




ÿ

z!DistUpgradeController.fullUpgradec                 C   s   | j  ¡  |  ¡ S r{  )r[   r†   rt  rþ   r*   r*   r+   r‚   ø  s   
zDistUpgradeController.runc                 C   s  | j  tj¡ | j  tj¡ | j  tj¡ d| _|  ¡  |  	¡ s"dS |  
¡ s(dS | j  tj¡ | j  tdƒ¡ |  ¡ s=dS | j  tj¡ | j  tdƒ¡ |  ¡ s]| j  tdƒtdƒ¡ dS |  ¡ sn| j  tdƒtdƒ¡ dS tj t¡r€| j  ¡ r~t d¡ dS | j  tdƒtdƒ¡ dS )	z, partial upgrade mode, useful for repairing TFr^  r_  rb  rc  re  z"The partial upgrade was completed.)r[   r   r   rf  ÚhideSteprg  rn  rm   rë   r`  r²  rk  r\   r]   rÙ  rl  rä  r©   r  rP   rR   r¥   ÚREBOOT_REQUIRED_FILErr  r¨   rØ   rþ   r*   r*   r+   ÚdoPartialUpgradeü  sB   ÿÿ

þÿz&DistUpgradeController.doPartialUpgradec              
   C   s  t  d¡ zoz+dd l}|  ¡  | ¡ | _| j dd¡}|j|dd}| dd¡ t	dƒ}t	d	ƒ}W n: t
yk } z.t d
d¡dv rPW Y d }~W t t ¡ ¡ d S t  dt|ƒ ¡ t	dƒ}t	dƒ}W Y d }~nd }~ww W t t ¡ ¡ nt t ¡ ¡ w | j ||¡ d S )Nzinhibit screensaverr   zorg.freedesktop.ScreenSaverz/org/freedesktop/ScreenSaver)Údbus_interfacer4   zUpgrading UbuntuzLock screen disabledzOYour lock screen has been disabled and will remain disabled during the upgrade.ÚXDG_SESSION_TYPErq  )rq  Úttyzfailed to inhibit screensaver: zUnable to disable lock screenz£It is highly recommended that the lock screen be disabled during the upgrade to prevent later issues. Please ensure your screen lock is disabled before continuing.)rX   rY   ÚdbusÚ_setNonRootEUIDÚ
SessionBusry   Ú
get_objectÚ	InterfaceÚInhibitr]   r  rP   ÚgetenvÚseteuidÚgetuidre   r[   r©   )rz   r{  ÚproxyÚscreensaverr­   Úmessager‘   r*   r*   r+   rj  #  s0   

ÿ
ø€ú€ z"DistUpgradeController._inhibitIdlec                 C   sL   t  ¡ dkrd S t  d¡}|st  d¡}|st d¡ d S t  t|ƒ¡ d S )Nr   ÚSUDO_UIDÚ
PKEXEC_UIDz"failed to determine user upgrading)rP   rƒ  r  rX   rY   r‚  Úint)rz   Úuidr*   r*   r+   r|  I  s   


z%DistUpgradeController._setNonRootEUIDc                 C   s   t j d¡S )Nz#/proc/sys/fs/binfmt_misc/WSLInterop)rP   rR   r¥   rþ   r*   r*   r+   ro  V  s   z!DistUpgradeController._inside_WSL)NN)TF)T)TN)F)2r.   r/   r0   Ú__doc__r~   r’   r…   r£   r¯   rÁ   rÐ   rë   rï   r?  rQ  r_  r`  ry  r‡  r£  r¯  r²  r¸  rÀ  rÄ  rÅ  rÙ  r  rá  rè  rä  r  r  rŠ   r"  rä   r,  r)  r!  r"  r?  rI  rW  rS  rt  r‚   rw  rj  r|  ro  r*   r*   r*   r+   r1   ]   sf    

b#;I
  7e
3$/:&J
fn
	
X o'&r1   Ú__main__)ÚDistUpgradeViewText)Úlevel)IrÒ  rl   r³  r‹   rP   r¨   rÌ  rX   rZ  rÞ   r‡   r   Úconfigparserr   r   rÄ   Ú	telemetryr   rM  Úutilsr   r   r   r	   r
   r   r   r   r   Ústringr   Úurllib.parser   ÚDistUpgradeViewr   ÚDistUpgradeCacher   ÚDistUpgradeConfigParserr   r   Ú
aptsourcesr   r   ÚDistInfoÚaptsources.sourceslistr   r   r.  r   r   ÚDistUpgradeGettextr   r]   r   r   r   r   ÚDistUpgradeApportr    rv  r,   r  r-   r¼  r1   r.   r  ÚbasicConfigÚDEBUGÚvÚdcrÄ  rÅ  r*   r*   r*   r+   Ú<module>   sx   ,	                ù