setup fix

This commit is contained in:
philc 2024-11-02 12:07:13 +01:00
parent 98290acdd0
commit 0af5aa32d7
3 changed files with 32 additions and 3 deletions

View File

@ -36,6 +36,32 @@ apxtri.main = async () => {
};
apxtri.setup = async () => {
const getip = async () => {
/**
* Return json with public IP and network interfaces with their local IP
* {WANIP:"public IP","eth0":"localIPoneth0",...}
*/
const network = {};
const urlgetip = `https://api.ipify.org?format=json`;
const getdata = await fetch(urlgetip);
if (getdata.ok) {
const data = await getdata.json();
network.WANIP = data.ip;
}
const os = await import("os");
const interfaces = os.networkInterfaces();
for (const name in interfaces) {
for (const iface of interfaces[name]) {
// Check for IPv4 and make sure it's not an internal (loopback) address
if (iface.family === "IPv4" && !iface.internal) {
network[name]=iface.address;
//localIP = iface.address;
//console.log(`Local network IP (${name}): ${localIP}`);
}
}
}
return network
};
console.log("Warning, this is a first install");
const initadminapi = fs.readJsonSync(
"../adminapi/apxtri/setup/initadminapi.json"
@ -157,7 +183,8 @@ apxtri.setup = async () => {
);
// add hosts entry for local access
// this command is ran by the setup.sh
// sudo sed -i '/127.0.0.1 adminapx.adminapi/c\127.0.0.1 adminapx.adminapi' /etc/hosts
// grep -q '^127.0.0.1 adminapx.adminapi' /etc/hosts || echo '127.0.0.1 adminapx.adminapi' | sudo tee -a /etc/hosts > /dev/null
const ips=await getip();
const { exec } = require("child_process");
exec(initadminapi.nginx.restart, (error, stdout, stderr) => {
if (error) {
@ -165,7 +192,7 @@ apxtri.setup = async () => {
process.exit(0);
} else {
console.log(
`\x1b[42m##############################################################################\x1b[0m\n\x1b[42mWellcome into apxtri, you can now 'yarn dev' for dev or 'yarn startapx' for prod \n'Access to your town here \x1b[0m\x1b[32mhttp://adminapx.adminapî\x1b[0m \x1b[42m \n\x1b[0m\n\x1b[42m###########################################################################################\x1b[0m`
`\x1b[42m#############################################################################################\x1b[0m\n\x1b[42mWellcome into this fresh apxtri install, this run as "yarn dev" to set up your machine with a public domain name.\n If this install is to be use accross internet or local network : add on yopur local machine in /etc/hosts lines:\n ${Object.values(ips).map(ip => `${ip} adminapx.adminapi`).join('\n')} \n then open in your local browser \x1b[0m\x1b[32mhttp://adminapx.adminapi\x1b[0m \x1b[42m \n In local dev continue with 'yarn dev'\nTo run as a production run 'yarn startapx' or 'yarn restartapx' this will use pm2 as production monitoring\n\x1b[0m\n\x1b[42m###########################################################################################\x1b[0m`
);
}
});

View File

@ -59,7 +59,8 @@ else
mkdir -p "${tribe}/logs"
mkdir -p "${tribe}/logs/nginx"
mkdir -p "${tribe}/backups"
sudo sed -i '/127.0.0.1 adminapx.adminapi/c\127.0.0.1 adminapx.adminapi\n' /etc/hosts
# add 127.0.0.1 local host
grep -q '^127.0.0.1 adminapx.adminapi' /etc/hosts || echo '127.0.0.1 adminapx.adminapi' | sudo tee -a /etc/hosts > /dev/null
cd "$tribe"
yarn install
cd ../adminapi

View File

@ -6,6 +6,7 @@
},
"description": "apxtri Decentralized Autonomous Organization",
"main": "./apxtri/apxtri.js",
"type":"module",
"repository": {
"url": "https://gitea.ndda.fr/apxtri/adminapi.git",
"type": "git"