Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fabric.api import env
- import sys
- from ilogue.fexpect import expect, expecting, run , sudo
- def instalar_pxp():
- question = raw_input("Nombre del sistema : ")
- nombre_sistema = question
- proxy = ""
- version = run("grep -o release.. /etc/redhat-release")
- # cambio de los archivos pg_hba y postgres.config#
- archi=open("/var/lib/pgsql/9.5/data/pg_hba.conf",'w')
- archi.write("# TYPE DATABASE USER ADDRESS METHOD\n\n")
- archi.write("# 'local' is for Unix domain socket connections only\n")
- archi.write("local all postgres,dbkerp_conexion,db" + nombre_sistema + "_conexion trust\n")
- archi.write("local all all md5\n")
- archi.write("# IPv4 local connections:\n")
- archi.write("host all all 127.0.0.1/32 md5\n")
- archi.write("host all all 192.168.0.0/16 md5\n")
- archi.write("# IPv6 local connections:\n")
- archi.write("host all all ::1/128 md5\n")
- archi.close()
- ## de aca empezamos a editar para crear un nuevo sistema
- db_pass = "postgres"
- sudo('psql -c "CREATE DATABASE db'+ nombre_sistema +' WITH ENCODING=\'UTF-8\';"', user='postgres')
- sudo('psql -c "CREATE USER db'+ nombre_sistema +'_conexion WITH PASSWORD \'db'+ nombre_sistema +'_conexion\';"', user='postgres')
- sudo('psql -c "ALTER ROLE db'+ nombre_sistema +'_conexion SUPERUSER;"', user='postgres')
- sudo('psql -c "CREATE USER db'+ nombre_sistema +'_admin WITH PASSWORD \'a1a69c4e834c5aa6cce8c6eceee84295\';"', user='postgres')
- sudo('psql -c "ALTER ROLE db'+ nombre_sistema +'_admin SUPERUSER;"', user='postgres')
- if(version == 'release 7'):
- run('systemctl restart postgresql-9.5')
- else:
- run('service postgresql-9.5 restart')
- # instalacion de git para poder bajar el repositoriio pxp y moviendo a la carpeta /var/www/html/kerp/#
- run("mkdir /var/www/html/"+ nombre_sistema)
- run("mkdir /var/www/html/"+ nombre_sistema +"/pxp")
- #Si existe proxy se configura github para el proxy
- run("git clone https://github.com/kplian/pxp.git /var/www/html/"+nombre_sistema+"/pxp")
- run("chown -R apache.apache /var/www/html/"+nombre_sistema+"/")
- run("chmod 700 -R /var/www/html/"+nombre_sistema+"/")
- # haciendo una copia de datosgenerales.samples.php y modificando archivo#
- f = open("/var/www/html/"+nombre_sistema+"/pxp/lib/DatosGenerales.sample.php")
- g = open("/var/www/html/"+nombre_sistema+"/pxp/lib/DatosGenerales.php","w")
- linea = f.readline()
- while linea != "":
- g.write(linea)
- linea = f.readline()
- g.close()
- f.close()
- #TODO VOLVER VARIABLE LA CARPETA PRINCIPAL KERP
- f = open("/var/www/html/"+nombre_sistema+"/pxp/lib/DatosGenerales.php",'r')
- chain = f.read()
- chain = chain.replace("/web/lib/lib_control/","/"+nombre_sistema+"/pxp/lib/lib_control/")
- chain = chain.replace("/kerp-boa/","/"+nombre_sistema+"/")
- chain = chain.replace("dbkerp_conexion","db"+nombre_sistema+"_conexion")
- chain = chain.replace("dbkerp","db"+nombre_sistema)
- chain = chain.replace("/var/lib/pgsql/9.1/data/pg_log/","/var/lib/pgsql/9.5/data/pg_log/")
- f.close()
- otro = open("/var/www/html/"+nombre_sistema+"/pxp/lib/DatosGenerales.php",'w')
- otro.write(chain)
- otro.close()
- run("ln -s /var/www/html/"+nombre_sistema+"/pxp/lib /var/www/html/"+nombre_sistema+"/lib")
- run("ln -s /var/www/html/"+nombre_sistema+"/pxp/index.php /var/www/html/"+nombre_sistema+"/index.php")
- run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_generador /var/www/html/"+nombre_sistema+"/sis_generador")
- run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_organigrama /var/www/html/"+nombre_sistema+"/sis_organigrama")
- run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_parametros /var/www/html/"+nombre_sistema+"/sis_parametros")
- run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_seguridad /var/www/html/"+nombre_sistema+"/sis_seguridad")
- run("ln -s /var/www/html/"+nombre_sistema+"/pxp/sis_workflow /var/www/html/"+nombre_sistema+"/sis_workflow")
- archi=open('/var/www/html/'+nombre_sistema+'/sistemas.txt','w')
- archi.close()
- run("mkdir /var/www/html/"+nombre_sistema+"/reportes_generados")
- run("sudo setfacl -R -m u:apache:wrx /var/www/html/"+nombre_sistema+"/reportes_generados")
- # sudo("yum -y install rpm-build")
- run("sudo setfacl -R -m u:postgres:wrx /var/www/html")
- run("sudo chcon -Rv --type=httpd_sys_rw_content_t /var/www/html/"+nombre_sistema+"/")
- run("sudo setsebool -P httpd_can_network_connect_db=1")
- run("sudo setsebool -P httpd_can_network_connect 1")
- run("php /var/www/html/"+nombre_sistema+"/lib/ratchet/pxp-Server.php > /dev/null 2>&1 &")
- prompts = []
- prompts += expect('Ingrese una opcion.*','1')
- prompts += expect('Ingrese el nombre de la BD.*','db'+nombre_sistema)
- prompts += expect('Desea obtener un backup de la BD.*','NO')
- prompts += expect('los datos de prueba.*','n')
- with expecting(prompts):
- sudo("/var/www/html/"+nombre_sistema+"/pxp/utilidades/restaurar_bd/./restaurar_todo.py" , user="postgres")
- def prueba_local():
- prompts = []
- prompts += expect('is your.*','Jaime')
- prompts += expect('you at stack.*','si')
- with expecting(prompts):
- run("python /root/prueba_local.py")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement