a ik@sdZddlmZmZmZmZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZddlZddlZddlmZddlmZddlZddlmZmZddlZed e d Ze d Ze d Ze d Z eZ!dZ"edZ#edZ$edZ%dZ&d5ddZ'ddZ(gfddZ)d6ddZ*ddZ+Gddde,Z-Gd d!d!e,Z.e.Z/Gd"d#d#ej0j1Z2d$d%Z3d&d'Z4d(d)Z5d*d+Z6gd,Z7Gd-d.d.ej8Z9Gd/d0d0ej:j;ZdS)7zGsystem_upgrade.py - DNF plugin to handle major-version system upgrades.)callPopen check_outputCalledProcessErrorN)journal)_logger)CliError)ucd)serialize_transactionTransactionReplayzthe color of the skyZ 9348174c5cc74001a71ef26bd79d302eZ fef1cc509d5047268b83a3a553f54b43Z 3e0a5636d16b4ca4bbe5321d06c6aa62Z 8cec00a1566f4d3594f116450395f06cz/usr/bin/plymouthz/usr/lib/python3.9/site-packages/dnf-plugins/system_upgrade.pyrEs rc Csd}dD]}zvt|Z}|D]D}|}||r|t|ddWdWSqWdn1sv0YWqtyYqYq0qdS)NzUPGRADE_GUIDE_URL=)z/etc/os-releasez/usr/lib/os-release")openstrip startswithlenIOError)keypathZ release_filelinerrrget_url_from_os_releaseOs  R  rc Csxtj|sdSt|D]X}tj||}||vr6qz(tj|rRtj|n t|Wqt ypYq0qdSN) rrisdirlistdirjoindnfutilZrm_rfunlinkOSError)rignoreentryfullpathrrr clear_dir^s   r+cCs6tj|j|jkrtt|r2||jkr2ttdSr )r$rpmdetect_releasever installroot releaseverr RELEASEVER_MSGCANT_RESET_RELEASEVER)conftargetrrrcheck_release_verosr4c CsRztdd}|dWn4tyL}zttd|WYd}~n d}~00dS)Nz /dev/tty0wbs[9;0]z%Screen blanking can't be disabled: %s)rwrite Exceptionprintr)Zttyerrrdisable_blankingxs  r:c@seZdZddZddZddZddZd d Zd d Zd dZ e dZ e dZ e dZ e dZ e dZe dZe dZe dZe dZe dZe dZe dZe dZe dZdS)StatecCs||_i|_|dSr ) statefile_data_read)selfr<rrr__init__szState.__init__cCsz:t|j}t||_Wdn1s.0YWn@tyRi|_Yn*tyzi|_tt d|jYn0dS)Nz;Failed loading state file: %s, continuing with empty state.) rr<jsonloadr=r ValueErrorrwarningr)r?fprrrr>s .    z State._readcCsZtjtj|jt|jd$}tj |j |dddWdn1sL0YdS)NwTindentZ sort_keys) r$r% ensure_dirrrdirnamer<rrAdumpr=)r?Zoutfrrrr6sz State.writecCs&tj|jrt|j|dSr )rrexistsr<r&r>r?rrrclears z State.clearcCs|Sr rrNrrr __enter__szState.__enter__cCs|dur|dSr )r6)r?exc_type exc_value tracebackrrr__exit__szState.__exit__cs"fdd}fdd}t||S)Ncs||j<dSr )r=)r?valueoptionrrsetpropszState._prop..setpropcs |jSr )r=getrNrVrrgetpropszState._prop..getprop)property)rWrXrZrrVr_props  z State._prop state_versiondownload_statusdestdirtarget_releaseversystem_releasevergpgcheckgpgcheck_reposrepo_gpgcheck_reposupgrade_statusupgrade_command distro_syncpoweroff_afterenable_disable_reposmodule_platform_idN)__name__ __module__ __qualname__r@r>r6rOrPrTr\r]r^r_r`rarbrcrdrerfrgrhrirjrrrrr;s*  r;c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)PlymouthOutputzA plymouth output helper class. Filters duplicate calls, and stops calling the plymouth binary if we fail to contact it. cCsd|_t|_d|_dSNT)alivedict _last_args _last_msgrNrrrr@szPlymouthOutput.__init__cGsf||j|k}|jr|r"|dkr`ztt|f|dk|_WntyTd|_Yn0||j|<|jS)N--pingrF)rrrYrprPLYMOUTHr')r?cmdargsZdupe_cmdrrr _plymouths   zPlymouthOutput._plymouthcCs |dS)Nrt)rxrNrrrpingszPlymouthOutput.pingcCs4|jr |j|kr |dd|j||_|dd|S)Nz hide-messagez--textzdisplay-message)rsrxr?msgrrrmessageszPlymouthOutput.messagec CsPd}z$ttdg}tdt|r&d}Wnttfy>Yn0|dd|S)NZupdatesz--helpz--system-upgradesystem-upgradez change-modez--)rruresearchr rr'rx)r?modesrrrset_modes zPlymouthOutput.set_modecCs|ddt|S)N system-updatez --progress)rxstr)r?percentrrrprogressszPlymouthOutput.progressN) rkrlrm__doc__r@rxryr|rrrrrrrns  rnc@s$eZdZddZddZddZdS)PlymouthTransactionProgresscCs|||||dSr )_update_plymouth)r?packageactionZti_doneZti_totalZts_doneZts_totalrrrrsz$PlymouthTransactionProgress.progresscCsd|dkr dS|tjjkr0ttd||ntdtd||t|||||dS)NgV@Zg$@)r$callbackZ PKG_VERIFYPlymouthrintr| _fmt_eventr?rrcurrenttotalrrrrs  z,PlymouthTransactionProgress._update_plymouthcCs tjj||}d||||fS)Nz[%d/%d] %s %s...)r$ transactionZACTIONSrYrrrrr sz&PlymouthTransactionProgress._fmt_eventN)rkrlrmrrrrrrrrsrccsFt}|j|jddd}|D] }|d}||kr6q |}|Vq dS)zVFind all boots with this message id. Returns the entries of all found boots. r) MESSAGE_IDZ_UIDN_BOOT_ID)rReaderZ add_matchhex) message_idjZoldbootr)Zbootrrr find_bootssrc Cspttdd}tttD]:\}}td|d|d|d|dd|d dq|dkrlttd dS) Nz3The following boots appear to contain upgrade logs:u){} / {.hex}: {:%Y-%m-%d %H:%M:%S} {}→{}rrZ__REALTIME_TIMESTAMPSYSTEM_RELEASEVERz??TARGET_RELEASEVERz-- no logs were found --)r8r enumeraterID_TO_IDENTIFY_BOOTSformatrY)nr)rrr list_logs$s   rcCsZtt|}z*|dkrt|dkr*|d8}||dWStyTttdYn0dS)Nrrrz!Cannot find logs with this index.)listr IndexErrorr r)rrZbootsrrr pick_boot2s  rcCsDtt|}tdd|jg}||j}|dkr@tjt ddS)NZ journalctlz--bootrz%Unable to match systemd journal entry) rrrrwait returncoder$ exceptionsErrorr)rZboot_idZprocessrcrrrshow_logAs  r)ZdownloadZcleanrupgradelogcs eZdZdZfddZZS)SystemUpgradePluginr}cs8tt||||r4|t|t|tdSr )superrr@Zregister_commandSystemUpgradeCommandOfflineUpgradeCommandOfflineDistrosyncCommand)r?basecli __class__rrr@Rs   zSystemUpgradePlugin.__init__)rkrlrmnamer@ __classcell__rrrrrOsrcs(eZdZdZedZdZfddZeddZ dd Z d d Z d d Z ddZ ddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Z d6d7Z!d8d9Z"d:d;Z#dd?Z%d@dAZ&dBdCZ'Z(S)Dr)r}fedupz+Prepare system for upgrade to a new releasezvar/lib/dnf/system-upgradecsjtt||tj|jjj|j |_ tj|j d|_ tj|jjjd|_ t tj|j d|_dS)Nzsystem-upgrade-transaction.jsonrzsystem-upgrade-state.json)rrr@rrr#rr2r.DATADIRdatadirtransaction_file magic_symlinkr;state)r?rrrrr@`s zSystemUpgradeCommand.__init__cCs`|jdddtdd|jdddtd d|jd d td d td|jdttdddS)Nz--no-downgraderg store_falsez=keep installed packages if the new release's version is older)destrhelpz --poweroffrh store_truez1power off system after the operation is completedtidrz[%s]|)nargschoicesmetavarz--numberzwhich logs to show)typer) add_argumentrCMDSr#r)parserrrr set_argparserhs  z"SystemUpgradeCommand.set_argparsercCs(tj||tj|jj|jjtjjddS)zLog directly to the journal.)rZPRIORITYrrZ DNF_VERSIONN) rsendZ LOG_NOTICErrar`r$constZVERSION)r?r|rrrr log_statusvszSystemUpgradeCommand.log_statuscCs|d|ddS)Ncheck pre_configure _call_subrNrrrrs z"SystemUpgradeCommand.pre_configurecCs|ddS)N configurerrNrrrrszSystemUpgradeCommand.configurecCs|ddS)NrunrrNrrrrszSystemUpgradeCommand.runcCs|ddS)NrrrNrrrrun_transactionsz$SystemUpgradeCommand.run_transactioncCs|ddS)NZresolvedrrNrrr run_resolvedsz!SystemUpgradeCommand.run_resolvedcCs.t||d|jjdd}t|r*|dS)Nrr)getattroptsrcallable)r?rZsubfuncrrrrszSystemUpgradeCommand._call_subcCs(|jjtkr$tdj|d}t|dS)NzFIncompatible version of data. Rerun 'dnf {command} download [OPTIONS]'command)rr] STATE_VERSIONrrr r?rr{rrr_check_state_versions  z)SystemUpgradeCommand._check_state_versioncCs*|j|jj_|jjr|jjnd|jj_dSr )rrr2cachedirrr_rNrrr _set_cachedirs z"SystemUpgradeCommand._set_cachedircCsttjjtjjg}ttjj}i}i}|jjjD]^}|j |vrn|j }|j | |j ji t|i|j <q4|j |vr4|j | t|j i|j <q4||fS)z forward = {repoid:{pkg_nevra: {tsi.action: tsi.reason}} reverse = {pkg_nevra: {tsi.action: tsi.reason}} :return: forward, reverse )setr$rZBACKWARD_ACTIONSlibdnfZ!TransactionItemAction_REINSTALLEDZFORWARD_ACTIONSrrrpkgreason setdefaultrepoidr)r?Zbackward_actionZforward_actionsZforwardreverseZtsirrrr%_get_forward_reverse_pkg_reason_pairss    z:SystemUpgradeCommand._get_forward_reverse_pkg_reason_pairscCs`|j|jj_|jjr|jjnd|jj_d|jjkrH|jjsHtt dnd|jjkr\d|j_dS)Noffline-distrosynczFCommand 'offline-distrosync' cannot be used with --no-downgrade optionoffline-upgradeF) rrr2rrr_rrgr rrNrrrpre_configure_downloads  z+SystemUpgradeCommand.pre_configure_downloadcCs |dSr rrNrrrpre_configure_rebootsz)SystemUpgradeCommand.pre_configure_rebootcCs.||jjr|jj|j_|jj|jj_dSr ) rrrirrepos_edr`rr2r/rNrrrpre_configure_upgrades z*SystemUpgradeCommand.pre_configure_upgradecCs |dSr rrNrrrpre_configure_cleansz(SystemUpgradeCommand.pre_configure_cleancCsd|jjksd|jjkrttdt}|rLtd}t|t||j rtd}|j j j s|j j jd|d|dsttd td t|j j |jjd nd |jjkr|j|jd |jj_d |jj_d |jj_d |jj_d |jj_|j j jdg7_dS)Nr}rz\WARNING: this operation is not supported on the RHEL distribution. Proceed at your own risk.z-Additional information for System Upgrade: {}zyBefore you continue ensure that your system is fully upgraded by running "dnf --refresh upgrade". Do you want to continuez {} [y/N]: z {} [Y/n]: )r{Zdefaultyes_msgzOperation aborted.r)r3rTtest)rrrrDrrrrr rZ _promptWantedr2ZassumenooutputZ userconfirmerrorsysexitr4r/rZ _populate_update_security_filterdemands root_user resolvingavailable_repossack_activationZfreshest_metadataZtsflags)r?Zhelp_urlr{rrrconfigure_downloads,        z'SystemUpgradeCommand.configure_downloadcCsd|jj_dSrorrrrNrrrconfigure_rebootsz%SystemUpgradeCommand.configure_rebootcCsd|jj_d|jj_d|jj_d|jj_|jj|j_|jj durN|jj |j j _ |jj dur||j j D]}|j|jj v|_ qf|jjdur|j j D]}|j|jjv|_q|jj|j j _d|jj_d|j j _t|jj_d|j j _d|j j _dS)NTF)rrrrrrrrgrrbrr2rcreposvaluesrrd repo_gpgcheckrjZ cacheonlyZ assumeyesrZtransaction_displayZclean_requirements_on_removeZinstall_weak_deps)r?rrrrconfigure_upgrades&            z&SystemUpgradeCommand.configure_upgradecCsd|jj_dSrorrNrrrconfigure_clean sz$SystemUpgradeCommand.configure_cleancCsdSr rrNrrr configure_logsz"SystemUpgradeCommand.configure_logcCs~|jjdksttd||jj|jj|jjkrRtdj|jjd}t|t j |j rlttdt j|jdS)Ncompletezsystem is not ready for upgradezZthe transaction was not prepared for '{command}'. Rerun 'dnf {command} download [OPTIONS]'rzupgrade is already scheduled)rr^r rrrrrfrrrlexistsrr$r%rJrrzrrr check_reboots   z!SystemUpgradeCommand.check_rebootcCstj|js$ttdtdt|j|j krLttdtdt j j |j|jj}|sp|jj}|||jjdkstdj|d}t|dS)Nz-trigger file does not exist. exiting quietly.rz1another upgrade tool is running. exiting quietly.readyz/use 'dnf {command} reboot' to begin the upgrader)rrr rrrr SystemExitreadlinkrr$ZyumZmiscZunlink_frrfrrrrerr rrrr check_upgrade!s  z"SystemUpgradeCommand.check_upgradecCs@t|j|j|j}d|_Wdn1s20YdS)Nr )rsymlinkrrrrer?rrrr run_prepare4sz SystemUpgradeCommand.run_preparecCsL||jjddksdS|jj|j_|tdt|jt dS)NrrzRebooting to perform upgrade.) rrrrhrrrREBOOT_REQUESTED_IDr6rrNrrr run_reboot;s   zSystemUpgradeCommand.run_rebootcsjjrjn jjjdvrjfddjjjD}|r\j|fddjjj D}|rj|j .}d|_ jj j |_jj j|_Wdn1s0YdS)N)rrcs$g|]}jjj|jr|jqSr)rhistorygrouprYr.0grNrr Tz5SystemUpgradeCommand.run_download..cs$g|]}jjj|jr|jqSr)rrenvrYrrrNrrrWrZ downloading)rrgrZ upgrade_allrZ read_compscompsgroupsZenv_group_upgradeZ environmentsrr^r2r/r`r_)r?Zinstalled_groupsZinstalled_environmentsrrrNr run_downloadJs       z!SystemUpgradeCommand.run_downloadcCsd}|j}d|_|j}Wdn1s,0Y|dkrHtd}n|dkrZtd}ntd}||tttdt |t t |j |j |_|jdS) NZ incompleterz1Starting offline upgrade. This will take a while.rz4Starting offline distrosync. This will take a while.z0Starting system upgrade. This will take a while.r)rrerfrrUPGRADE_STARTED_IDrrrr|r:r rrreplayr)r?rrr{rrr run_upgrade`s $     z SystemUpgradeCommand.run_upgradecCsxttdt|jjjtj |jjjj g|j .}d|_ d|_ d|_d|_d|_Wdn1sj0YdS)NzCleaning up downloaded data...)rrrr+rr2rr$Z persistorZTempfilePersistorZdb_pathrr^r]rerfr_rrrr run_cleanzs zSystemUpgradeCommand.run_cleancCs |jjrt|jjntdSr )rnumberrrrNrrrrun_logszSystemUpgradeCommand.run_logcCs|jdS)z5Adjust transaction reasons according to stored valuesN)r!Zpost_transactionrNrrrresolved_upgradesz%SystemUpgradeCommand.resolved_upgradec Cs|jj}|s&ttddSt|}z`t|j d,}t j ||ddd| dWdn1sn0Yt td|j Wn>ty}z&tjtdt|WYd}~n d}~00tj|jjj}|j}d |_t|_|jj|_|jjj|_d d |jj D|_!d d |jj D|_"||_#|jjj$|_%|jjj&|_&|jj'|_(|jjj)|_)|jj*|_+Wdn1s0Yt,j|jj*d }t||-tdt.dS)NzKThe system-upgrade transaction is empty, your system is already up-to-date.rFrGTrH zTransaction saved to {}.zError storing transaction: {}rcSsg|]}|jr|jqSr)rbrrrrrrrsz=SystemUpgradeCommand.transaction_download..cSsg|]}|jr|jqSr)rrr(rrrrsrzDownload finished.)/rrZ get_currentZpackagesrrrr rrrArLr6r8rr'r$rr rr,r-r2r.rr^rr]rrgrbrrrcrdrar/r`rjrrir_rrfDOWNLOAD_FINISHED_MSGrDOWNLOAD_FINISHED_ID)r?rdatafr9Z system_verrr{rrrtransaction_downloadsB (0        * z)SystemUpgradeCommand.transaction_downloadcCsX|jjrtd}ntd}t|||t||jj ddkrTt |jjdS)Nz1Upgrade complete! Cleaning up and powering off...z.Upgrade complete! Cleaning up and rebooting...rr) rrhrrr|rUPGRADE_FINISHED_IDr#rrr)r?Zupgrade_complete_msgrrrtransaction_upgrades   z(SystemUpgradeCommand.transaction_upgrade))rkrlrmaliasesrsummaryrr@ staticmethodrrrrrrrrrrrrrrrrrrrrr rrrrr"r#r%r&r-r/rrrrrrZsH       (rc@seZdZdZedZdS)r)rz%Prepare offline upgrade of the systemNrkrlrmr0rr1rrrrrsrc@seZdZdZedZdS)r)rz(Prepare offline distrosync of the systemNr3rrrrrsr)F)N)?r subprocessrrrrrArZos.pathr~rZuuidZsystemdrZdnfpluginscorerrr$Zdnf.clir Zdnf.i18nr Zdnf.transactionZdnf.transaction_srr r Z libdnf.confrZUUIDr*rr r.rrur0r)r1rrrr+r4r:objectr;rnrrZTransactionProgressrrrrrrZPluginrrZCommandrrrrrrrsj           A.  s