@@ -2,7 +2,7 @@ const { Binary } = require('binary-install-raw')
2
2
const os = require ( 'os' )
3
3
const chalk = require ( 'chalk' )
4
4
const fetch = require ( 'node-fetch' )
5
- const { filesystem, patching, print } = require ( 'gluegun' )
5
+ const { filesystem, patching, print, system } = require ( 'gluegun' )
6
6
const { fixParameters } = require ( '../command-helpers/gluegun' )
7
7
const path = require ( 'path' )
8
8
const semver = require ( 'semver' )
@@ -103,7 +103,7 @@ async function runBinary(datasource, opts) {
103
103
let latestVersion = opts . get ( "latestVersion" )
104
104
let recompileOpt = opts . get ( "recompile" )
105
105
106
- const platform = getPlatform ( logsOpt )
106
+ const platform = await getPlatform ( logsOpt )
107
107
108
108
const url = `https://github.com/LimeChain/matchstick/releases/download/${ versionOpt || latestVersion } /${ platform } `
109
109
@@ -121,16 +121,18 @@ async function runBinary(datasource, opts) {
121
121
args . length > 0 ? binary . run ( ...args ) : binary . run ( )
122
122
}
123
123
124
- function getPlatform ( logsOpt ) {
124
+ async function getPlatform ( logsOpt ) {
125
125
const type = os . type ( )
126
126
const arch = os . arch ( )
127
- const release = os . release ( )
128
127
const cpuCore = os . cpus ( ) [ 0 ]
129
- const majorVersion = semver . major ( release )
130
128
const isM1 = cpuCore . model . includes ( "Apple M1" )
129
+ const linuxInfo = type === 'Linux' ? await getLinuxInfo ( ) : new Map ( )
130
+ const linuxDistro = linuxInfo . get ( 'name' )
131
+ const release = linuxInfo . get ( 'version' ) || os . release ( )
132
+ const majorVersion = parseInt ( linuxInfo . get ( 'version' ) , 10 ) || semver . major ( release )
131
133
132
134
if ( logsOpt ) {
133
- print . info ( `OS type: ${ type } \nOS arch: ${ arch } \nOS release: ${ release } \nOS major version: ${ majorVersion } \nCPU model: ${ cpuCore . model } ` )
135
+ print . info ( `OS type: ${ linuxDistro || type } \nOS arch: ${ arch } \nOS release: ${ release } \nOS major version: ${ majorVersion } \nCPU model: ${ cpuCore . model } ` )
134
136
}
135
137
136
138
if ( arch === 'x64' || ( arch === 'arm64' && isM1 ) ) {
@@ -146,8 +148,9 @@ function getPlatform(logsOpt) {
146
148
} else if ( type === 'Linux' ) {
147
149
if ( majorVersion === 18 ) {
148
150
return 'binary-linux-18'
151
+ } else {
152
+ return 'binary-linux-20'
149
153
}
150
- return 'binary-linux-20'
151
154
} else if ( type === 'Windows_NT' ) {
152
155
return 'binary-windows'
153
156
}
@@ -156,6 +159,23 @@ function getPlatform(logsOpt) {
156
159
throw new Error ( `Unsupported platform: ${ type } ${ arch } ${ majorVersion } ` )
157
160
}
158
161
162
+ async function getLinuxInfo ( ) {
163
+ try {
164
+ let result = await system . run ( "cat /etc/*-release | grep -E '(^VERSION|^NAME)='" , { trim : true } )
165
+ let infoArray = result . replace ( / [ ' " ] + / g, '' ) . split ( '\n' ) . map ( p => p . split ( '=' ) )
166
+ let infoMap = new Map ( ) ;
167
+
168
+ infoArray . forEach ( ( val ) => {
169
+ infoMap . set ( val [ 0 ] . toLowerCase ( ) , val [ 1 ] )
170
+ } ) ;
171
+
172
+ return infoMap
173
+ } catch ( error ) {
174
+ print . error ( `Error fetching the Linux version:\n ${ error } ` )
175
+ process . exit ( 1 )
176
+ }
177
+ }
178
+
159
179
async function runDocker ( datasource , opts ) {
160
180
let coverageOpt = opts . get ( "coverage" )
161
181
let forceOpt = opts . get ( "force" )
0 commit comments