Penguin's eggs are generated and new birds are ready to fly... https://penguins-eggs.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

172 lines
5.2 KiB

  1. /**
  2. * penguins-eggs: buster/calamares-config.ts
  3. *
  4. * author: Piero Proietti
  5. * mail: piero.proietti@gmail.com
  6. */
  7. import fs = require('fs')
  8. import path = require('path')
  9. import shx = require('shelljs')
  10. import Utils from '../utils'
  11. import Pacman from '../pacman'
  12. import { IRemix, IDistro } from '../../interfaces'
  13. import { Buster } from './buster'
  14. import { Beowulf } from './beowulf'
  15. import { Focal } from './focal'
  16. import { Bionic } from './bionic'
  17. const exec = require('../../lib/utils').exec
  18. /**
  19. *
  20. */
  21. export default class CalamaresConfig {
  22. verbose = false
  23. remix: IRemix
  24. distro: IDistro
  25. user_opt: string
  26. displaymanager = false
  27. sourcesMedia = false
  28. sourcesTrusted = true
  29. /**
  30. *
  31. * @param remix
  32. * @param distro
  33. * @param verbose
  34. */
  35. constructor(remix: IRemix, distro: IDistro, user_opt: string = 'live', verbose = false) {
  36. this.remix = remix
  37. this.distro = distro
  38. this.user_opt = user_opt
  39. this.verbose = verbose
  40. this.displaymanager = Pacman.packageIsInstalled('lightdm') || Pacman.packageIsInstalled('sddm') || Pacman.packageIsInstalled('sddm')
  41. }
  42. /**
  43. * config
  44. */
  45. async config() {
  46. this.createCalamaresDirs()
  47. this.createBranding()
  48. this.createInstallDebian()
  49. if (this.distro.versionLike === 'buster' || this.distro.versionLike === 'stretch' || this.distro.versionLike === 'bulleye') {
  50. const buster = new Buster(this.remix, this.distro, this.displaymanager, this.user_opt, this.verbose)
  51. buster.settings()
  52. buster.modules()
  53. } else if (this.distro.versionLike === 'beowulf') {
  54. const beowulf = new Beowulf(this.remix, this.distro, this.displaymanager, this.user_opt, this.verbose)
  55. beowulf.settings()
  56. beowulf.modules()
  57. } else if (this.distro.versionLike === 'focal') {
  58. const focal = new Focal(this.remix, this.distro, this.displaymanager, this.user_opt, this.verbose)
  59. focal.settings()
  60. focal.modules()
  61. } else if (this.distro.versionLike === 'bionic') {
  62. const bionic = new Bionic(this.remix, this.distro, this.displaymanager, this.user_opt, this.verbose)
  63. bionic.settings()
  64. bionic.modules()
  65. }
  66. }
  67. /**
  68. *
  69. */
  70. private createCalamaresDirs() {
  71. if (!fs.existsSync('/etc/calamares')) {
  72. fs.mkdirSync('/etc/calamares')
  73. }
  74. if (!fs.existsSync('/etc/calamares/branding')) {
  75. fs.mkdirSync('/etc/calamares/branding')
  76. }
  77. if (!fs.existsSync('/etc/calamares/branding/eggs')) {
  78. fs.mkdirSync('/etc/calamares/branding/eggs')
  79. }
  80. if (!fs.existsSync('/etc/calamares/modules')) {
  81. fs.mkdirSync('/etc/calamares/modules')
  82. }
  83. if (!fs.existsSync('/usr/lib/calamares')) {
  84. fs.mkdirSync('/usr/lib/calamares/')
  85. }
  86. if (!fs.existsSync('/usr/lib/calamares/modules')) {
  87. fs.mkdirSync('/usr/lib/calamares/modules')
  88. }
  89. /**
  90. * ADDONS
  91. */
  92. let calamaresBranding = path.resolve(__dirname, `../../../addons/${this.remix.branding}/theme/branding`)
  93. if (fs.existsSync(calamaresBranding)) {
  94. if (!fs.existsSync(`/etc/calamares/branding/${this.remix.branding}`)) {
  95. fs.mkdirSync(`/etc/calamares/branding/${this.remix.branding}`)
  96. }
  97. shx.cp(`${calamaresBranding}/*`, `/etc/calamares/branding/${this.remix.branding}/`)
  98. } else {
  99. console.log(`${calamaresBranding} not found!`)
  100. process.exit()
  101. }
  102. let calamaresIcon = path.resolve(__dirname, `../../../addons/${this.remix.branding}/theme/artwork/install-debian.png`)
  103. if (fs.existsSync(calamaresIcon)) {
  104. shx.cp(calamaresIcon, '/usr/share/icons/')
  105. } else {
  106. console.log(`${calamaresIcon} not found!`)
  107. process.exit()
  108. }
  109. let calamaresLauncher = path.resolve(__dirname, `../../../addons/${this.remix.branding}/theme/applications/install-debian.desktop`)
  110. if (fs.existsSync(calamaresLauncher)) {
  111. shx.cp(calamaresLauncher, '/usr/share/applications/')
  112. } else {
  113. console.log(`${calamaresLauncher} not found!`)
  114. process.exit()
  115. }
  116. // script di avvio
  117. shx.cp(path.resolve(__dirname, '../../../assets/calamares/install-debian'), '/sbin/install-debian')
  118. }
  119. /**
  120. *
  121. */
  122. private createBranding() {
  123. const branding = require('./branding').branding
  124. const dir = `/etc/calamares/branding/${this.remix.branding}/`
  125. if (!fs.existsSync(dir)) {
  126. fs.mkdirSync(dir)
  127. }
  128. const file = dir + 'branding.desc'
  129. const content = branding(this.remix, this.distro, this.verbose)
  130. write(file, content, this.verbose)
  131. }
  132. /**
  133. *
  134. */
  135. private async createInstallDebian() {
  136. const scriptInstallDebian = require('./calamares-modules/scripts/install-debian').installDebian
  137. const scriptDir = `/usr/bin/`
  138. const scriptFile = scriptDir + 'install-debian'
  139. const scriptContent = scriptInstallDebian()
  140. write(scriptFile, scriptContent, this.verbose)
  141. await exec(`chmod +x ${scriptFile}`)
  142. }
  143. }
  144. /**
  145. *
  146. * @param file
  147. * @param content
  148. * @param verbose
  149. */
  150. function write(file: string, content: string, verbose = false) {
  151. if (verbose) {
  152. console.log(`calamares: create ${file}`)
  153. }
  154. fs.writeFileSync(file, content, 'utf8')
  155. }