o
    wÚ7eµ  ã                
   @   sÎ   U d 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
 ddlmZmZ ddlmZ dd	lmZ d
ZdddeegeedƒgdgdœZeed< eeƒZ e e¡Zdede
dededdf
dd„ZdS )zERuncmd: run arbitrary commands at rc.local with output to the consoleé    N)Údedent)Úutil)ÚCloud)ÚConfig)Ú
MetaSchemaÚget_meta_doc)ÚALL_DISTROS)ÚPER_INSTANCEa  Run arbitrary commands at a rc.local like time-frame with output to the
console. Each item can be either a list or a string. The item type affects
how it is executed:


* If the item is a string, it will be interpreted by ``sh``.
* If the item is a list, the items will be executed as if passed to execve(3)
  (with the first arg as the command).

Note that the ``runcmd`` module only writes the script to be run
later. The module that actually runs the script is ``scripts_user``
in the :ref:`Final<boot-Final>` boot stage.

.. note::

    all commands must be proper yaml, so you have to quote any characters
    yaml would eat (':' can be problematic)

.. note::

    when writing files, do not use /tmp dir as it races with
    systemd-tmpfiles-clean LP: #1707222. Use /run/somedir instead.
Ú	cc_runcmdÚRuncmdzRun arbitrary commandsa          runcmd:
            - [ ls, -l, / ]
            - [ sh, -xc, "echo $(date) ': hello world!'" ]
            - [ sh, -c, echo "=========hello world'=========" ]
            - ls -l /root
            - [ wget, "http://example.org", -O, /tmp/index.html ]
    Úruncmd)ÚidÚnameÚtitleÚdescriptionÚdistrosÚ	frequencyÚexamplesÚactivate_by_schema_keysÚmetar   ÚcfgÚcloudÚargsÚreturnc              
   C   s€   d|vrt  d| ¡ d S tj | d¡d¡}|d }zt |¡}t ||d¡ W d S  t	y? } z
t
|ƒd ||¡ƒ‚d }~ww )Nr   z:Skipping module named %s, no 'runcmd' key in configurationÚscriptsiÀ  z"Failed to shellify {} into file {})ÚLOGÚdebugÚosÚpathÚjoinÚ	get_ipathr   ÚshellifyÚ
write_fileÚ	ExceptionÚtypeÚformat)r   r   r   r   Úout_fnÚcmdÚcontentÚe© r*   ú</usr/lib/python3/dist-packages/cloudinit/config/cc_runcmd.pyÚhandleQ   s   ÿ
€ÿr,   )Ú__doc__Úloggingr   Útextwrapr   Ú	cloudinitr   Úcloudinit.cloudr   Úcloudinit.configr   Úcloudinit.config.schemar   r   Úcloudinit.distrosr   Úcloudinit.settingsr	   ÚMODULE_DESCRIPTIONr   Ú__annotations__Ú	getLoggerÚ__name__r   ÚstrÚlistr,   r*   r*   r*   r+   Ú<module>   s4   	ÿÿí
"