UNPKG

pooliot-client

Version:
141 lines (118 loc) 2.87 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _fs = require('fs'); var _envfile = require('envfile'); var _envfile2 = _interopRequireDefault(_envfile); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const getModelInfo = () => { try { return (0, _fs.readFileSync)('/proc/device-tree/model', { encoding: 'utf-8' }); } catch (err) { return ''; } }; const getHardwareInfo = () => { let cpuInfo; try { cpuInfo = (0, _fs.readFileSync)('/proc/cpuinfo', { encoding: 'utf-8' }); } catch (e) { return {}; } const data = new Map(cpuInfo.split('\n').map(line => line.replace(/\t/g, '')).filter(line => line.length).map(line => { const splitted = line.split(':'); return [splitted[0].trim(), splitted.slice(1).join(':').trim()]; })); return { model: data.get('Hardware'), serial: data.get('Serial'), revision: data.get('Revision') }; }; const getOsInfo = () => { const snakeCaseToCamelCase = s => s.toLowerCase().replace(/(_\w)/g, m => m[1].toUpperCase()); try { const parsed = _envfile2.default.parseFileSync('/etc/os-release'); const osInfo = {}; Object.keys(parsed).forEach(key => { osInfo[snakeCaseToCamelCase(key)] = parsed[key]; }); return osInfo; } catch (err) { console.warn(err); return { id: 'unknown' }; } }; const isPi = model => model.startsWith('Raspberry Pi'); const rpiVersion = () => { try { // eslint-disable-next-line return require('raspi-ver'); } catch (err) { return null; } }; const detect = () => { const hardwareInfo = getHardwareInfo(); const osInfo = getOsInfo(); const model = getModelInfo(); let user; if (osInfo.id === 'osmc') { user = 'osmc'; } if (isPi(model)) { return { id: 'rpi', name: 'Raspberry PI', user: user || 'pi', info: rpiVersion(), os: osInfo, hardware: hardwareInfo, touchscreen: 'FT5406 memory based driver', sound: { type: 'alsamixer', jack: [3, 1], hdmi: [3, 2] } }; } if (hardwareInfo.model && hardwareInfo.model.startsWith('Rockchip')) { return { id: 'tkb', name: 'Tinker Board', user: 'linaro', os: osInfo, hardware: hardwareInfo, touchscreen: 'fts_ts', sound: { type: 'pulseaudio', jack: [2], hdmi: [3] } }; } if (hardwareInfo.model === 'Vero4K') { return { id: 'vero4k', name: 'Vero4K', user, os: osInfo, hardware: hardwareInfo }; } return { id: 'unknown', name: 'Unknown', os: osInfo, hardware: hardwareInfo }; }; let cache; exports.default = () => { if (!cache) cache = detect(); return cache; }; //# sourceMappingURL=detectBoard.js.map