spacedrive/scripts/utils/machineId.mjs

69 lines
1.6 KiB
JavaScript
Raw Normal View History

[ENG-927, ENG-735, ENG-766] Fix Updater & Tauri 1.5 (#1361) * custom updater with toasts * new state management + updated router route * tauri-specific update route * ref * update in prod only * change 'Install' to 'Update' * fix tsconfig * desktop tauri * remove tauri patch * tauri 1.5 * tauri 1.5 * use tauri script * native-deps * Rework preprep and tauri script to better support tauri 1.5 * Update to tauri 1.5.1 - Update workspace and apps/desktop dependencies - Fix mustache import, @types/mustache is not compatible with ES imports - Replace arm64 with aarch64 in machineID, they should be treated the same and this simplyfies the code * Fix tauri updater not building due to missing key - Fix dmg background not being found - Generate an adhoc key for tauri updater with it is enabled and the user is doing a prod build * Fix ctrl+c/ctrl+v typo * Normalie @tanstack/react-query version through workspace - Use undici in scripts instead of global fetch - Fix typecheck * Fix linux prod and dev builds - Improve error handling in tauri.mjs * Normalize dev deps in workspace - Improve linux shared libs setup * Fix CI and server docker * Fix windows - Remove superfluous envvar * Attempt to fix server, mobile, deb and release updater * Attempt to fix deb and mobile again - Fix type on deb dependency - Enable release deb for aarch64-unknown-linux-gnu * Github doesn't have arm runners - Fix typo in server Dockerfile * Publish deb and updater artifacts * remove version from asset name * update commands * log release * Some logs on updater errors * show updater errors on frontend * fix desktop ui caching --------- Co-authored-by: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Co-authored-by: Ericson Fogo Soares <ericson.ds999@gmail.com>
2023-10-10 07:30:56 +00:00
import { exec as execCb } from 'node:child_process'
import * as os from 'node:os'
import { env } from 'node:process'
import { promisify } from 'node:util'
const __debug = env.NODE_ENV === 'debug'
/** @type {'musl' | 'glibc'} */
let libc = 'glibc'
if (os.type() === 'Linux') {
try {
const exec = promisify(execCb)
if ((await exec('ldd /bin/ls')).stdout.includes('musl')) {
libc = 'musl'
}
} catch (error) {
if (__debug) {
console.warn(`Failed to check libc type`)
console.error(error)
}
}
}
/** @type {Record<string, string>} */
const OS_TYPE = {
darwin: 'Darwin',
windows: 'Windows_NT',
linux: 'Linux',
}
/** @returns {['Darwin' | 'Windows_NT', 'x86_64' | 'aarch64'] | ['Linux', 'x86_64' | 'aarch64', 'musl' | 'glibc']} */
export function getMachineId() {
let _os, _arch
let _libc = libc
/**
* Supported TARGET_TRIPLE:
* x86_64-apple-darwin
* aarch64-apple-darwin
* x86_64-pc-windows-msvc
* aarch64-pc-windows-msvc
* x86_64-unknown-linux-gnu
* x86_64-unknown-linux-musl
* aarch64-unknown-linux-gnu
* aarch64-unknown-linux-musl
*/
if (env.TARGET_TRIPLE) {
const target = env.TARGET_TRIPLE.split('-')
_os = OS_TYPE[target[2] ?? '']
_arch = target[0]
if (_os === 'Linux') _libc = target[3]?.includes('musl') ? 'musl' : 'glibc'
} else {
// Current machine identifiers
_os = os.type()
_arch = os.machine()
if (_arch === 'arm64') _arch = 'aarch64'
}
if (_arch !== 'x86_64' && _arch !== 'aarch64') throw new Error(`Unsuported architecture`)
if (_os === 'Linux') {
return [_os, _arch, _libc]
} else if (_os !== 'Darwin' && _os !== 'Windows_NT') {
throw new Error(`Unsuported OS`)
}
return [_os, _arch]
}