-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(unraid): add identconfig module (#11)
- Loading branch information
1 parent
9ec0dd8
commit 6e04cd4
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Executor } from '../../../instance/executor'; | ||
import { UnraidModuleExtensionBase } from '../unraid-module-extension-base'; | ||
|
||
export type IdentConfig = { | ||
name: string; | ||
timezone: string; | ||
comment: string; | ||
security: string; | ||
workgroup: string; | ||
domain: string; | ||
domainShort: string; | ||
hidedotfiles: string; | ||
localmaster: string; | ||
enablefruit: string; | ||
useNetbios: string; | ||
useWsd: string; | ||
wsdOpt: string; | ||
useNtp: string; | ||
ntpServer1: string; | ||
ntpServer2: string; | ||
ntpServer3: string; | ||
ntpServer4: string; | ||
domainLogin: string; | ||
domainPasswd: string; | ||
sysModel: string; | ||
sysArraySlots: string; | ||
useSsl: string; | ||
port: string; | ||
portssl: string; | ||
localTld: string; | ||
bindMgt: string; | ||
useTelnet: string; | ||
porttelnet: string; | ||
useSsh: string; | ||
portssh: string; | ||
useUpnp: string; | ||
startPage: string; | ||
[key: string]: string; | ||
}; | ||
|
||
function snakeToCamel(input: string): string { | ||
const keys = input.split('_'); | ||
const partsWithUpperCase = keys.map((key, index) => { | ||
if (index === 0) return key; | ||
return key.charAt(0).toUpperCase() + key.slice(1); | ||
}); | ||
return partsWithUpperCase.join(''); | ||
} | ||
|
||
export class UnraidModuleIdentConfigExtension< | ||
ExecutorConfig, | ||
Ex extends Executor<ExecutorConfig> | ||
> extends UnraidModuleExtensionBase<ExecutorConfig, Ex> { | ||
/** | ||
* Returns /boot/config/ident.cfg as parsed JSON | ||
*/ | ||
async getIdentConfig(): Promise<IdentConfig> { | ||
const { code, stdout } = await this.instance.execute(`cat /boot/config/ident.cfg`); | ||
if (code !== 0) throw new Error('Got non-zero exit code while catting ident.cfg'); | ||
const result = {}; | ||
stdout.forEach((line) => { | ||
if (line.startsWith('#')) return; | ||
const [key, value] = line.split('='); | ||
const cameledKey = snakeToCamel(key.toLowerCase()); | ||
result[cameledKey] = value.replace('\r', '').replace(/"/g, ''); | ||
}); | ||
|
||
return result as IdentConfig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './casemodel'; | ||
export * from './identconfig'; | ||
export * from './notifications'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters