/**
 * penguins-eggs-v8
 * author: Piero Proietti
 * email: piero.proietti@gmail.com
 * license: MIT
 */ import fs from 'node:fs' ; import shx from 'shelljs' ; import Utils from '../utils' ; import Pacman from '../pacman' ; import { array2spaced } from '../../lib/dependencies' ; import { exec } from '../../lib/utils' ; remarks export default class Fedora { static packs4calamares = [ 'calamares' ] ; returns static isInstalledXorg ( ) { return this . packageIsInstalled ( 'xorg-x11-server-Xorg.x86_64' ) ; } returns static isInstalledWayland ( ) { return this . packageIsInstalled ( 'xorg-x11-server-Xwayland*' ) ; } /**
     * Crea array pacchetti da installare/rimuovere
     */ static packages ( remove = false , verbose = false ) { const packages = [ 'xorriso' , 'xz-lzma-compat' , 'syslinux' , 'squashfs-tools' ] ; const toInstall = [ ] ; const toRemove = [ ] ; for ( const elem of packages ) { if ( ! this . packageIsInstalled ( elem ) ) { toInstall . push ( elem ) ; } else { toRemove . push ( elem ) ; } } if ( remove ) { return toRemove ; } return toInstall ; } /**
     *
     */ static async prerequisitesInstall ( verbose = true ) { const echo = Utils . setEcho ( verbose ) ; const retVal = false ; await exec ( `dnf install ${ array2spaced ( this . packages ( false , verbose ) ) }` , echo ) ; if ( ! Pacman . isInstalledGui ( ) ) { /**
             * live-config-getty-generator
             *
             * Viene rimosso in naked, altrimenti non funziona il login
             * generando un errore getty.
             * Sarebbe utile individuarne le ragioni, forse rompe anche sul desktop
             * non permettendo di cambiare terminale e loggarsi
             *
             * A che serve?
             */ const fileToRemove = '/lib/systemd/system-generators/live-config-getty-generator' ; if ( fs . existsSync ( fileToRemove ) ) { await exec ( `rm ${ fileToRemove }` ) ; } } return retVal ; } /**
     * Torna verso se calamares è installato
     */ static async calamaresCheck ( ) { let installed = true ; for ( const i in this . packs4calamares ) { if ( ! this . packageIsInstalled ( this . packs4calamares [ i ] ) ) { installed = false ; break ; } } return installed ; } /**
     *
     */ static async calamaresInstall ( verbose = true ) { const echo = Utils . setEcho ( verbose ) ; try { await exec ( `dnf install ${ array2spaced ( this . packs4calamares ) }` , echo ) ; } catch { Utils . error ( `Fedora.calamaresInstall() pacman -Sy ${ array2spaced ( this . packs4calamares ) }` ) ; } } /**
     * calamaresPolicies
     */ static async calamaresPolicies ( ) { const policyFile = '/usr/share/polkit-1/actions/com.github.calamares.calamares.policy' ; } /**
     *
     */ static async calamaresRemove ( verbose = true ) { const echo = Utils . setEcho ( verbose ) ; const retVal = false ; if ( fs . existsSync ( '/etc/calamares' ) ) { await exec ( 'rm /etc/calamares -rf' , echo ) ; } await exec ( 'yay -Rns calamares' , echo ) ; return retVal ; } param packageName static packageIsInstalled ( packageName ) { let installed = false ; const cmd = `/usr/bin/dnf list --installed ${ packageName }` ; const stdout = shx . exec ( cmd , { silent : true } ) . stdout . trim ( ) ; if ( stdout . includes ( packageName ) ) { installed = true ; } return installed ; } param packageName { string } returns { boolean } static async packageInstall ( packageName ) { let retVal = false ; if ( shx . exec ( `/usr/bin/dnf install ${ packageName }` , { silent : true } ) === '0' ) { retVal = true ; } return retVal ; } param packageName static async packageAvailable ( packageName ) { let available = false ; const cmd = `/usr/bin/dnf list --available ${ packageName } | grep Package:` ; const stdout = shx . exec ( cmd , { silent : true } ) . stdout . trim ( ) ; if ( stdout . includes ( packageName ) ) { available = true ; } return available ; } }