2023-05-31 15:19:21 +02:00
const { argv } = require ( "process" ) ;
2023-04-17 12:03:56 +02:00
const fs = require ( "fs-extra" ) ;
const path = require ( "path" ) ;
const dnsSync = require ( "dns-sync" ) ;
const mustache = require ( "mustache" ) ;
const readlineSync = require ( "readline-sync" ) ;
2023-04-27 06:17:20 +02:00
2023-04-17 12:03:56 +02:00
/ * *
* This Setup is run at the first installation
* This is not an exportable module
*
*
*
* /
2023-01-22 10:53:09 +01:00
const Setup = { } ;
2023-04-17 12:03:56 +02:00
//const nationsync = require('./Nations').updateChains();
2023-01-22 10:53:09 +01:00
2023-05-16 10:31:27 +02:00
Setup . check = ( param ) => {
//run a nationchains sync nd check town does not already exist
2023-05-31 15:19:21 +02:00
[ "nationId" , "townId" , "dns" , "chain" ] . forEach ( ( k ) => {
if ( ! param [ k ] ) {
console . log ( ` Please provide a ${ k } in your param ` ) ;
2023-05-16 10:31:27 +02:00
process . exit ( ) ;
}
2023-05-31 15:19:21 +02:00
} ) ;
const localconf = {
nationId : param . nationId ,
townId : param . townId ,
url : param . dns ,
comment : "Generate by setup.js with minimum of information" ,
} ;
if ( fs . existsSync ( ` ../../adminapi/www/adminapx/conf/setup_xx.json ` ) ) {
const setupxx = readJsonSYnc ( ` ../../adminapi/www/adminapx/conf/setup_xx.json ` )
if ( setupxx . nationId == param . nationId && setupxx . townId = param . townId ) {
// This is a re-install
} else {
console . log (
"A conf file exist in adminapi/www/adminapx/conf/setup_xx.json remove it an run again yarn setup ..."
) ;
process . exit ( ) ;
}
}
fs . outputJsonSync (
` ../../adminapi/www/adminapx/conf/setup_xx.json ` ,
localconf
) ;
const initconf = fs . readJsonSync (
"./adminapi/www/adminapx/tpldata/initconf.json"
) ;
let nationupdated = false ;
const Wwws = require ( "../models/Wwws.js" ) ;
const Nations = require ( "../models/Nations.js" ) ;
for ( let t = 0 ; t < initconf . towns ; t ++ ) {
const synchro = Nations . synchronize ( initconf . towns [ t ] . dns ) ;
if ( synchro . status == 200 ) {
nationupdated = true ;
break ;
}
2023-05-16 10:31:27 +02:00
}
2023-05-31 15:19:21 +02:00
if ( ! nationupdated ) {
Console . log (
"Please check your internet access other towns cannot be reach to synchronize your town"
) ;
2023-05-16 10:31:27 +02:00
process . exit ( ) ;
}
// check nationId exist and townId not
2023-05-31 15:19:21 +02:00
const idxnationId = fs . readJsonSync (
` ../../nationchains/nations/idx/nationId_all.json `
) ;
if ( ! Object . keys ( idxnationId ) . includes ( param . nationId ) ) {
console . log ( ` Sorry your nationId: ${ param . nationId } does not exist ` ) ;
2023-05-16 10:31:27 +02:00
process . exit ( ) ;
2023-05-31 15:19:21 +02:00
}
const idxtownId = fs . readJsonSync (
"../../nationchains/towns/idx/townId_all.json"
) ;
if ( Object . keys ( idxtownId ) . includes ( param . townId ) ) {
console . log (
` Sorry your townId: ${ param . townId } already exist, please choose another one `
) ;
process . exit ( ) ;
}
2023-04-17 12:03:56 +02:00
if ( "testinternet" != "testinternet" ) {
console . log (
"\x1b[31m Check your internet access, to setup this town we need to update the Nations. It seems we cannot do it"
) ;
process . exit ( ) ;
}
if ( ! fs . existsSync ( "/etc/nginx/nginx.conf" ) ) {
console . log (
"\x1b[31m Check documentation, nginx have to be installed on this server first, no /etc/nginx/nginx.conf available"
) ;
process . exit ( ) ;
}
2023-05-16 10:31:27 +02:00
if ( fs . existsSync ( "./adminapi/www/nginx_adminapx.conf" ) ) {
2023-04-17 12:03:56 +02:00
console . log (
2023-05-16 10:31:27 +02:00
"\x1b[31m Be carefull you already have a town set, check http://adminapx or remove ./adminapi/www/nginx_adminapx.conf to reset nginxconf"
2023-04-17 12:03:56 +02:00
) ;
process . exit ( ) ;
}
return true ;
} ;
2023-04-13 07:46:35 +02:00
2023-05-16 10:31:27 +02:00
Setup . init = async ( param ) => {
2023-05-12 07:59:32 +02:00
/ * *
* create empty nationchains
* rsync all subfolder nationchains except the tribes / and / www / nginx _adminapx . conf
*
* Then to send new version we fix a master production
*
* /
2023-05-31 15:19:21 +02:00
const initconf = fs . readJsonSync (
"./adminapi/www/adminapx/tpldata/initconf.json"
) ;
2023-05-16 10:31:27 +02:00
2023-05-12 07:59:32 +02:00
initconf . sudoerUser = process . env . USER ;
2023-05-16 10:31:27 +02:00
initconf . dirapi = path . resolve ( ` ${ _ _dirname } /../../ ` ) ;
2023-05-31 15:19:21 +02:00
initconf . dirtown = path . resolve (
` ${ _ _dirname } /../../../ ${ param . townId } - ${ param . nationId } / `
2023-05-12 07:59:32 +02:00
) ;
2023-05-31 15:19:21 +02:00
// To allow to serve the nation website until the end
initconf . nginx . include . push ( ` ${ initconf . dirapi } /adminapi/www/nginx_*.conf ` ) ;
2023-05-12 07:59:32 +02:00
// To allow to serve tribes web site
2023-05-31 15:19:21 +02:00
initconf . nginx . include . push ( ` ${ initconf . dirtown } /tribes/*/www/nginx_*.conf ` ) ;
initconf . dns . push ( param . dns ) ;
2023-05-16 10:31:27 +02:00
initconf . nginx . logs = ` ${ dirtown } /logs/nginx/adminapx ` ;
2023-05-12 07:59:32 +02:00
initconf . nginx . website = "adminapx" ;
2023-05-16 10:31:27 +02:00
initconf . nginx . fswww = ` ${ dirapi } /adminapi/www ` ;
2023-05-12 07:59:32 +02:00
initconf . nginx . pageindex = "index_en.html" ;
2023-05-16 10:31:27 +02:00
const nginxconf = fs . readFileSync (
"../../adminapi/www/adminapx/static/tpl/nginx.conf.mustache" ,
"utf8"
) ;
const proxyparams = fs . readFileSync (
"../../adminapi/www/adminapx/static/tpl/nginxproxy_params.mustache" ,
"utf8"
) ;
// saved and change nginx conf
if ( ! fs . existsSync ( "/etc/nginx/nginxconf.saved" ) ) {
fs . moveSync ( "/etc/nginx/nginx.conf" , "/etc/nginx/nginxconf.saved" ) ;
console . log (
"your previous /etc/nginx/nginx.conf was backup in /etc/nginx/nginxconf.saved"
) ;
2023-05-12 07:59:32 +02:00
}
2023-05-16 10:31:27 +02:00
fs . outputFileSync (
"/etc/nginx/nginx.conf" ,
mustache . render ( nginxconf , initconf ) ,
"utf8"
) ;
fs . outputFileSync (
"/etc/nginx/proxy_params" ,
mustache . render ( proxyparams , initconf ) ,
"utf8"
) ;
if ( ! fs . existsSync ( initconf . nginx . logs ) ) fs . mkdirSync ( initconf . nginx . logs ) ;
const { exec } = require ( "child_process" ) ;
2023-05-31 15:19:21 +02:00
exec ( initconf . restart , ( error , stdout , stderr ) => {
2023-05-16 10:31:27 +02:00
if ( error ) {
2023-05-31 15:19:21 +02:00
console . log ( "\x1b[42m" , error , stdout , stderr , "x1b[0m" ) ;
//@todo supprimer la derniere config et relancer
2023-05-16 10:31:27 +02:00
} else {
2023-05-31 15:19:21 +02:00
console . log (
` \x 1b[42m########################################################################################### \x 1b[0m \n \x 1b[42mWellcome into apxtrib, you can now 'yarn dev' for dev or 'yarn startpm2' for prod or \n 'yarn unittest' for testing purpose. Access to your town here \x 1b[0m \x 1b[32mhttp:// ${ param . dns } \x 1b[0m \x 1b[42m \n to finish your town setup. Don't forget to set your localhost /etc/hosts by adding 127.0.0.1 adminapx or {LAN IP} adminapx . Check README's project to learn more. \x 1b[0m \n \x 1b[42m########################################################################################### \x 1b[0m `
) ;
2023-05-16 10:31:27 +02:00
}
2023-05-31 15:19:21 +02:00
} ) ;
2023-05-12 07:59:32 +02:00
} ;
2023-05-16 10:31:27 +02:00
2023-05-31 15:19:21 +02:00
if ( argv . length != 6 ) {
console . log (
"Check you parameter you need to type yarn setup nationId:ants townid:mytown dns:mytown-ants "
) ;
process . exit ( ) ;
2023-05-16 10:31:27 +02:00
}
2023-05-31 15:19:21 +02:00
const param = { } ;
argv . slice ( 2 ) . forEach ( ( arg ) => {
const kv = arg . split ( ":" ) ;
if ( kv . length == 2 ) {
param [ kv [ 0 ] ] = kv [ 1 ] ;
} else {
console . log (
"Check your args that have to be yarn main key1:val1 keyn:valn"
) ;
process . exit ( 1 ) ;
}
} ) ;
console . log ( param ) ;
//if (Setup.check(param)) Setup.init(param);
2023-05-12 07:59:32 +02:00
// After testing remove all stuff after this line
Setup . initold = async ( ) => {
2023-04-17 12:03:56 +02:00
// Get standard conf and current data
const townconf = fs . readJsonSync ( "./nationchains/www/adminapx/townconf.json" ) ;
2023-04-27 06:17:20 +02:00
const apxnations = fs . readJsonSync (
` ./nationchains/nations/idx/nationId_all.json `
) ;
const apxtowns = fs . readJsonSync ( ` ./nationchains/towns/idx/townId_all.json ` ) ;
2023-05-12 07:59:32 +02:00
let apxpagans = { } ;
if ( fs . existsSync ( ` ./nationchains/pagans/idx/alias_all.json ` ) ) {
apxpagans = fs . readJsonSync ( ` ./nationchains/pagans/idx/alias_all.json ` ) ;
}
2023-04-27 06:17:20 +02:00
if ( ! Object . keys ( apxnations ) . includes ( townconf . nationId ) ) {
console . log (
` Sorry nationId ${ townconf . nationId } does not exist, please change with an existing nation `
) ;
process . exit ( ) ;
}
if ( Object . keys ( apxtowns ) . includes ( townconf . townId ) ) {
console . log (
` Sorry townId ${ townconf . townId } already exist, please change it `
) ;
process . exit ( ) ;
}
/ *
if ( Object . keys ( apxpagans ) . includes ( townconf . mayorId ) ) {
console . log (
` Sorry paganId ${ townconf . maorId } already exist ti create a town you need a new identity, please change it `
) ;
process . exit ( ) ;
}
* /
2023-04-17 12:03:56 +02:00
townconf . sudoerUser = process . env . USER ;
2023-05-16 10:31:27 +02:00
townconf . dirapi = path . resolve ( ` ${ _ _dirname } /../../ ` ) ;
2023-04-28 13:21:02 +02:00
// To allow to serve the nation website until the end
townconf . nginx . include . push (
2023-05-16 10:31:27 +02:00
` ${ townconf . dirapi } /nationchains/www/nginx_*.conf `
2023-04-28 13:21:02 +02:00
) ;
// To allow to serve tribes web site
2023-04-27 06:17:20 +02:00
townconf . nginx . include . push (
2023-05-16 10:31:27 +02:00
` ${ townconf . dirapi } /nationchains/tribes/*/www/nginx_*.conf `
2023-04-27 06:17:20 +02:00
) ;
2023-05-16 10:31:27 +02:00
townconf . nginx . logs = ` ${ townconf . dirapi } /nationchains/logs/nginx ` ;
2023-04-27 06:17:20 +02:00
townconf . nginx . website = "adminapx" ;
2023-04-17 12:03:56 +02:00
townconf . nginx . fswww = "nationchains/" ; //for a local tribe nationchains/tribes/tribeid
townconf . nginx . tribeid = "town" ;
2023-04-27 06:17:20 +02:00
townconf . nginx . pageindex = "index_en.html" ;
2023-04-13 07:46:35 +02:00
2023-04-17 12:03:56 +02:00
console . log ( townconf ) ;
if (
! readlineSync . keyInYN (
2023-04-27 06:17:20 +02:00
` \x 1b[42mThis is the first install from ./nationchains/www/adminapx/townconf.json (check it if you want) \n this will change your nginx config in /etc/nginx and run nginx from sudoer user ${ townconf . sudoerUser } (Yes/no)? \n no if you want to change parameter and run yarn setup again \x 1b[0m `
2023-04-17 12:03:56 +02:00
)
)
process . exit ( ) ;
2023-05-12 07:59:32 +02:00
2023-04-17 12:03:56 +02:00
// saved and change nginx conf
if ( ! fs . existsSync ( "/etc/nginx/nginxconf.saved" ) ) {
fs . moveSync ( "/etc/nginx/nginx.conf" , "/etc/nginx/nginxconf.saved" ) ;
2023-04-27 06:17:20 +02:00
console . log (
"your previous /etc/nginx/nginx.conf was backup in /etc/nginx/nginxconf.saved"
) ;
2023-04-17 12:03:56 +02:00
}
const tplnginxconf = fs . readFileSync (
"./nationchains/www/adminapx/nginx/nginx.conf.mustache" ,
"utf8"
) ;
fs . outputFileSync (
"/etc/nginx/nginx.conf" ,
mustache . render ( tplnginxconf , townconf ) ,
"utf8"
) ;
2023-05-12 07:59:32 +02:00
//proxyparam
const proxy _params = fs . readFileSync (
"./nationchains/www/adminapx/nginx/proxy_params.mustache" ,
"utf8"
) ;
fs . outputFileSync (
"/etc/nginx/proxy_params" ,
mustache . render ( proxy _params , townconf ) ,
"utf8"
) ;
2023-04-17 12:03:56 +02:00
const tplnginxwww = fs . readFileSync (
"./nationchains/www/adminapx/nginx/modelwebsite.conf.mustache" ,
"utf8"
) ;
fs . outputFileSync (
` ./ ${ townconf . nginx . fswww } www/nginx_ ${ townconf . nginx . website } .conf ` ,
mustache . render ( tplnginxwww , townconf ) ,
"utf8"
) ;
2023-04-27 06:17:20 +02:00
fs . outputJsonSync ( "./nationchains/tribes/conf.json" , townconf , {
2023-04-17 12:03:56 +02:00
spaces : 2 ,
} ) ;
2023-05-12 07:59:32 +02:00
// Integrer cette partie du setup en inteactif.
// l'objectif du setup est de rendere accessible adminapx en local (IP local) ou production IP public
2023-04-27 06:17:20 +02:00
//CREATE A TOWN setup local voir utiliser towns.create
2023-05-12 07:59:32 +02:00
/ * t o w n c o n f . t o w n = {
2023-04-27 06:17:20 +02:00
townId : townconf . townId ,
nationId : townconf . nationId ,
2023-05-31 15:19:21 +02:00
dns : ` http:// ${ townconf . dns [ 0 ] } ` ,
2023-04-27 06:17:20 +02:00
IP : townconf . IP ,
mayorid : townconf . mayorId ,
status : "unchain" ,
} ;
2023-05-12 07:59:32 +02:00
apxtowns [ townconf . townId ] = townconf . town ;
fs . outputJsonSync ( ` ./nationchains/towns/idx/townId_all.json ` , apxtowns ) ;
fs . outputJsonSync (
` ./nationchains/towns/itm/ ${ townconf . townId } .json ` ,
townconf . town ,
{ spaces : 2 }
) ;
2023-04-27 06:17:20 +02:00
// Create tribe id voir a utiliser tribes.create()
townconf . tribe = {
tribeId : townconf . tribeId ,
dns : [ ] ,
status : "unchain" ,
nationId : townconf . nationId ,
townId : townconf . townId ,
} ;
//tribe does not exist in a new town
2023-05-12 07:59:32 +02:00
apxtribes = { } ;
apxtribes [ townconf . tribeId ] = townconf . tribe ;
fs . outputJsonSync ( ` ./nationchains/tribes/idx/tribeId_all.json ` , apxtribes ) ;
fs . outputJsonSync (
` ./nationchains/tribes/itm/ ${ townconf . tribeId } .json ` ,
townconf . tribe ,
{ spaces : 2 }
) ;
2023-04-28 13:21:02 +02:00
fs . ensureDirSync ( ` ./nationchains/tribes/ ${ townconf . tribeId } /logs/nginx ` ) ;
2023-04-27 06:17:20 +02:00
//CREATE a mayorId pagans if it does not exist
2023-05-12 07:59:32 +02:00
if ( ! apxpagans [ townconf . mayorId ] ) {
const Pagans = require ( "./Pagans" ) ;
const createPagans = await Pagans . createId (
townconf . mayorId ,
townconf . passphrase
) ;
if ( createPagans . status == 200 ) {
fs . outputFileSync (
` ./ ${ townconf . mayorId } _PrivateKey.txt ` ,
createPagans . data . privateKey ,
"utf8"
) ;
fs . outputFileSync (
` ./ ${ townconf . mayorId } _PublicKey.txt ` ,
createPagans . data . publicKey ,
"utf8"
) ;
console . log (
` \x 1b[43mCut paste your keys / ${ townconf . mayorId } _PrivateKey.txt / ${ townconf . mayorId } _PublicKey.txt \x 1b[0m `
) ;
} else {
console . log ( "Error at Pagan creation " ) ;
2023-04-27 06:17:20 +02:00
console . log ( createPagans ) ;
process . exit ( ) ;
}
2023-05-12 07:59:32 +02:00
} * /
//fin de partie à integer dans l'interface graphique adminapx
//restart nginx
2023-04-17 12:03:56 +02:00
const { exec } = require ( "child_process" ) ;
exec ( townconf . nginx . restart , ( error , stdout , stderr ) => {
if ( error ) {
console . log ( "\x1b[42m" , error , stdout , stderr , "x1b[0m" ) ;
} else {
console . log (
2023-04-27 06:17:20 +02:00
` \x 1b[42m########################################################################################### \x 1b[0m \n \x 1b[42mWellcome into apxtrib, you can now 'yarn dev' for dev or 'yarn startpm2' for prod or \n 'yarn unittest' for testing purpose. Access to your town here \x 1b[0m \x 1b[32mhttp:// ${ townconf . dns } \x 1b[0m \x 1b[42m \n to finish your town set up. Check README's project to learn more. \x 1b[0m \n \x 1b[42m########################################################################################### \x 1b[0m `
2023-04-17 12:03:56 +02:00
) ;
}
} ) ;
} ;
2023-01-22 10:53:09 +01:00
2023-04-17 12:03:56 +02:00
Setup . Checkjson = ( conf ) => {
var rep = "" ;
const nation _town = fs . readJsonSync (
"./nationchains/socialworld/objects/towns/searchindex/towns_nation_uuid.json"
) ;
2023-04-27 06:17:20 +02:00
if ( ! ObjectKeys ( nation _town ) . includes ( conf . nationId ) ) {
rep += ` your nationId ${ conf . nationId } does not exist you have to choose an existing one ` ;
2023-04-17 12:03:56 +02:00
}
2023-04-27 06:17:20 +02:00
if ( nation _town [ conf . nationId ] . includes ( conf . townId ) ) {
rep += ` This conf.townId already exist you have to find a unique town name per nation ` ;
2023-04-17 12:03:56 +02:00
}
const getnation = Odmdb . get (
"./nationchains/socialworld/objects" ,
"towns" ,
2023-04-27 06:17:20 +02:00
[ conf . NationId ] ,
2023-04-17 12:03:56 +02:00
[ nationId ]
) ;
//if getnation.data.notfound
conf . language . forEach ( ( l ) => {
if ( ! [ "fr" , "en" , "it" , "de" , "sp" ] . includes ( l ) ) {
rep += l + " Only fr,en,it,de,sp are available \n" ;
}
} ) ;
if ( ! fs . existsSync ( ` /home/ ${ conf . sudoerUser } ` ) ) {
rep += ` /home/ ${ conf . sudoerUser } does not exist, user has to be create with a /home on this server \n ` ;
}
try {
if (
"true" ==
execSync ( 'timeout 2 sudo id && sudo="true" || sudo="false";echo "$sudo"' )
. toString ( )
. trim ( )
. split ( /\r?\n/ )
. slice ( - 1 )
) {
rep += ` ${ sudoerUser } is not sudoer please change this ` ;
}
} catch ( err ) {
console . log ( err ) ;
rep += " Check your user it seems to not be a sudoer" ;
}
if ( conf . jwtsecret . length < 32 ) {
rep += "Your jwtsecretkey must have at least 32 characters" ;
}
if (
conf . dns != "unchain" &&
2023-04-27 06:17:20 +02:00
! dnsSync . resolve ( ` ${ conf . townId } . ${ conf . nationId } . ${ conf . dns } ` )
2023-04-17 12:03:56 +02:00
) {
2023-04-27 06:17:20 +02:00
rep += ` \n resolving $ ${ conf . townId } . ${ conf . nationId } . ${ conf . dns } will not responding valid IP, please setup domain redirection IP before runing this script ` ;
2023-04-17 12:03:56 +02:00
}
return rep ;
2023-01-22 10:53:09 +01:00
} ;
2023-03-27 07:52:21 +02:00
2023-04-17 12:03:56 +02:00
Setup . config = ( townSetup ) => {
// Init this instance with a .config.js
Setup . configjs ( townSetup ) ;
// Create tribeid space + a user admin + webspace withe apxtrib webapp install
Setup . druidid ( townSetup ) ;
2023-01-22 10:53:09 +01:00
} ;
2023-04-17 12:03:56 +02:00
Setup . configjs = ( townSetup ) => {
// Set /config.js
let confapxtrib = fs . readFileSync ( "./setup/config.mustache" , "utf-8" ) ;
fs . writeFileSync (
"./config.js" ,
Mustache . render ( confapxtrib , townSetup ) ,
"utf-8"
) ;
if ( fs . existsSync ( "./config.js" ) ) {
console . log ( "config.js successfully created." ) ;
} else {
console . log (
"config.js not created, check what's wrong in tpl:" ,
confapxtrib
) ;
console . log ( "for data :" , townSetup ) ;
process . exit ( ) ;
}
2023-01-22 10:53:09 +01:00
} ;
2023-04-17 12:03:56 +02:00
Setup . druidid = ( townSetup ) => {
// create a tribeid with a user that will admin this instance into /tribes/tribeid /users
const config = require ( "../config.js" ) ;
// Need to do it on setup this is also done again in models/Tribes.js
console . log ( ` ${ config . tribes } / ${ townSetup . druidid } ` ) ;
fs . ensureDirSync ( ` ${ config . tribes } / ${ townSetup . druidid } ` ) ;
[ "users" , "www" , "referentials" , "nationchains" ] . forEach ( ( r ) => {
fs . copySync (
2023-05-16 10:31:27 +02:00
` ${ _ _dirapi } /setup/tribes/apxtrib/ ${ r } ` ,
2023-04-17 12:03:56 +02:00
` ${ config . tribes } / ${ townSetup . druidid } / ${ r } `
) ;
} ) ;
2023-05-16 10:31:27 +02:00
/ * c o n s t c o n f c l i = J S O N . p a r s e ( M u s t a c h e . r e n d e r ( f s . r e a d F i l e S y n c ( ` $ { _ _ d i r a p i } / s e t u p / t r i b e s / a p x t r i b / c l i e n t c o n f . m u s t a c h e ` , ' u t f 8 ' ) , t o w n S e t u p ) ) ;
2023-03-27 07:52:21 +02:00
fs . outputJsonSync ( ` ${ config . tribes } / ${ townSetup . druidid } /clientconf.json ` , confcli ) ;
2023-01-22 10:53:09 +01:00
// Create a new tribeid + admin user for this tribeid
// with access to {druidid}:webapp as admin
2023-03-27 07:52:21 +02:00
* /
2023-04-17 12:03:56 +02:00
const Tribes = require ( "./Tribes.js" ) ;
const access = { app : { } , data : { } } ;
access . app [ ` ${ townSetup . druidid } :webapp ` ] = "admin" ;
access . data [ townSetup . druidid ] = {
users : "CRUDO" ,
referentials : "CRUDO" ,
www : "CRUDO" ,
} ;
const createclient = Tribes . create ( {
tribeid : townSetup . druidid ,
genericpsw : townSetup . genericpsw ,
lanquageReferential : townSetup . language ,
useradmin : {
LOGIN : townSetup . login ,
xlang : townSetup . language [ 0 ] ,
ACCESSRIGHTS : access ,
} ,
} ) ;
if ( createclient . status == 200 ) {
console . log (
` Your tribeid domain was created with login : ${ townSetup . login } and password: ${ townSetup . genericpsw } , change it after the 1st login on https:// ${ townSetup . subdomain } . ${ townSetup . domain } `
) ;
// Create nginx conf for a first install
const confnginx = fs . readFileSync (
"./setup/nginx/nginx.conf.mustache" ,
"utf8"
) ;
fs . outputFileSync (
"/etc/nginx/nginx.conf" ,
Mustache . render ( confnginx , townSetup ) ,
"utf-8"
) ;
// Create a spacedev for webapp of apxtrib
// that will be accesible in prod from https://subdomain.domain/ and in dev http://webapp.local.fr
const addspaceweb = Tribes . addspaceweb ( {
setup : true ,
dnsname : [ ` ${ townSetup . subdomain } . ${ townSetup . domain } ` ] ,
mode : townSetup . mode ,
tribeid : townSetup . druidid ,
website : "webapp" ,
pageindex : "app_index_fr.html" ,
} ) ;
if ( addspaceweb . status == 200 ) {
console . log ( ` WELL DONE run yarn dev to test then yarn startpm2 ` ) ;
}
} else {
console . log ( "Issue " , createclient ) ;
}
} ;