Skip to content

Commit

Permalink
update loaderEntrues (#418)
Browse files Browse the repository at this point in the history
* to husein

* again

* speriamo...

* fixed on rockylinux
  • Loading branch information
pieroproietti authored Nov 6, 2024
1 parent 961ba1f commit 27049f5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
71 changes: 68 additions & 3 deletions src/krill/modules/bootloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
* https://stackoverflow.com/questions/23876782/how-do-i-split-a-typescript-class-into-multiple-files
*/

import { dir } from 'node:console'
import Utils from '../../classes/utils.js'
import { exec } from '../../lib/utils.js'
import Sequence from '../sequence.js'
import fs from 'node:fs'
import path from 'node:path'
import { subscribe } from 'node:diagnostics_channel'

/**
*
* @param this
*/
export default async function bootloader(this: Sequence) {
let grubInstall='grub-install'
let grubInstall = 'grub-install'
if (this.distro.familyId === 'fedora' || this.distro.familyId === 'opensuse') {
grubInstall='grub2-install'
grubInstall = 'grub2-install'
}
let cmd = `chroot ${this.installTarget} ${grubInstall} ${this.partitions.installationDevice} ${this.toNull}`
try {
Expand All @@ -28,12 +32,73 @@ export default async function bootloader(this: Sequence) {
}

cmd = `chroot ${this.installTarget} grub-mkconfig -o /boot/grub/grub.cfg ${this.toNull}`
if (this.distro.familyId === 'fedora' || this.distro.familyId === 'opensuse' ) {
if (this.distro.familyId === 'fedora' || this.distro.familyId === 'opensuse') {
cmd = `chroot ${this.installTarget} grub2-mkconfig -o /boot/grub2/grub.cfg ${this.toNull}`
}
try {
await exec(cmd, this.echo)
} catch {
await Utils.pressKeyToExit(cmd)
}

// update boot/loader/entries/
const pathEntries = path.join(this.installTarget, '/boot/loader/entries/')
if (fs.existsSync(pathEntries)) {
const uuid = Utils.uuid(this.devices.root.name)
const machineId = fs.readFileSync(path.join(this.installTarget, '/etc/machine-id'), 'utf-8').trim()
await renameLoaderEntries(pathEntries, machineId)
await updateLoaderEntries(pathEntries, uuid)
}
}

/**
*
* @param directoryPath
* @param machineId
*/
async function renameLoaderEntries(directoryPath: string, machineId: string): Promise<void> {
const files: string[] = fs.readdirSync(directoryPath)
if (files.length > 0) {
for (const file of files) {
const oldPath = path.join(directoryPath, file)
let current = file.substring(32)
current = machineId + current
const newPath = path.join(directoryPath, current)
await exec(`mv ${oldPath} ${newPath}`)
}
}
}

/**
*
* @param directoryPath
* @param newUUID
*/
async function updateLoaderEntries(directoryPath: string, newUUID: string): Promise<void> {
const files: string[] = fs.readdirSync(directoryPath)
if (files.length > 0) {
for (const file of files) {
console.log(file)
const filePath = path.join(directoryPath, file)
console.log(`entry: ${filePath}`)
let source = fs.readFileSync(filePath, 'utf8')
let lines = source.split('\n')
let content = ''
for (let line of lines) {
if (line.includes('UUID=')) {
const at = line.indexOf('UUID=')
const p1 = line.substring(0, at + 5)
const p2 = newUUID
const p3 = line.substring(at + 5 + 36)
console.log("Orig: " + line)
console.log("p1: " + p1)
console.log("p2: " + p2)
console.log("p3: " + p3)
line = p1 + p2 + p3
}
content += line + '\n'
}
fs.writeFileSync(filePath, content)
}
}
}
8 changes: 8 additions & 0 deletions src/krill/modules/machine-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ export default async function machineId(this: Sequence): Promise<void> {
await exec(`rm ${file} ${this.toNull}`, this.echo)
}

/**
* machine/id always new now
*/
await exec(`dbus-uuidgen --ensure=${this.installTarget}/var/lib/dbus/machine-id ${this.toNull}`)
await exec(`cp ${this.installTarget}/var/lib/dbus/machine-id ${this.installTarget}/etc/machine-id`)

/*
// On Alpine, we need to create the machine-id file
if (this.distro.familyId === 'alpine') {
await exec(`dbus-uuidgen --ensure=${this.installTarget}/var/lib/dbus/machine-id ${this.toNull}`)
await exec(`cp ${this.installTarget}/var/lib/dbus/machine-id ${this.installTarget}/etc/machine-id`)
} else {
await exec(`touch ${file} ${this.toNull}`)
}
*/
}

0 comments on commit 27049f5

Please sign in to comment.