|
|
@ -1,6 +1,7 @@ |
|
|
|
import { spawnSync, SpawnSyncOptions } from 'child_process'; |
|
|
|
import { spawnSync, SpawnSyncOptions } from 'child_process'; |
|
|
|
|
|
|
|
import { readFileSync } from 'fs'; |
|
|
|
|
|
|
|
|
|
|
|
import SERVER_PATHS from './consts/SERVER_PATHS'; |
|
|
|
import { SERVER_PATHS } from './consts'; |
|
|
|
|
|
|
|
|
|
|
|
import { stderr as sherr, stdout as shout } from './shell'; |
|
|
|
import { stderr as sherr, stdout as shout } from './shell'; |
|
|
|
|
|
|
|
|
|
|
@ -8,15 +9,18 @@ const formatQuery = (query: string) => query.replace(/\s+/g, ' '); |
|
|
|
|
|
|
|
|
|
|
|
const execAnvilAccessModule = ( |
|
|
|
const execAnvilAccessModule = ( |
|
|
|
args: string[], |
|
|
|
args: string[], |
|
|
|
options: SpawnSyncOptions = { |
|
|
|
options: SpawnSyncOptions = {}, |
|
|
|
encoding: 'utf-8', |
|
|
|
|
|
|
|
timeout: 10000, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) => { |
|
|
|
) => { |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
encoding = 'utf-8', |
|
|
|
|
|
|
|
timeout = 10000, |
|
|
|
|
|
|
|
...restSpawnSyncOptions |
|
|
|
|
|
|
|
} = options; |
|
|
|
|
|
|
|
|
|
|
|
const { error, stdout, stderr } = spawnSync( |
|
|
|
const { error, stdout, stderr } = spawnSync( |
|
|
|
SERVER_PATHS.usr.sbin['anvil-access-module'].self, |
|
|
|
SERVER_PATHS.usr.sbin['anvil-access-module'].self, |
|
|
|
args, |
|
|
|
args, |
|
|
|
options, |
|
|
|
{ encoding, timeout, ...restSpawnSyncOptions }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (error) { |
|
|
|
if (error) { |
|
|
@ -152,9 +156,9 @@ const getLocalHostName = () => { |
|
|
|
let result: string; |
|
|
|
let result: string; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
result = execModuleSubroutine('host_name', { |
|
|
|
result = readFileSync(SERVER_PATHS.etc.hostname.self, { |
|
|
|
subModuleName: 'Get', |
|
|
|
encoding: 'utf-8', |
|
|
|
}).stdout; |
|
|
|
}).trim(); |
|
|
|
} catch (subError) { |
|
|
|
} catch (subError) { |
|
|
|
throw new Error(`Failed to get local host name; CAUSE: ${subError}`); |
|
|
|
throw new Error(`Failed to get local host name; CAUSE: ${subError}`); |
|
|
|
} |
|
|
|
} |
|
|
@ -168,9 +172,9 @@ const getLocalHostUUID = () => { |
|
|
|
let result: string; |
|
|
|
let result: string; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
result = execModuleSubroutine('host_uuid', { |
|
|
|
result = readFileSync(SERVER_PATHS.etc.anvil['host.uuid'].self, { |
|
|
|
subModuleName: 'Get', |
|
|
|
encoding: 'utf-8', |
|
|
|
}).stdout; |
|
|
|
}).trim(); |
|
|
|
} catch (subError) { |
|
|
|
} catch (subError) { |
|
|
|
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`); |
|
|
|
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`); |
|
|
|
} |
|
|
|
} |
|
|
|