rpi_setup/scripts/flash.ts
2024-03-13 14:46:29 +01:00

40 lines
818 B
TypeScript

import config from '../config.json' with { type: 'json' }
console.log(
`%c[setup:flash]%c running rpi-imager`,
'color: royalblue; font-weight: bold',
'',
)
const rpiImager = new Deno.Command('rpi-imager', {
args: [
'--cli',
'--first-run-script',
'./dist/prepare.sh',
'./dist/rpi_os.img',
config.image.drive,
],
})
try {
console.log(
`%c[setup:flash]%c flashing img to drive %c${config.image.drive}`,
'color: royalblue; font-weight: bold',
'',
'text-decoration: underline',
)
await rpiImager.spawn().output()
console.log(
`%c[setup:flash]%c drive successfully flashed`,
'color: green; font-weight: bold',
'',
)
} catch (error) {
console.error(
`%c[setup:flash]%c can't rpi-imager or return error`,
'color: red; font-weight: bold',
'',
)
console.error(error)
Deno.exit(1)
}