o
    ȷe                     @   sV   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 G dd dejj	j
Z
dS )    N)getpwnamc                   @   sJ   e Zd ZdZdddZdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dS )	Installerz5
    Base Installer class for Ubuntu-based AMI's
    *rootNc
              
   C   s   |dkrt td}|dkrt td}td| d}
|	r1|	 D ]\}}|
d||f  q#|
d|||||||f  |
  dS )	z
        Write a file to /etc/cron.d to schedule a command
            env is a dict containing environment variables you want to set in the file
            name will be used as the name of the file
        random<      z/etc/cron.d/%swz%s=%s
z%s %s %s %s %s %s %s
N)strr   	randrangeopenitemswriteclose)selfnamecommandminutehourmdaymonthwdaywhoenvfpkeyvalue r   ]/var/www/ideatree/venv/lib/python3.10/site-packages/boto/pyami/installers/ubuntu/installer.pyadd_cron"   s   zInstaller.add_cronc                 C   sV   t jd|}t|d}|| |  t |tjtj	B tj
B  | d|  dS )z7
        Add this file to the init.d directory
        z/etc/init.dr	   z!/usr/sbin/update-rc.d %s defaultsN)ospathjoinr   r   r   chmodstatS_IREADS_IWRITES_IEXECrun)r   filer   f_pathfr   r   r   add_init_script3   s   

zInstaller.add_init_scriptc                 C   sb   t jd||f  tjds| jdddd tdd}|d||f  |	  |tj
|< d	S )
z
        Add an environemnt variable
        For Ubuntu, the best place is /etc/environment.  Values placed here do
        not need to be exported.
        zAdding env variable: %s=%sz/etc/environment.origz)cp /etc/environment /etc/environment.origF)notifyexit_on_errorz/etc/environmentaz
%s="%s"N)botologinfor    r!   existsr(   r   r   r   environ)r   r   r   r   r   r   r   add_env>   s   
zInstaller.add_envc                 C      |  d|  d S )Nz/etc/init.d/%s stopr(   r   service_namer   r   r   stopL      zInstaller.stopc                 C   r6   )Nz/etc/init.d/%s startr7   r8   r   r   r   startO   r;   zInstaller.startc                 C   s   |  d|  t|}|S )z3
        Create a user on the local system
        zuseradd -m %s)r(   r   )r   userusrr   r   r   create_userR   s   zInstaller.create_userc                 C   s   t )z>
        This is the only method you need to override
        )NotImplementedError)r   r   r   r   installZ   s   zInstaller.install)r   r   r   r   r   r   N)__name__
__module____qualname____doc__r   r,   r5   r:   r<   r?   rA   r   r   r   r   r      s    
r   )boto.pyami.installersr0   r    os.pathr$   r   pwdr   pyami
installersr   r   r   r   r   <module>   s   