import { networkInterfaces } from "os" ; import { writeFile } from "fs" ; import { callback } from "awaiting" ; import { getLogger } from "./logger" ; import { infoJson , project_id , username } from "./data" ; import { options } from "./init-program" ; import basePath from "@cocalc/backend/base-path" ; let INFO ; export { INFO } ; export default async function init ( ) { const winston = getLogger ( "info-json init" ) ; winston . info ( "initializing the info.json file..." ) ; let host ; if ( process . env . HOST != null ) { host = process . env . HOST ; } else if ( options . kucalc ) { const nics = networkInterfaces ( ) ; const mynic = nics . eth0 ?? nics . ens4 ; host = mynic ?. [ 0 ] . address ?? "localhost" ; } else { host = "localhost" ; } INFO = { project_id , location : { host , username } , base_path : basePath , base_url : basePath , } ; await callback ( writeFile , infoJson , JSON . stringify ( INFO ) ) ; winston . info ( `Successfully wrote "${ infoJson }"` ) ; }