def install():
    allhost = []
    allhost.extend(gtmhost)
    allhost.extend(gtmshost)
    allhost.extend(dnhost)
    allhost.extend(cnhost)
    allhost.extend(dnshost)
    ahost = list(set(allhost))
    pakname = package.replace('./', '')
    pakname = pakname.replace('.tgz', '')
    print('======== deploy packages ========')
    f = open('./env.sh', 'w')
    stmt1 = (((('export PATH=' + defbase) + '/') + pakname) + '/bin:$PATH')
    stmt2 = (((('export LD_LIBRARY_PATH=' + defbase) + '/') + pakname) + '/lib:$LD_LIBRARY_PATH')
    f.write((((stmt1 + '\n') + stmt2) + '\n'))
    f.close()
    for i in ahost:
        stmt = (((((((('scp' + ' ') + package) + ' ') + defuser) + '@') + i) + ':') + defbase)
        stmt3 = (((((('scp' + ' ./env.sh ') + defuser) + '@') + i) + ':') + defbase)
        stmt5 = (((((('scp' + ' ./install.sh ') + defuser) + '@') + i) + ':') + defbase)
        subprocess.run(stmt, shell=True)
        print(stmt)
        subprocess.run(stmt3, shell=True)
        print(stmt3)
        subprocess.run(stmt5, shell=True)
        print(stmt5)
        stmt7 = ((('tar -zxf ' + defbase) + '/') + package)
        sshTemp(i, stmt7, 1)
    print()
    print('\n ======== creating gtm master node ======== \n')
    makeTemp(gtmhost[0], gtmdata[0])
    initgtm = ('initgtm -Z gtm -D ' + gtmdata[0])
    sshTemp(gtmhost[0], initgtm, 1)
    gtmconf = ((((((((((('/bin/bash ' + defbase) + '/install.sh gtm ') + gtmhost[0]) + ' ') + str(gtmport[0])) + ' ') + gtmname[0]) + ' ') + gtmdata[0]) + ' ') + gtmuser[0])
    sshTemp(gtmhost[0], gtmconf, 1)
    startgtm = (('gtm_ctl -Z gtm -D ' + gtmdata[0]) + ' start')
    sshTemp(gtmhost[0], startgtm, 1)
    n = 0
    print('\n ======== creating gtm slave node ========')
    for i in gtmshost:
        makeTemp(i, gtmsdata[n])
        print(('\n creating gtm slave node ' + gtmsname[n]))
        initgtms = ('initgtm -Z gtm -D ' + gtmsdata[n])
        sshTemp(i, initgtms, 1)
        gtmsconf = ((((((((((('/bin/bash ' + defbase) + '/install.sh gtm_slave ') + gtmhost[0]) + ' ') + str(gtmsport[n])) + ' ') + gtmsname[n]) + ' ') + gtmsdata[n]) + ' ') + str(gtmport[0]))
        sshTemp(i, gtmsconf, 1)
        startgtms = (('gtm_ctl -Z gtm_standby -D ' + gtmsdata[n]) + ' start')
        sshTemp(i, startgtms, 1)
        n = (n + 1)
    n = 0
    print('\n ======== creating cn node ========')
    for i in cnhost:
        makeTemp(i, cndata[n])
        print(('\n ==========creating cn node ' + cnname[n]))
        if (types == 'pgxz'):
            initcn = ((((((((((('initdb --locale=en_US.UTF-8 -U ' + cnuser[n]) + ' -E utf8 -D ') + cndata[n]) + ' --nodename=') + cnname[n]) + ' --nodetype=coordinator --master_gtm_nodename ') + gtmname[0]) + ' --master_gtm_ip ') + gtmhost[0]) + ' --master_gtm_port ') + str(gtmport[0]))
            sshTemp(i, initcn, 3)
        elif (types == 'pgxc'):
            initcn = ((('initdb -D ' + cndata[n]) + ' --nodename ') + cnname[n])
            sshTemp(i, initcn, 3)
        if (types == 'pgxz'):
            cnconf = ((((((((((('/bin/bash ' + defbase) + '/install.sh cn ') + str(cnport[n])) + ' ') + str(cnpooler[n])) + ' ') + cndata[n]) + ' ') + gtmhost[0]) + ' ') + str(gtmport[0]))
            sshTemp(i, cnconf, 1)
        elif (types == 'pgxc'):
            cnconf = ((((((((((((('/bin/bash ' + defbase) + '/install.sh cn ') + str(cnport[n])) + ' ') + str(cnpooler[n])) + ' ') + cndata[n]) + ' ') + gtmhost[0]) + ' ') + str(gtmport[0])) + ' ') + types)
            sshTemp(i, cnconf, 2)
        startcn = (('pg_ctl -Z coordinator -D ' + cndata[n]) + ' start')
        reloadcn = (('pg_ctl -D ' + cndata[n]) + ' reload')
        sshTemp(i, startcn, 3)
        if (types == 'pgxc'):
            restartcn = ('pg_ctl -Z coordinator restart -m f -D ' + cndata[n])
            sshTemp(i, restartcn, 2)
        sshTemp(i, reloadcn, 1)
        n = (n + 1)
    n = 0
    print('\n ======== creating dn master node ========')
    for i in dnhost:
        makeTemp(i, dndata[n])
        print(('\n ================creating dn node ' + dnname[n]))
        if (types == 'pgxz'):
            initdn = ((((((((((('initdb --locale=en_US.UTF-8 -U ' + dnuser[n]) + ' -E utf8 -D ') + dndata[n]) + ' --nodename=') + dnname[n]) + ' --nodetype=datanode --master_gtm_nodename ') + gtmname[0]) + ' --master_gtm_ip ') + gtmhost[0]) + ' --master_gtm_port ') + str(gtmport[0]))
            sshTemp(i, initdn, 3)
        elif (types == 'pgxc'):
            initdn = ((('initdb -D ' + dndata[n]) + ' --nodename ') + dnname[n])
            sshTemp(i, initdn, 5)
        if (types == 'pgxz'):
            dnconf = ((((((((((('/bin/bash ' + defbase) + '/install.sh dn ') + str(dnport[n])) + ' ') + str(dnpooler[n])) + ' ') + dndata[n]) + ' ') + gtmhost[0]) + ' ') + str(gtmport[0]))
            sshTemp(i, dnconf, 1)
        elif (types == 'pgxc'):
            dnconf = ((((((((((((('/bin/bash ' + defbase) + '/install.sh dn ') + str(dnport[n])) + ' ') + str(dnpooler[n])) + ' ') + dndata[n]) + ' ') + gtmhost[0]) + ' ') + str(gtmport[0])) + ' ') + types)
            sshTemp(i, dnconf, 2)
        startdn = (('pg_ctl -Z datanode -D ' + dndata[n]) + ' start')
        reloaddn = (('pg_ctl -D ' + dndata[n]) + ' reload')
        sshTemp(i, startdn, 3)
        if (types == 'pgxc'):
            restartdn = ('pg_ctl -Z datanode restart -m f -D ' + dndata[n])
            sshTemp(i, restartdn, 2)
        sshTemp(i, reloaddn, 1)
        n = (n + 1)
    n = 0
    print('\n ======== creating dn slave node ========')
    for i in dnshost:
        makeTemp(i, dnsdata[n])
        print(('\n ==============creating dns node ' + dnsname[n]))
        initdns = (((((((('pg_basebackup -p ' + dnsmport[n]) + ' -h ') + dnsmhost[n]) + ' -U ') + dnsuser[n]) + ' -D ') + dnsdata[n]) + ' -X f -P -v')
        sshTemp(i, initdns, 5)
        dnsconf = ((((((((((((((('/bin/bash ' + defbase) + '/install.sh dn_slave ') + str(dnsport[n])) + ' ') + str(dnspooler[n])) + ' ') + dnsdata[n]) + ' ') + dnsmhost[n]) + ' ') + dnsmport[n]) + ' ') + dnsmuser[n]) + ' ') + dnsmname[n])
        changedir = ('chmod 700 ' + dnsdata[n])
        sshTemp(i, dnsconf, 2)
        sshTemp(i, changedir, 1)
        startdns = (('pg_ctl -Z datanode -D ' + dnsdata[n]) + ' start')
        reloaddns = (('pg_ctl -D ' + dnsdata[n]) + ' reload')
        sshTemp(i, startdns, 3)
        if (types == 'pgxc'):
            restartdns = ('pg_ctl -Z datanode restart -m f -D ' + dnsdata[n])
            sshTemp(i, restartdns, 2)
        sshTemp(i, reloaddns, 1)
        n = (n + 1)
