Mini Shell

Direktori : /lib64/python3.6/site-packages/pyanaconda/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/pyanaconda/__pycache__/rescue.cpython-36.pyc

3

Z��e[L�@s�ddlmZddlmZddlmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZmZddlmZdd	lmZdd
lmZddlmZmZddlmZdd
lmZddlmZddl m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1m2Z2ddl3Z3ddl4Z4ddl5Z5ddl6m7Z7ddl8m9Z9e9e:�Z;dddgZ<d-dd�Z=d d!�Z>d"d#�Z?Gd$d%�d%e7�Z@Gd&d'�d'eA�ZBGd(d�de�ZCGd)d�de�ZDGd*d�de�ZEd+d,�ZFdS).�)�util)�conf)�ANACONDA_CLEANUP�THREAD_STORAGE�QUIT_MESSAGE)�DEVICE_TREE)�STORAGE)�MountFilesystemError)�OSData�DeviceFormatData)�
sync_run_task)�	threadMgr)�flags)�_�N_)�runPostScripts)�tui_quit_callback)�NormalTUISpoke)�	KS_REBOOT�KS_SHUTDOWN)�App)�YesNoDialog�PasswordDialog)�ListColumnContainer)�Prompt)�
InputState)�
ScreenHandler)�
TextWidget�CheckboxWidgetN)�Enum)�get_module_logger�RescueModeSpoke�RootSelectionSpoke�RescueStatusAndShellSpoke�cCs�tjdtj�r*tdd�}|j�}|j�nd}y(t|dd�}|rL|j|�|j�Wn.tk
r�}ztj	d|�WYdd}~XnXdS)zMake the fs tab.z/proc/mounts�rr$z
/etc/fstab�azfailed to write /etc/fstab: %sN)
�os�access�R_OK�open�read�close�write�IOError�log�info)�instPath�f�buf�e�r5�/usr/lib64/python3.6/rescue.py�	makeFStab7s


r7cCs�tjjrdStjdtj�sdStjd|ftj�rTtd|fd�}|j�}|j�nd}|j	d�d
krjdStdd�}|j�}|j�|j	d�dkr�dSt
jd|fd|f�td|fd	�}|j|�|j�dS)z(Make the resolv.conf file in the chroot.Nz/etc/resolv.confz%s/etc/resolv.confr%r$Z
nameserver�z%s/etc/resolv.conf.bakzw+���r9)
r�target�is_imager'r(r)r*r+r,�find�shutilZcopyfiler-)r1r2r3r5r5r6�makeResolvConfIs*


r>cCsLxFdD]>}ytjd|d	|�Wqtk
rBtjd
|�YqXqWdS)
z2I don't know why I live. Maybe I should be killed.�services�	protocols�group�
man.config�
nsswitch.conf�selinux�mke2fs.confz/mnt/runtime/etc/z/etc/z0Failed to create symlink for /mnt/runtime/etc/%sN)r?r@rArBrCrDrE)r'�symlink�OSErrorr/�debug)r2r5r5r6�create_etc_symlinksksrIc@s eZdZdZdZdZdZdZdS)�RescueModeStatusz"Status of rescue mode environment.znot set�mountedzmount failedzroot not foundN)�__name__�
__module__�__qualname__�__doc__�NOT_SET�MOUNTED�MOUNT_FAILED�ROOT_NOT_FOUNDr5r5r5r6rJus
rJc@sTeZdZdZddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
ddd�ZdS)�Rescuea�Rescue mode module.

        Provides interface to:
        - find and unlock encrypted devices
        - find existing systems
        - mount selected existing system and run kickstart scripts
        - run interactive shell
        - finish the environment (reboot)

        Dependencies:
        - storage module
        - storage initialization thread

        Initialization:
        rescue_data - data of rescue command seen in kickstart
                      <pykickstart.commands.rescue.XX_Rescue>
        reboot      - flag for rebooting after finishing
                      bool
        scritps     - kickstart scripts to be run after mounting root
                      <pyanaconda.kickstart.AnacondaKSScript>

    NFTcCsftj�|_tjt�|_||_||_d|_d|_d|_	t
