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
3.5 KiB

  1. /* eslint-disable no-console */
  2. /**
  3. * penguins-eggs: Bleach.ts
  4. *
  5. * author: Piero Proietti
  6. * mail: piero.proietti@gmail.com
  7. */
  8. import fs = require('fs')
  9. import Utils from './utils'
  10. // libraries
  11. const exec = require('../lib/utils').exec
  12. /**
  13. * Bleach:
  14. */
  15. export default class Bleach {
  16. /**
  17. * clean
  18. * @param verbose
  19. */
  20. async clean(verbose = false) {
  21. await this.cleanApt(verbose)
  22. await this.cleanHistory(verbose)
  23. await this.cleanJournal(verbose)
  24. await this.cleanSystemCache(verbose)
  25. }
  26. /**
  27. * cleanApt
  28. * @param verbose
  29. */
  30. private async cleanApt(verbose = false) {
  31. let echo = { echo: false, ignore: true, capture: false }
  32. if (verbose) {
  33. echo = { echo: true, ignore: true, capture: false }
  34. Utils.warning('cleaning apt')
  35. }
  36. await exec('apt clean', echo)
  37. await exec('apt autoclean', echo)
  38. const dest = '/var/lib/apt/lists/'
  39. rmdir(dest, verbose)
  40. }
  41. /**
  42. * cleanHistory
  43. * @param verbose
  44. */
  45. private async cleanHistory(verbose = false) {
  46. if (verbose) {
  47. Utils.warning('cleaning bash history')
  48. }
  49. const dest = '/root/.bash_history'
  50. if (fs.existsSync(dest)) {
  51. await rm(dest, verbose)
  52. }
  53. }
  54. /**
  55. * cleanJournal
  56. * @param verbose
  57. */
  58. private async cleanJournal(verbose = false) {
  59. let echo = { echo: false, ignore: true, capture: false }
  60. if (verbose) {
  61. echo = { echo: true, ignore: true, capture: false }
  62. Utils.warning('cleaning journald')
  63. }
  64. // Non puo funzionare su devuan utilizzare logrotate?
  65. await exec('journalctl --rotate', echo)
  66. await exec('journalctl --vacuum-time=1s', echo)
  67. }
  68. /**
  69. * cleanSystemCache
  70. * @param verbose
  71. */
  72. private async cleanSystemCache(verbose = false) {
  73. let echo = { echo: false, ignore: true, capture: false }
  74. if (verbose) {
  75. echo = { echo: true, ignore: true, capture: false }
  76. Utils.warning('cleaning system cache')
  77. }
  78. // Clear PageCache only.
  79. await exec('sync; echo 1 > /proc/sys/vm/drop_caches', echo)
  80. // Clear dentries and inodes.
  81. await exec('sync; echo 2 > /proc/sys/vm/drop_caches', echo)
  82. // Clear PageCache, dentries and inodes.
  83. await exec('sync; echo 3 > /proc/sys/vm/drop_caches', echo)
  84. }
  85. }
  86. /**
  87. *
  88. * @param dest
  89. */
  90. async function rm(dest = '', verbose = false) {
  91. let echo = { echo: false, ignore: true, capture: false }
  92. if (verbose) {
  93. echo = { echo: true, ignore: true, capture: false }
  94. }
  95. if (fs.existsSync(dest)) {
  96. await exec(`rm ${dest} -rf`, echo)
  97. } else {
  98. console.log(`non esiste ${dest}`)
  99. }
  100. }
  101. async function rmdir(dest = '', verbose = false) {
  102. let echo = { echo: false, ignore: true, capture: false }
  103. if (verbose) {
  104. echo = { echo: true, ignore: true, capture: false }
  105. }
  106. const result: string[] = fs.readdirSync(dest)
  107. if (result.length > 0) {
  108. await exec(`rm ${dest} -rf`, echo)
  109. }
  110. }
  111. /**
  112. * Elenco pulitori bleachbit
  113. * Solo quelli pertinenti root
  114. */
  115. /*
  116. # apt
  117. # bash.history
  118. // deepscan.backup
  119. // deepscan.ds_store
  120. // deepscan.thumbs_db
  121. // deepscan.tmp
  122. gnome.run
  123. gnome.search_history
  124. journald.clean
  125. // kde.cache
  126. // kde.recent_documents
  127. // kde.tmp
  128. # system.cache
  129. system.clipboard // xclip
  130. system.custom
  131. system.desktop_entry
  132. system.free_disk_space
  133. system.localizations
  134. system.memory
  135. system.recent_documents
  136. system.rotated_logs
  137. system.tmp
  138. system.trash
  139. wine.tmp
  140. winetricks.temporary_files
  141. x11.debug_logs
  142. yum.clean_all
  143. yum.vacuum
  144. */