def install():
    allhost = []
    allhost.extend(gtmhost)
    allhost.extend(gtmshost)
    allhost.extend(dnhost)
    allhost.extend(cnhost)
    allhost.extend(dnshost)
    ahost = list(set(allhost))
    pakname = package.replace('./', )
    pakname = pakname.replace('.tgz', )
    print('======== deploy packages ========')
    f = open('./env.sh', 'w')
    stmt1 = (((('export PATH=' + defbase) + '/') + pakname) + '/bin:$PATH')
    stmt2 = (((('export LD_LIBRARY_PATH=' + defbase) + '/') + pakname) + '/lib:$LD_LIBRARY_PATH')
    f.write((((stmt1 + '\n') + stmt2) + '\n'))
    f.close()
    for i in ahost:
        stmt = (((((((('scp' + ' ') + package) + ' ') + defuser) + '@') + i) + ':') + defbase)
        stmt3 = (((((('scp' + ' ./env.sh ') + defuser) + '@') + i) + ':') + defbase)
        stmt5 = (((((('scp' + ' ./install.sh ') + defuser) + '@') + i) + ':') + defbase)
        subprocess.run(stmt, shell=True)
        print(stmt)
        subprocess.run(stmt3, shell=True)
        print(stmt3)
        subprocess.run(stmt5, shell=True)
        print(stmt5)
        stmt7 = ((('tar -zxf ' + defbase) + '/') + package)
        sshTemp(i, stmt7, 1)
    print()
    print('\n ======== creating gtm master node ======== \n')
    makeTemp(gtmhost[0], gtmdata[0])
    initgtm = ('initgtm -Z gtm -D ' + gtmdata[0])
    sshTemp(gtmhost[0], initgtm, 1)
    gtmconf = ((((((((((('/bin/bash ' + defbase) + '/install.sh gtm ') + gtmhost[0]) + ' ') + str(gtmport[0])) + ' ') + gtmname[0]) + ' ') + gtmdata[0]) + ' ') + gtmuser[0])
    sshTemp(gtmhost[0], gtmconf, 1)
    startgtm = (('gtm_ctl -Z gtm -D ' + gtmdata[0]) + ' start')
    sshTemp(gtmhost[0], startgtm, 1)
    n = 0
    print('\n ======== creating gtm slave node ========')
    for i in gtmshost:
        makeTemp(i, gtmsdata[n])
        print(('\n creating gtm slave node ' + gtmsname[n]))
        initgtms = ('initgtm -Z gtm -D ' + gtmsdata[n])
        sshTemp(i, initgtms, 1)
        gtmsconf = ((((((((((('/bin/bash ' + defbase) + '/install.sh gtm_slave ') + gtmhost[0]) + ' ') + str(gtmsport[n])) + ' ') + gtmsname[n]) + ' ') + gtmsdata[n]) + ' ') + str(gtmport[0]))
        sshTemp(i, gtmsconf, 1)
        startgtms = (('gtm_ctl -Z gtm_standby -D ' + gtmsdata[n]) + ' start')
        sshTemp(i, startgtms, 1)
        n = (n + 1)
    n = 0
    print('\n ======== creating cn node ========')
    for i in cnhost:
        makeTemp(i, cndata[n])
        print(('\n ==========creating cn node ' + cnname[n]))
        if (types == 'pgxz'):
            initcn = ((((((((((('initdb --locale=en_US.UTF-8 -U ' + cnuser[n]) + ' -E utf8 -D ') + cndata[n]) + ' --nodename=') + cnname[n]) + ' --nodetype=coordinator --master_gtm_nodename ') + gtmname[0]) + ' --master_gtm_ip ') + gtmhost[0]) + ' --master_gtm_port ') + str(gtmport[0]))
            sshTemp(i, initcn, 3)
        elif (types == 'pgxc'):
            initcn = ((('initdb -D ' + cndata[n]) + ' --nodename ') + cnname[n])
            sshTemp(i, initcn, 3)
        if (types == 'pgxz'):
            cnconf = ((((((((((('/bin/bash ' + defbase) + '/install.sh cn ') + str(cnport[n])) + ' ') + str(cnpooler[n])) + ' ') + cndata[n]) + ' ') + gtmhost[0]) + ' ') + str(gtmport[0]))
            sshTemp(i, cnconf, 1)
        elif (types == 'pgxc'):
            cnconf = ((((((((((((('/bin/bash ' + defbase) + '/install.sh cn ') + str(cnport[n])) + ' ') + str(cnpooler[n])) + ' ') + cndata[n]) + ' ') + gtmhost[0]) + ' ') + str(gtmport[0])) + ' ') + types)
            sshTemp(i, cnconf, 2)
        startcn = (('pg_ctl -Z coordinator -D ' + cndata[n]) + ' start')
        reloadcn = (('pg_ctl -D ' + cndata[n]) + ' reload')
        sshTemp(i, startcn, 3)
        if (types == 'pgxc'):
            restartcn = ('pg_ctl -Z coordinator restart -m f -D ' + cndata[n])
            sshTemp(i, restartcn, 2)
        sshTemp(i, reloadcn, 1)
        n = (n + 1)
    n = 0
    print('\n ======== creating dn master node ========')
    for i in dnhost:
        makeTemp(i, dndata[n])
        print(('\n ================creating dn node ' + dnname[n]))
        if (types == 'pgxz'):
            initdn = ((((((((((('initdb --locale=en_US.UTF-8 -U ' + dnuser[n]) + ' -E utf8 -D ') + dndata[n]) + ' --nodename=') + dnname[n]) + ' --nodetype=datanode --master_gtm_nodename ') + gtmname[0]) + ' --master_gtm_ip ') + gtmhost[0]) + ' --master_gtm_port ') + str(gtmport[0]))
            sshTemp(i, initdn, 3)
        elif (types == 'pgxc'):
            initdn = ((('initdb -D ' + dndata[n]) + ' --nodename ') + dnname[n])
            sshTemp(i, initdn, 5)
        if (types == 'pgxz'):
            dnconf = ((((((((((('/bin/bash ' + defbase) + '/install.sh dn ') + str(dnport[n])) + ' ') + str(dnpooler[n])) + ' ') + dndata[n]) + ' ') + gtmhost[0]) + ' ') + str(gtmport[0]))
            sshTemp(i, dnconf, 1)
        elif (types == 'pgxc'):
            dnconf = ((((((((((((('/bin/bash ' + defbase) + '/install.sh dn ') + str(dnport[n])) + ' ') + str(dnpooler[n])) + ' ') + dndata[n]) + ' ') + gtmhost[0]) + ' ') + str(gtmport[0])) + ' ') + types)
            sshTemp(i, dnconf, 2)
        startdn = (('pg_ctl -Z datanode -D ' + dndata[n]) + ' start')
        reloaddn = (('pg_ctl -D ' + dndata[n]) + ' reload')
        sshTemp(i, startdn, 3)
        if (types == 'pgxc'):
            restartdn = ('pg_ctl -Z datanode restart -m f -D ' + dndata[n])
            sshTemp(i, restartdn, 2)
        sshTemp(i, reloaddn, 1)
        n = (n + 1)
    n = 0
    print('\n ======== creating dn slave node ========')
    for i in dnshost:
        makeTemp(i, dnsdata[n])
        print(('\n ==============creating dns node ' + dnsname[n]))
        initdns = (((((((('pg_basebackup -p ' + dnsmport[n]) + ' -h ') + dnsmhost[n]) + ' -U ') + dnsuser[n]) + ' -D ') + dnsdata[n]) + ' -X f -P -v')
        sshTemp(i, initdns, 5)
        dnsconf = ((((((((((((((('/bin/bash ' + defbase) + '/install.sh dn_slave ') + str(dnsport[n])) + ' ') + str(dnspooler[n])) + ' ') + dnsdata[n]) + ' ') + dnsmhost[n]) + ' ') + dnsmport[n]) + ' ') + dnsmuser[n]) + ' ') + dnsmname[n])
        changedir = ('chmod 700 ' + dnsdata[n])
        sshTemp(i, dnsconf, 2)
        sshTemp(i, changedir, 1)
        startdns = (('pg_ctl -Z datanode -D ' + dnsdata[n]) + ' start')
        reloaddns = (('pg_ctl -D ' + dnsdata[n]) + ' reload')
        sshTemp(i, startdns, 3)
        if (types == 'pgxc'):
            restartdns = ('pg_ctl -Z datanode restart -m f -D ' + dnsdata[n])
            sshTemp(i, restartdns, 2)
        sshTemp(i, reloaddns, 1)
        n = (n + 1)