j|_d|_
|rbd|_|jpT||_|j|_	dS)NFT)r�	get_proxyZ_storage_proxyr�_device_tree_proxy�_scripts�reboot�	automated�mount�rorJrP�status�errorZnomountZromount)�selfZrescue_datarX�scripts�rescue_nomountr5r5r6�__init__�s
zRescue.__init__cCstjt�t�dS)N)r
�waitrrI)r^r5r5r6�
initialize�s
zRescue.initializecCsZ|jj�}tj|�}t|�tj|jj��}dd�|D�}|sFtj	|_
tjdt
|��|S)zList of found roots.cSsg|]}|j�r|�qSr5)�get_root_device)�.0r%r5r5r6�
<listcomp>�sz%Rescue.find_roots.<locals>.<listcomp>zThese systems were found: %s)rVZFindExistingSystemsWithTaskrrUrr
Zfrom_structure_listZGetExistingSystemsrJrSr\r/rH�str)r^�	task_path�
task_proxy�rootsr5r5r6�
find_roots�s

zRescue.find_rootsc:Cs�y:|jj|j�|j�}tj|�}t|�tjdt	j
j�Wn@tk
rz}z$tj
dt	j
j|�tj|_||_
dSd}~XnXt	jjr�ytdt	j
jd�}|j�Wn.tk
r�}ztjd|�WYdd}~XnXtjjdd	�jd
�}dd�|D�}tjdd
j||��y tjd
tj��r(tj d
d�Wn0t!k
�rZ}ztj
d|�WYdd}~XnX|j�s�yt"t	j
j�Wn4t!tfk
�r�}ztj
d|�WYdd}~XnXt#�|j�r�|j$�r�t%|j$�tj&|_dS)z&Mounts selected root and runs scripts.z!System has been mounted under: %sz#Mounting system under %s failed: %sFNz%s/.autorelabelzw+zError turning on selinux: %sZLD_LIBRARY_PATHr$�:cSsg|]}d|�qS)z/mnt/sysimage%sr5)reZldirr5r5r6rf�sz%Rescue.mount_root.<locals>.<listcomp>z
/usr/bin/bashz	/bin/bashzError symlinking bash: %szError making resolv.conf: %sT)'rVZMountExistingSystemWithTaskrdr[rrUrr/r0rr:�system_rootr	r]rJrRr\ZsecurityrDr*r,r.Zwarningr'�environ�get�splitrZsetenv�joinr(r)rFrGr>r7rWrrQ)r^�rootrhrir4�fdZlibdirsrKr5r5r6�
mount_root�sH

zRescue.mount_rootcCsDg}x:|jj�D],}tj|jj|��}|jdks2q|j|�qW|S)zeGet a list of names of locked LUKS devices.

        All LUKS devices are considered locked.
        Zluks)rVZ
GetDevicesrZfrom_structureZ
GetFormatData�type�append)r^Zdevice_names�device_nameZformat_datar5r5r6�get_locked_device_names�s
zRescue.get_locked_device_namescCs|jj||�S)zUnlocks LUKS device.)rVZUnlockDevice)r^rw�
passphraser5r5r6�
unlock_deviceszRescue.unlock_devicecCs0tjjd�rtj�nttd��tjd�dS)zLaunch a shell.z	/bin/bashz9Unable to find /bin/bash to execute!  Not starting shell.�N)	r'�path�existsrZexecConsole�printr�time�sleep)r^r5r5r6�	run_shells
zRescue.run_shellrcCs$tj|�|jr tjdddg�dS)z'Finish rescue mode with optional delay.Z	systemctlz	--no-wallrXN)rr�rXrZexecWithRedirect)r^�delayr5r5r6�finishs
z
Rescue.finish)NFNT)r)rLrMrNrOrarcrkrtrxrzr�r�r5r5r5r6rT}s
8	rTcs�eZdZdZ�fdd�Zd�fdd�	Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�Zdd�Zdd�Z�ZS)r!z@UI offering mounting existing installation roots in rescue mode.cs,t�jdddd�td�|_d|_||_dS)N)�data�storage�payloadrT)�superrar�title�
_container�_rescue)r^�rescue)�	__class__r5r6ra$s
zRescueModeSpoke.__init__Ncs�t�j|�td�tjj}|jjt|��t	d�|_
|j
jttd��|j�|j
jttd��|j
�|j
jttd��|j�|j
jttd��|j�|jj|j
�dS)Na�The rescue environment will now attempt to find your Linux installation and mount it under the directory : %s.  You can then make any changes required to your system.  Choose '1' to proceed with this step.
You can choose to mount your file systems read-only instead of read-write by choosing '2'.
If for some reason this process does not work choose '3' to skip directly to a shell.

