去除多余变量

调整部分方法内容
This commit is contained in:
陌生人 2024-11-18 13:35:19 +08:00 committed by wangpenglong
parent 53c9a95e4e
commit 9740b7b5c4
1 changed files with 52 additions and 60 deletions

View File

@ -1,16 +1,10 @@
const os = require('os');
const fs = require('fs');
var os_arch;
var os_org;
var os_type;
var os_custom;
var pretty_name;
var milestone;
var dist_id;
var pretty_name;
var os_info;
const os_info = { info: null, arch: null, org: null, type: null, custom: null, pretty_name: null, milestone: null, dist_id: null };
const kyinfoPath = '/etc/.kyinfo';
const osReleasePath = '/etc/os-release';
const kyinfoPathIsExist = fs.existsSync(kyinfoPath);
//检查系统架构
function getArch() {
const arch = os.arch();
@ -24,14 +18,15 @@ function getArch() {
'loongarch': 'loongarch'
}
let res = archObj[arch] || arch;
os_info['arch'] = res;
return res;
}
function getoskey() {
if (os_arch == 'x86' && os_org == 'openkylin' && os_type == 'desktop') {
return "x86_openkylin_desktop";
if (os_info['arch'] == 'x86' && os_info['org'] == 'openkylin' && os_info['type'] == 'desktop') {
os_info['info'] = "x86_openkylin_desktop";
}
return "undefined"
os_info['info'] = "undefined";
}
@ -56,7 +51,7 @@ function getFileData() {
//5、是否带sp是sp几
//6、小版本号
//7、定制版字符
os_arch = getArch();
getArch();
/*
1.存在.kyinfo的系统 取值dist_id 架构之前的信息
2.不在.kyinfo的系统但是存在os-release 的kylin系统
@ -64,8 +59,8 @@ function getFileData() {
*/
let data;
let releasedata;
if (fs.existsSync(kyinfoPath) && fs.existsSync(osReleasePath)) {
os_org = "kylin";
if (kyinfoPathIsExist && fs.existsSync(osReleasePath)) {
os_info['org'] = "kylin";
try {
let version_id;
data = fs.readFileSync(kyinfoPath, 'utf8');
@ -76,16 +71,16 @@ function getFileData() {
lines.forEach((line) => {
line = line.replace(/ /g, "");
if (line.startsWith("milestone=")) {
milestone = line.slice(10).toLocaleLowerCase();
os_info['milestone'] = line.slice(10).toLocaleLowerCase();
} else if (line.startsWith("dist_id=")) {
dist_id = line.slice(8).toLocaleLowerCase();
os_info['dist_id'] = line.slice(8).toLocaleLowerCase();
}
});//end lines
const releasedatalines = releasedata.split('\n');
releasedatalines.forEach((line) => {
if (line.startsWith("PRETTY_NAME=")) {
pretty_name = line.slice(12).toLocaleLowerCase().replace(/"/g, '');
os_info['pretty_name'] = line.slice(12).toLocaleLowerCase().replace(/"/g, '');
} else if (line.startsWith("VERSION_ID=")) {
version_id = line.slice(11).toLocaleLowerCase().replace(/"/g, '');
}
@ -93,24 +88,24 @@ function getFileData() {
if (version_id) {
os_version_id = version_id;
}
os_type = dist_id.includes('desktop') ? "desktop" : "server";
if (milestone.indexOf('release')) {
os_release = milestone.slice(milestone.indexOf('release') + 8);
os_info['type'] = os_info['dist_id'].includes('desktop') ? "desktop" : "server";
if (os_info['milestone'].indexOf('release')) {
os_release = os_info['milestone'].slice(os_info['milestone'].indexOf('release') + 8);
}
if (dist_id.includes('edu')) {
os_custom = 'edu';
if (os_info['dist_id'].includes('edu')) {
os_info['custom'] = 'edu';
} else {
os_custom = 'gen';
os_info['custom'] = 'gen';
}
if (dist_id.includes('hwe')) {
os_custom += 'hwe';
if (os_info['dist_id'].includes('hwe')) {
os_info['custom'] += 'hwe';
}
if (dist_id.includes('gfb')) {
os_custom += 'gfb'
if (os_info['dist_id'].includes('gfb')) {
os_info['custom'] += 'gfb'
}
} catch (err) {
os_info = "";
os_info['info'] = "";
console.log(err);
}
} else
@ -121,64 +116,61 @@ function getFileData() {
const releasedatalines = releasedata.split('\n');
releasedatalines.forEach((line) => {
if (line.startsWith("PRETTY_NAME=")) {
pretty_name = line.slice(12).toLocaleLowerCase().replace(/"/g, '');
pretty_name = pretty_name.replace(/ /g, "_")
os_info['pretty_name'] = line.slice(12).toLocaleLowerCase().replace(/"/g, '');
os_info['pretty_name'] = os_info['pretty_name'].replace(/ /g, "_")
} else if (line.startsWith("VERSION_ID=")) {
version_id = line.slice(11).toLocaleLowerCase().replace(/"/g, '');
} else if (line.startsWith("ID=")) {
os_org = line.slice(3).toLocaleLowerCase().replace(/"/g, '');
os_info['org'] = line.slice(3).toLocaleLowerCase().replace(/"/g, '');
} else if (line.startsWith("VERSION_CODENAME=")) {
os_custom = line.slice(17).toLocaleLowerCase().replace(/"/g, '');
os_info['custom'] = line.slice(17).toLocaleLowerCase().replace(/"/g, '');
} else if (line.startsWith('NAME=')) {
os_org = line.slice(5).toLocaleLowerCase().replace(/"/g, '')
os_info['org'] = line.slice(5).toLocaleLowerCase().replace(/"/g, '')
}
});
if (version_id) {
os_version_id = version_id;
}
if (pretty_name.includes('openkylin'))
os_type = "desktop";
if (os_info['pretty_name'].includes('openkylin'))
os_info['type'] = "desktop";
} catch (err) {
os_info = "";
os_info['info'] = "";
}
}
}
function getosinfo() {
os_info = getoskey();
return os_info;
getoskey();
return os_info['info'];
}
function showosinfo() {
let osData = '';
if (fs.existsSync(kyinfoPath)) {
if (os_arch) { osData += os_arch; }
if (os_org) { osData += "_" + os_org; }
if (milestone) { osData += "_" + milestone; }
osData = osData.replace(/^_+|_+$/g, '');
osData = osData.replace("-release-", "-");
osData = osData.replace(/-/g, "_");
return osData;
let keyList = [];
if (kyinfoPathIsExist) {
keyList = ['arch', 'org', 'milestone'];
}
else {
//架构
if (os_arch) { osData += os_arch; }
//组织
if (os_org) { osData += "_" + os_org; }
//操作系统类型
if (os_type) { osData += "_" + os_type; }
if (pretty_name) { osData += "_" + pretty_name; }
if (os_custom) { osData += "_" + os_custom; }
osData = osData.replace(/^_+|_+$/g, '');
return osData;
//架构 组织 操作系统类型
keyList = ['arch', 'org', 'type', 'pretty_name', 'custom'];
}
let osDataList = [];
for (let key of keyList) {
osDataList.push(os_info[key]);
}
osData = osDataList.join('_')
osData = osData.replace(/^_+|_+$/g, '');
if (kyinfoPathIsExist) {
osData = osData.replace("-release-", "-");
osData = osData.replace(/-/g, "_");
}
return osData;
}
function getsupportlist() {
let strArry = ["X86 openkylin操作系统"
];
let strArry = ["X86 openkylin操作系统"];
return strArry;
}