o ckF[ @sVddlZddlZddlZddlZddlZddlZddlmZGdddejj j Z dS)N)getpwnamc@sJeZdZdZdddZddZd d Zd d Zd dZddZ ddZ dS) Installerz5 Base Installer class for Ubuntu-based AMI's *rootNc Cs|dkr ttd}|dkrttd}td|d} | r1| D] \} } | d| | fq#| d|||||||f| dS) 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/%swz%s=%s z%s %s %s %s %s %s %s N)strr randrangeopenitemswriteclose) selfnamecommandminutehourmdaymonthwdaywhoenvfpkeyvaluerH/usr/lib/python3/dist-packages/boto/pyami/installers/ubuntu/installer.pyadd_cron"s zInstaller.add_croncCsVtjd|}t|d}|||t|tjtj Btj B| d|dS)z7 Add this file to the init.d directory z /etc/init.dr z!/usr/sbin/update-rc.d %s defaultsN) ospathjoinr rrchmodstatS_IREADS_IWRITES_IEXECrun)rfilerf_pathfrrradd_init_script3s   zInstaller.add_init_scriptcCsbtjd||ftjds|jddddtdd}|d||f| |tj |<d S) z Add an environemnt variable For Ubuntu, the best place is /etc/environment. Values placed here do not need to be exported. zAdding env variable: %s=%sz/etc/environment.origz)cp /etc/environment /etc/environment.origF)notify exit_on_errorz/etc/environmentaz %s="%s"N) botologinfor r!existsr(r rrenviron)rrrrrrradd_env>s  zInstaller.add_envcC|d|dS)Nz/etc/init.d/%s stopr(r service_namerrrstopLzInstaller.stopcCr6)Nz/etc/init.d/%s startr7r8rrrstartOr;zInstaller.startcCs|d|t|}|S)z3 Create a user on the local system z useradd -m %s)r(r)ruserusrrrr create_userRszInstaller.create_usercCst)z> This is the only method you need to override )NotImplementedError)rrrrinstallZszInstaller.install)rrrrrrN) __name__ __module__ __qualname____doc__rr,r5r:r<r?rArrrrrs   r) boto.pyami.installersr0r os.pathr$rpwdrpyami installersrrrrrs