
    W'Fg9                         S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  SSKJ	r	  SSKJ
r
  SSKJr  S rS	 rS
 r " S S5      r " S S5      rS rS rS rS rS rg)    N)	Libosinfo   )
urlfetcher   )progress)logc                     U S:g  $ )Nroot )logins    6/usr/share/virt-manager/virtinst/install/unattended.py_is_user_login_safer      s    F?    c                      [         R                  " 5       n [        R                  " U 5      R                  n[        U 5      (       d  gX4$ )N)NN)getpassgetuserpwdgetpwnampw_gecosr   )hostuserrealnames     r   _login_from_hostuserr      s9     H||H%..Hx((r   c                 (	   S nS n[         R                  " 5       nUR                  n	UR                  n
U	(       d  [        5       u  pU	(       af  U	R	                  5       n	[        U	5      (       d$  [        [        S5      UR                  U	S.-  5      eUR                  U	5        UR                  U
5        U R                  5       (       a6  UR                  5       (       d!  [        [        S5      UR                  -  5      eUR                  UR                  5       =(       d    S5        U R                  5       (       a6  UR                  5       (       d!  [        [        S5      UR                  -  5      eUR!                  UR                  5       =(       d    S5        UR#                  5       (       a  SOS	nUR%                  5       (       a  S
nUR'                  U5        UR)                  U5        [*        R,                  " SSU5      nUR/                  U5        U" 5       nU(       a  UR1                  U5        U" 5       nU(       a"  UR3                  U5        UR5                  U5        U(       a  UR7                  U5        UR8                  (       a  UR;                  UR8                  5        UR<                  (       a  UR?                  UR<                  5        [@        RB                  " S5        [@        RB                  " SURE                  5       5        [@        RB                  " SURG                  5       5        [@        RB                  " SURI                  5       5        [@        RB                  " SURK                  5       5        [@        RB                  " SURM                  5       5        [@        RB                  " SURO                  5       5        [@        RB                  " SURQ                  5       5        [@        RB                  " SURS                  5       5        [U        US5      (       a%  [@        RB                  " SURW                  5       5        [@        RB                  " SURY                  5       5        [@        RB                  " SUR[                  5       5        U$ )z*
Build a Libosinfo.InstallConfig instance
c                      Sn [         R                  R                  U 5      nUR                  S5      n[	        U5      S:  a  US   $ g )Nz/etc/localtimez	zoneinfo/r   )ospathrealpathsplitlen)TZ_FILElinkpathtokenss      r   get_timezone)_make_installconfig.<locals>.get_timezone'   sC    "77##G,,v;?!9 r   c                  2    [         R                  " 5       S   $ )Nr   )locale	getlocaler   r   r   get_language)_make_installconfig.<locals>.get_language.   s    !!$$r   z4%(osname)s cannot use '%(loginname)s' as user-login.)osname	loginnamez(%s requires the user-password to be set. z)%s requires the admin-password to be set.z/dev/vdaz/dev/sdaCz![{|}~[\]^':; <=>?@!"#$%`()+/.,*&]-z6InstallScriptConfig created with the following params:zusername: %szrealname: %sztarget disk: %szhardware arch: %szhostname: %sztimezone: %szlanguage: %szkeyboard: %sget_installation_urlzurl: %szreg-login %szproduct-key: %s).r   InstallConfig
user_loginr   lowerr   RuntimeError_nameset_user_loginset_user_realnamerequires_user_passwordget_user_passwordset_user_passwordrequires_admin_passwordget_admin_passwordset_admin_passwordsupports_virtiodisk
is_windowsset_target_diskset_hardware_archresubset_hostnameset_l10n_timezoneset_l10n_languageset_l10n_keyboardset_installation_url	reg_loginset_reg_loginproduct_keyset_reg_product_keyr   debugget_user_loginget_user_realnameget_target_diskget_hardware_archget_hostnameget_l10n_timezoneget_l10n_languageget_l10n_keyboardhasattrr/   get_reg_loginget_reg_product_key)scriptosobjunattended_dataarchhostnameurlr#   r(   configr   r   tgttimezonelanguages                 r   _make_installconfigrc   #   s{   % $$&F
 &&E))H.0"5))HI ::E:;< < 	e$  * 	%%''--//89JJ 	 _>>@FBG 	&&((..009:JJ 	 o@@BHbI 1133*C
3 T" vv;S(KH
! ~H  * ~H  *  *
##C(  _667""""?#>#>?IIFGIInf3356IInf6689II!7!7!9:II!6#;#;#=>IInf1134IInf6689IInf6689IInf6689v-..		)++-	/IInf2245II!;!;!=>Mr   c                       \ rS rSrSr\S 5       r\S 5       rS rS r	S r
S rS	 rS
 rS rS rS rS rS rS rSrg)OSInstallScript   z2
Wrapper for Libosinfo.InstallScript interactions
c                      SSK Jn   U R                  S5      nUR                  5        H5  n[        R
                  R                  UR                  5       -  (       d  M5    g   g)Nr   )OSDBwin7TF)osdictrh   	lookup_osget_install_script_listr   InstallScriptInjectionMethodCDROMget_injection_methods)rh   ri   rY   s      r   have_new_libosinfo"OSInstallScript.have_new_libosinfo   sS    !~~f%224F66<<,,./ / 5 r   c                  6    [        [        R                  S5      $ )NrH   )rV   r   r0   r   r   r   have_libosinfo_installation_url/OSInstallScript.have_libosinfo_installation_url   s    y..0FGGr   c                     Xl         X l        X0l        X@l        S U l        [
        R                  5       (       d  [        [        S5      5      eg )NzAlibosinfo or osinfo-db is too old to support unattended installs.)	_script_osobj_osinfomediaobj_osinfotreeobj_configre   rp   r3   r4   )selfrY   rZ   osinfomediaobjosinfotreeobjs        r   __init__OSInstallScript.__init__   sL    -+1133q "/  0 1 1 4r   c                 6    U R                   R                  5       $ N)rv   get_expected_filenamer{   s    r   r   %OSInstallScript.get_expected_filename   s    ||1133r   c                 z   [         R                  R                  [         R                  R                  S.n[        R
                  " SU5        X!   nU R                  R                  5       nX4-  S:X  a.  [        [        S5      U R                  R                  US.-  5      eU R                  R                  U5        g )N)cdrominitrdzUsing '%s' injection methodr   zKOS '%(osname)s' does not support required injection method '%(methodname)s')r*   
methodname)r   rm   rn   INITRDr   rM   rv   ro   r3   r4   rw   r5   set_preferred_injection_method)r{   namestrnamesinjection_methodsupported_injection_methodss        r   r   .OSInstallScript.set_preferred_injection_method   s     ;;AA<<CC

 			/9 >&*ll&H&H&J#:a? 6 7;;++7CDE E
 	334DEr   c                     [         R                  R                  [         R                  R                  S.n[        R
                  " SU5        U R                  R                  X!   5        g )N)medianetworkzUsing '%s' installation source)r   InstallScriptInstallationSourceMEDIANETWORKr   rM   rv   set_installation_source)r{   r   r   s      r   r   'OSInstallScript.set_installation_source   sN     >>DD @@HH

 			2G<,,U^<r   c                     U R                   R                  U5      n[        U=(       a    UR                  5       (       + 5      $ r   )rv   get_config_paramboolis_optional)r{   config_paramparams      r   _requires_paramOSInstallScript._requires_param   s2    --l;E5%"3"3"5566r   c                 @    U R                  [        R                  5      $ r   )r   r   !INSTALL_CONFIG_PROP_USER_PASSWORDr   s    r   r8   &OSInstallScript.requires_user_password   s    ##;;= 	=r   c                 @    U R                  [        R                  5      $ r   )r   r   "INSTALL_CONFIG_PROP_ADMIN_PASSWORDr   s    r   r;   'OSInstallScript.requires_admin_password   s    ##<<> 	>r   c                     Xl         g r   )rz   )r{   r_   s     r   
set_configOSInstallScript.set_config   s    r   c                    U R                   (       a0  U R                  R                  U R                   U R                  5      $ [	        U R                  S5      (       aA  U R
                  (       a0  U R                  R                  U R
                  U R                  5      $ U R                  R                  U R                  R                  5       U R                  5      $ )Ngenerate_for_tree)
rx   rv   generate_for_mediarz   rV   ry   r   generaterw   
get_handler   s    r   r   OSInstallScript.generate   s    <<22(($,,8 84<<!455$:M:M <<11''7 7 ||$$T[[%;%;%=t||LLr   c                    U R                   (       a0  U R                  R                  U R                   U R                  5      $ [	        U R                  S5      (       aA  U R
                  (       a0  U R                  R                  U R
                  U R                  5      $ U R                  R                  U R                  R                  5       U R                  5      $ )Ngenerate_command_line_for_tree)
rx   rv   generate_command_line_for_mediarz   rV   ry   r   generate_command_linerw   r   r   s    r   generate_cmdline OSInstallScript.generate_cmdline   s    <<??(($,,8 8DLL"BCC## <<>>''7 7||11&&($,,8 	8r   c                 f   U R                   R                  5       nU R                   R                  5       nU R                   R                  S5        U R                   R	                  S5        U R                  5       nU R                   R                  U5        U R                   R	                  U5        U$ )Nz[SCRUBBLED])rz   r9   r<   r:   r=   r   )r{   original_user_passwordoriginal_admin_passworddebug_contents       r   _generate_debugOSInstallScript._generate_debug   s    !%!?!?!A"&,,"A"A"C&&}5''6&&'=>''(?@r   c                    [         R                  " SSS9nUR                  nU R                  5       n[	        US5      R                  U5        U R                  5       n[        R                  " SU5        [        R                  " SU5        U$ )Nzvirtinst-unattended-scriptF)prefixdeletewzGenerated unattended script: %szGenerated script contents:
%s)	tempfileNamedTemporaryFiler5   r   openwriter   r   rM   )r{   fileobj
scriptpathcontentr   s        r   r   OSInstallScript.write  sr    --/?\\
--/Z##G,,,.		3Z@		2MBr   )rz   rx   ry   rw   rv   N)__name__
__module____qualname____firstlineno____doc__staticmethodrp   rs   r~   r   r   r   r   r8   r;   r   r   r   r   r   __static_attributes__r   r   r   re   re      so       H H	14F$=7=>
M8r   re   c                   >    \ rS rSrSrSrSrSrSrSr	S r
S rS rSrg)UnattendedDatai  Nc                     [        US5       nUR                  5       R                  S5      sS S S 5        $ ! , (       d  f       g = f)Nrz
)r   readlinerstrip)r{   pwdfilefobjs      r   _get_passwordUnattendedData._get_password#  s.    '34==?))&1  s	   6
Ac                 \    U R                   (       a  U R                  U R                   5      $ g r   )user_password_filer   r   s    r   r9    UnattendedData.get_user_password'  s'    ""%%d&=&=>> #r   c                 \    U R                   (       a  U R                  U R                   5      $ g r   )admin_password_filer   r   s    r   r<   !UnattendedData.get_admin_password+  s'    ##%%d&>&>?? $r   r   )r   r   r   r   profiler   r1   r   rK   rI   r   r9   r<   r   r   r   r   r   r     s2    GJKI2?@r   r   c                 t    0 nU  H/  nUR                  5       nX1;  a  / X'   X   R                  U5        M1     U$ )z>
Generate a mapping of profile name -> [list, of, rawscripts]
)get_profileappend)script_list
script_maprY   r   s       r   _make_scriptmapr   0  sH     J$$&$"$J""6*	 
 r   c                 L    S/nS nU H  nX0;   d  M
  Un  O   U=(       d    U S   $ )Ndesktopr   r   )profile_namesprofile_prefsfoundps       r   _find_default_profiler   =  s8    KMEE  $M!$$r   c                 &   / nU(       aF  UR                  5       (       d!  [        [        S5      U R                  -  5      eUR	                  5       nU(       d  U R	                  5       nU(       d!  [        [        S5      U R                  -  5      e[        U5      n[        [        UR                  5       5      5      nU(       aN  UR                  U/ 5      nU(       d4  [        [        S5      U R                  USR                  U5      S.-  5      eO/[        U5      n[        R                  " [        S5      U5        XA   n/ nU H"  nUR                  UR                  5       5        M$     [        R                   " SUSR                  U5      5        U$ )Nz6OS '%s' media does not support unattended installationz1OS '%s' does not support unattended installation.z|OS '%(osname)s' does not support unattended installation for the '%(profilename)s' profile. Available profiles: %(profiles)sz, )r*   profilenameprofileszUsing unattended profile '%s'z*Install scripts found for profile '%s': %s)supports_installer_scriptr3   r4   r5   rl   r   listsortedkeysgetjoinr   r   warningr   get_idrM   )	osinfor   os_mediar   r   r   
rawscriptsids	rawscripts	            r   _lookup_rawscriptsr   G  sq   K1133  ! "%+[[23 3 668446ABKK 	 !-J
 123M^^GR0
 5 6 ";;w!YY}5778 8  (6A56@(

 C	

9##%&   II:TYYs^%r   c           	         S n/ n[        U R                  UR                  U5      nU(       a  UR                  5       OS n	U(       a  UR	                  5       OS n
U H  n[        XR                  X5      nUR                  U5        U" U5      nUR                  U5        [        XR                  UU R                  R                  U R                  U5      nUR                  U5        UR                  U5        M     U$ )Nc                     U (       d  gg)Nr   r   r   )r   s    r   _get_installation_source9prepare_install_scripts.<locals>._get_installation_source{  s    r   )r   r   r   get_osinfo_mediaget_osinfo_treere   r   r   rc   r   r\   r5   r   r   )guestr[   r^   r   os_treer   r   scriptsr   r|   r}   r   rY   installationsourcer_   s                  r   prepare_install_scriptsr  y  s    
 G#ELL##X/J 5=X..0$N18G++-dM	 <<H 	--.>?5h?&&'9:$V\\?uzz30&!v   Nr   c                 V   [         R                  " U5      n[        R                  " S X5      nX#l        / n U  H;  nUR                  SS5      S   nUR                  U5      nUR                  Xv45        M=     U$ ! [         a$    U H  n[        R                  " US   5        M     e f = f)N/r   r   )r   ensure_meterr   DirectFetchermeterrsplitacquireFiler   	Exceptionr   unlink)		locations
scratchdirr  fetcherdriverslocationfilenamedriver
driverpairs	            r   download_driversr    s    !!%(E&&tZ?GMG!HsA.q1H((2FNNF-. " N  !JIIjm$ "s   AA: :.B()r   r&   r   r   rB   r   gi.repositoryr   r,   r   r   loggerr   r   r   rc   re   r   r   r   r   r  r  r   r   r   <module>r     si      	 
 	  #   sl D@ @*
%/d<r   