o
    аif                    @   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rddlBmBZB ejCejDd eB ZEe@eEZFeFG  eFH  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rt	
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 supportedzYou 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 sshdzTo 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 ACCEPTzIf 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|rt }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rt 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rt d
 }td|  tdt|d   tj|d rutjd|d  tj|d rtjd|d  |d }tj|rtd|  ttj| |   |  st
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sdS | j! | _"| j"rd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'zIts 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rt  jd
d  jd
dD ]}t d|  | j	vs~ j	| j
r~t j	| j
jdks~ j	| j
rt j	| j
jdkr j	| j
jd jdkrt 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rt d*|  d	|_qs|jd)rt!j"d+}tj#$d,|t!%|jd-|j d.f st 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sd9|jv rt d: d;t+  dfD ],}	t,,|}|	|_ j|_  -|rt .d<|	  |	|_|j|vrd=||j<  nqZt d>t/|   0|j}| p 1|j}|s|rd	}|js|j2d?ksd@|jv sdA j |j v sdB j |j v sd#|jv rd}|j |v rt 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   }|rt .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st d	  j	t
d	t
d
 j jf }|rt jd _ jdds jrt
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 foundzWhile 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-corezUpgrading 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 disabledzSome 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 statezThe 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.zThe 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 updatezA 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 sw   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 spacezThe 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'.zYou 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 rz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 } ztd|  |}tjdrtd}| }W d    n1 sfw   Y  td	|  d
dg}	|	D ]1}
t||
rtd |   td}|dt| 7 }|td7 }| j td| |   qxtd}| jst 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std dS | j!ddD ]}|| jv r| j| j%r| j&'| j!|d qt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 ]}	| jj.|	| j/ds.|0|	 qt1|D ]'\}
}	|2|
t3t4| d  | j5  | j6|	|| j&sZtd|	 q4td |7  | j8 }tdddd |D   td}tdtdg}t4|d kr| j9||g d |d!r| j: }| j;| j}z	| j<|| 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 pkgs)rk  g      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)ArM  	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   r  isRemoveCandidaterk  remove	enumeraters  floatr'   r   tryMarkObsoleteForRemovaldoner  r  r   r  r  r   rt  rm   runPostInstallScripts)rz   r  r  now_obsoletenow_foreignr^  remove_candidatesunused_dependenciesr   r-  ir  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+  H  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!  ^  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)r5  ru   r   )rz   r   r<  r*   r*   r+   r"  t  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+   _getPreReqMirrorLines}  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   rA  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}|st d|	  t|  d	S |jdkrt d|	  t|  d	S t d|	  |
jd	d	d qd	}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  rK  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outpathrH  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+   rU    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rtd |  st	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 rt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% t01d | jdd | j | _| j  | j td | 2 s6|r2| j /td$td% t01d n|   | j tj' | j td | . s^| 3  | j /td&td' t01d | 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 sw   Y  | j >  n| j ? rtd/ t01d0 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  zPreparing 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 failedzThe 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.zThe 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 completeKThe 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   rY  r  ry  r   r`  MODIFY_SOURCESrQ  r^   r   r   rn   +ensure_recommends_are_installed_on_desktopsrq   anyVersionDownloadabler  _inhibitIdleFETCHr  r  INSTALLr  r  rT  r   re   KeyboardInterruptr  r   r   r   r  r	  r  r  REBOOTrM  r  r   _inside_WSLadviseExitOtherWSLr   rD  adviseRestartWSLconfirmRestart)rz   r^  libc6_possibler   r   r*   r*   r+   fullUpgrade  s  



	



















z!DistUpgradeController.fullUpgradec                 C   s   | j   |  S r{  )r[   r   rv  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`  ra  rd  re  rg  z"The partial upgrade was completed.)r[   r   r   rh  hideStepri  rp  rm   r   r`  r  rm  r\   r]   r  rn  r  r   r  rP   rR   r   REBOOT_REQUIRED_FILErt  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 screenzIt 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+   rl  (  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~  N  s   


z%DistUpgradeController._setNonRootEUIDc                 C   s   t jdS )Nz#/proc/sys/fs/binfmt_misc/WSLInterop)rP   rR   r   r   r*   r*   r+   rq  [  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"  rA  rK  rY  rU  rv  r   ry  rl  r~  rq  r*   r*   r*   r+   r1   ]   sf    

b#;I
  7e
3$/:&J
fs
	
X o'&r1   __main__)DistUpgradeViewText)level)Ir  rl   r  r   rP   r   r  rX   r\  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    rx  r,   r  r-   r  r1   r.   r  basicConfigDEBUGvdcr  r  r*   r*   r*   r+   <module>   sx   ,	                