r8ZContinuezRead-only mountz
Skip to shellz
Quit (Reboot))r��refreshrrr:rm�window�add_with_separatorrrr��add�_read_write_mount_callback�_read_only_mount_callback�_skip_to_shell_callback�_quit_callback)r^�args�msg)r�r5r6r�*s

zRescueModeSpoke.refreshcCs|j�dS)N)�_mount_and_prompt_for_shell)r^r�r5r5r6r�@sz*RescueModeSpoke._read_write_mount_callbackcCsd|j_|j�dS)NT)r�r[r�)r^r�r5r5r6r�Csz)RescueModeSpoke._read_only_mount_callbackcCs|j�dS)N)�!_show_result_and_prompt_for_shell)r^r�r5r5r6r�Gsz'RescueModeSpoke._skip_to_shell_callbackcCs:ttt��}tj|�|j�|jr6d|j_|jj	�dS)NT)
rrrr�push_screen_modal�redraw�answerr�rXr�)r^r��dr5r5r6r�Js
zRescueModeSpoke._quit_callbackcCsd|j_|j�|j�dS)NT)r�rZ�_mount_rootr�)r^r5r5r6r�Rsz+RescueModeSpoke._mount_and_prompt_for_shellcCs*|jjr$|jjr|j�|j�dSt�S)z! Override the default TUI prompt.N)r�rYrZr�r�r)r^r�r5r5r6�promptWszRescueModeSpoke.promptcCs|jj|�rtjStjSdS)z0Override any input so we can launch rescue mode.N)r��process_user_inputr�	PROCESSEDZ	DISCARDED)r^r��keyr5r5r6�input`szRescueModeSpoke.inputcCs`|j�|jj�}|sdSt|�dkr0|d}n t|�}tj|�|j�|j}|jj	|�dS)Nr8r)
�_unlock_devicesr�rk�lenr"rr�r��	selectionrt)r^rjrrZ
root_spoker5r5r6r�gs


zRescueModeSpoke._mount_rootcCs t|j�}tj|�|j�dS)N)r#r�rr�r,)r^Z	new_spoker5r5r6r�{s

z1RescueModeSpoke._show_result_and_prompt_for_shellcCsbd}xX|jj�D]J}xD|dkrBt|�}tj|�|js8P|jj�}|jj||�rRPd}qWqWdS)z*Attempt to unlock all locked LUKS devices.N)r�rxrrr�r��striprz)r^ryrwZdialogr5r5r6r��s

zRescueModeSpoke._unlock_devicescCsdS)zMove along home.Nr5)r^r5r5r6�apply�szRescueModeSpoke.apply)N)N)rLrMrNrOrar�r�r�r�r�r�r�r�r�r�r�r��
__classcell__r5r5)r�r6r!s
	csTeZdZdZ�fdd�Zedd��Zd�fdd�	Zdd	d
�Zdd�Z	d
d�Z
�ZS)r#z?UI displaying status of rescue mode mount and prompt for shell.cs&t�jdddd�td�|_||_dS)N)r�r�r�zRescue Shell)r�rarr�r�)r^r�)r�r5r6ra�s
z"RescueStatusAndShellSpoke.__init__cCsdS)NTr5)r^r5r5r6�indirect�sz"RescueStatusAndShellSpoke.indirectNcst�j|�td�t}td�}d}|jjr�|jj}|tjkrn|jj	rL|}n|}t
td�dtjj
i|�}nx|tjkr�|jj	r�|}n|}td�jt|jj�tjj
d�}t
|d|�}n,|tjkr�|jj	r�|}nd}t
td	�|�}n"|jj	r�|}nd}t
td
�|�}|jj|�dS)Nz3Run %s to unmount the system when you are finished.zGWhen finished, please exit from the shell and your system will reboot.
z�Your system has been mounted under %(mountpoint)s.

If you would like to make the root of your system the root of the active system, run the command:

	chroot %(mountpoint)s

Z
mountpointzpAn error occurred trying to mount some or all of your system: {message}

Some of it may be mounted under {path}.)�messager|� r$z%You don't have any Linux partitions.
zNot mounting the system.
)r�r�rrr�rZr\rJrQrXrrr:rmrR�formatrgr]rSr�r�)r^r�Z
umount_msgZexit_reboot_msg�textr\Z
finish_msgr�)r�r5r6r��s>



z!RescueStatusAndShellSpoke.refreshcCsV|jjrD|jjr$|jjtjkr$d}nd}|jj�|jj|d�dStt	d�tj
�S)z! Override the default TUI prompt.r{r)r�NzPlease press %s to get a shell)r�rYrXr\rJrSr�r�rrZENTER)r^r�r�r5r5r6r��s
z RescueStatusAndShellSpoke.promptcCs|jj�|jj�tjS)zMove along home.)r�r�r�rr�)r^r�r�r5r5r6r��s

zRescueStatusAndShellSpoke.inputcCsdS)Nr5)r^r5r5r6r��szRescueStatusAndShellSpoke.apply)N)N)rLrMrNrOra�propertyr�r�r�r�r�r�r5r5)r�r6r#�s1
csheZdZdZ�fdd�Zedd��Zedd��Zd�fd	d
�	Zdd�Z	dd
d�Z
dd�Zdd�Z�Z
S)r"z8UI for selection of installed system root to be mounted.cs6t�jdddd�td�|_||_|d|_d|_dS)N)r�r�r�zRoot Selectionr)r�rarr��_roots�
_selectionr�)r^rj)r�r5r6ra�s


zRootSelectionSpoke.__init__cCs|jS)zThe selected root fs to mount.)r�)r^r5r5r6r��szRootSelectionSpoke.selectioncCsdS)NTr5)r^r5r5r6r��szRootSelectionSpoke.indirectNcs�t�j|�td�|_x@|jD]6}tdj|j|j��|j	|kd�}|jj
||j|�qWtd�}|j
jt|��|j
j|j�dS)Nr8z{} on {})r�Z	completedz;The following installations were discovered on your system.)r�r�rr�r�rr�Zos_namerdr�r��_select_rootrr�r�r)r^r�rrZboxr�)r�r5r6r��s
zRootSelectionSpoke.refreshcCs
||_dS)N)r�)r^rrr5r5r6r�szRootSelectionSpoke._select_rootcCst�}|j�|S)z! Override the default TUI prompt.)rZadd_continue_option)r^r�r�r5r5r6r�szRootSelectionSpoke.promptcCs*|jj|�rtjS|tjkr"tjS|SdS)z0Override any input so we can launch rescue mode.N)r�r�rZPROCESSED_AND_REDRAWrZCONTINUEZPROCESSED_AND_CLOSE)r^r�r�r5r5r6r�s

zRootSelectionSpoke.inputcCsdS)zDefine the abstract method.Nr5)r^r5r5r6r� szRootSelectionSpoke.apply)N)N)rLrMrNrOrar�r�r�r�r�r�r�r�r�r5r5)r�r6r"�s
	cCs�d}|jjjr|jj}|jj}|jj}d}tjjr6d}t	j
rR|jjjt
tgkrRd}t||||�}|j�tj�tj�}|jt�t|�}tj|�tj�dS)zStart the rescue mode UI.NTF)Zksdatar��seenr_Zoptsr`rr:r;rZautomatedInstallrX�actionrrrTrcrZget_event_loopZset_quit_callbackrr!rZschedule_screenZrun)ZanacondaZ
ksdata_rescuer_r`rXr�ZloopZspoker5r5r6�start_rescue_mode_ui%s$


r�)r$)GZpyanaconda.corerZ&pyanaconda.core.configuration.anacondarZpyanaconda.core.constantsrrrZ+pyanaconda.modules.common.constants.objectsrZ,pyanaconda.modules.common.constants.servicesrZ(pyanaconda.modules.common.errors.storager	Z,pyanaconda.modules.common.structures.storager
rZpyanaconda.modules.common.taskrZpyanaconda.threadingr
Zpyanaconda.flagsrZpyanaconda.core.i18nrrZpyanaconda.kickstartrZpyanaconda.ui.tuirZpyanaconda.ui.tui.spokesrZpykickstart.constantsrrZ
simplelinerZsimpleline.render.adv_widgetsrrZsimpleline.render.containersrZsimpleline.render.promptrZsimpleline.render.screenrZ simpleline.render.screen_handlerrZsimpleline.render.widgetsrrr'r=r�enumrZpyanaconda.anaconda_loggersr rLr/�__all__r7r>rIrJ�objectrTr!r#r"r�r5r5r5r6�<module>sL

"
#yS: