Skip to content

Commit

Permalink
fix bugs, add config merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Seshpenguin committed Nov 1, 2023
1 parent a736859 commit d3f6cbc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cli-src/plctl.ts
Expand Up @@ -117,6 +117,9 @@ async function main() {
console.log("Cloud Ready (Authenticated): " + res.ocsReady);
if((await isPL2())) console.log("Selected Root: " + res.selectedRoot);
if((await isPL2())) console.log("Locked Root: " + res.lockedRoot);
if((await isPL2())) console.log("Hostname: " + res.hostname);
if((await isPL2())) console.log("KExec Disabled: " + res.disable_kexec);
if((await isPL2())) console.log("Build Info: " + res.buildInfo.product + " " + res.buildInfo.variant + " " + res.buildInfo.channel + " " + res.buildInfo.arch + " - " + res.buildInfo.buildnum + "," + res.buildInfo.uuid + " (" + res.buildInfo.builddate + ")");
process.exit(0);
});

Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -24,10 +24,12 @@
},
"dependencies": {
"@ltd/j-toml": "^1.37.0",
"@types/lodash": "^4.14.200",
"axios": "^1.3.4",
"commander": "^10.0.0",
"dotenv": "^16.0.3",
"is-reachable": "^5.2.1",
"lodash": "^4.17.21",
"node-pty": "^0.10.1",
"uuid": "^9.0.0",
"ws": "^8.11.0",
Expand Down
3 changes: 2 additions & 1 deletion src/constants.ts
Expand Up @@ -23,7 +23,8 @@ export interface ProLinuxInfo {
channel: string,
builddate: string,
filename: string,
arch: string
arch: string,
deviceinfoCodename: string
}

export interface RemoteUpdate {
Expand Down
7 changes: 6 additions & 1 deletion src/helpers/getProLinuxInfo.ts
Expand Up @@ -4,6 +4,10 @@ export async function getProLinuxInfo(): Promise<ProLinuxInfo> {
const prolinuxInfo = fs.readFileSync('/opt/build-info/prolinux-info.txt', 'utf8');
// "4,c5e3ff5b-1aba-4796-80dd-8622ec4f9cc6,prolinux,embedded,dev,Thu Sep 21 11:04:27 PM EDT 2023,prolinux-root-embedded-dev.squish,x64"
const [buildnum, uuid, product, variant, channel, builddate, filename, arch] = prolinuxInfo.split(',');

// read /sineware/deviceinfo_codename file, get the string
const deviceinfoCodename = fs.readFileSync('/sineware/deviceinfo_codename', 'utf8');

return {
buildnum,
uuid,
Expand All @@ -12,7 +16,8 @@ export async function getProLinuxInfo(): Promise<ProLinuxInfo> {
channel,
builddate,
filename,
arch
arch,
deviceinfoCodename
};

}
8 changes: 6 additions & 2 deletions src/index.ts
Expand Up @@ -5,6 +5,8 @@ import { WebSocket } from "ws";
import isReachable from "is-reachable";
import * as TOML from '@ltd/j-toml';
import axios from "axios";
import * as _ from "lodash";

import { log, logger } from "./logging";
import { OCS2Connection } from "./modules/ocs2/cloudapi";
import { loadPL2Module } from "./modules/pl2";
Expand Down Expand Up @@ -52,7 +54,8 @@ export let config = {
async function main() {
// Read configuration file
try {
config = TOML.parse(fs.readFileSync(process.env.CONFIG_FILE ?? path.join(__dirname, "prolinux.toml"), "utf-8")) as typeof config;
const tomlConfig = TOML.parse(fs.readFileSync(process.env.CONFIG_FILE ?? path.join(__dirname, "prolinux.toml"), "utf-8")) as typeof config;
config = _.merge(config, tomlConfig);
log.info("Configuration file loaded!");
log.info(JSON.stringify(config, null, 4));
} catch(e) {
Expand Down Expand Up @@ -131,7 +134,7 @@ async function main() {
replyResult(LocalActions.SET_HOSTNAME, true, {});
} break;
case LocalActions.SET_DISABLE_KEXEC: {
config.pl2.disable_kexec = msg.payload.disable_kexec;
config.pl2.disable_kexec = msg.payload.disableKexec;
saveConfig();
replyResult(LocalActions.SET_DISABLE_KEXEC, true, {});
} break;
Expand All @@ -150,6 +153,7 @@ async function main() {
selectedRoot: config.pl2.selected_root,
lockedRoot: config.pl2.locked_root,
hostname: config.pl2.hostname,
disable_kexec: config.pl2.disable_kexec,
buildInfo: await getProLinuxInfo(),
config: config
},
Expand Down

0 comments on commit d3f6cbc

Please sign in to comment.