Browse Source

clean espanso per apt, history, journald, system cache. variz. homepage

tags/v7.8.10
Piero Proietti 11 months ago
parent
commit
2ec50783cd
4 changed files with 130 additions and 17 deletions
  1. +2
    -1
      README.md
  2. +2
    -2
      package.json
  3. +123
    -10
      src/classes/bleach.ts
  4. +3
    -4
      src/lib/utils.ts

+ 2
- 1
README.md View File

@@ -34,7 +34,8 @@ key to boot your system. You can also boot your egg - via remote boot - on your
LAN.

All it is written in pure typescript, so ideally can be used with differents Linux
distros. At the moment it is tested with Debian 10 Buster, and LMDE4.
distros. Yes, there are big differences about package manager used, but not so
much in the way to work of bash and various programs used to build the iso.

penguins-eggs, at the moment 2020 may 12 is a working tool, yes can have again
same troubles for people not in confidence with Linux system administration, but


+ 2
- 2
package.json View File

@@ -6,6 +6,8 @@
"bin": {
"eggs": "./bin/run"
},
"homepage": "https://penguin-s-eggs.gitbook.io/project/",
"repository": "https://github.com/pieroproietti/penguins-eggs",
"bugs": "https://github.com/pieroproietti/penguins-eggs/issues",
"dependencies": {
"@oclif/command": "^1.6.1",
@@ -69,7 +71,6 @@
"/scripts",
"/templates"
],
"homepage": "https://github.com/pieroproietti/penguins-eggs",
"keywords": [
"oclif"
],
@@ -82,7 +83,6 @@
"@oclif/plugin-help"
]
},
"repository": "pieroproietti/penguins-eggs",
"scripts": {
"docs": "rm docs -rf && npx typedoc src --out docs",
"build": "tsc -p .",


+ 123
- 10
src/classes/bleach.ts View File

@@ -6,9 +6,42 @@
* mail: piero.proietti@gmail.com
*/

import fs = require('fs')
import chalk = require('chalk')
import Utils from './utils'

// libraries
const exec = require('../lib/utils').exec

/**
*
* @param dest
*/
async function rm(dest = '', verbose = false) {
let echo = {echo: false, ignore: true, capture: false}
if (verbose) {
echo = {echo: true, ignore: true, capture: false}
}

if (fs.existsSync(dest)) {
await exec(`rm ${dest} -rf`, echo)
} else {
console.log(`non esiste ${dest}`)
}
}

async function rmdir(dest = '', verbose = false) {
let echo = {echo: false, ignore: true, capture: false}
if (verbose) {
echo = {echo: true, ignore: true, capture: false}
}
const result: string[] = fs.readdirSync(dest)
if ( result.length > 0 ) {
await exec(`rm ${dest} -rf`, echo)
}
}


/**
* Bleach:
*/
@@ -18,26 +51,106 @@ export default class Ovary {
* @param verbose
*/
static async clean(verbose = false) {
await this.cleanJournal(verbose)
await this.cleanApt(verbose)
await this.cleanHistory(verbose)
await this.cleanJournal(verbose)
await this.cleanSystemCache(verbose)
}

/**
*
* @param verbose */
* PULITORI
*/

static async cleanApt(verbose = false) {
let echo = {echo: false, ignore: true, capture: false}
if (verbose) {
echo = {echo: true, ignore: true, capture: false}
Utils.warning('cleaning apt')
}
await exec('apt clean', echo)
await exec('apt autoclean', echo)
const dest = '/var/lib/apt/lists/'
rmdir(dest, verbose)
}

static async cleanHistory(verbose = false) {
if (verbose) {
Utils.warning('cleaning bash history')
}
const dest = '/root/.bash_history'
if (fs.existsSync(dest)) {
await rm(dest, verbose)
}
}

static async cleanJournal(verbose = false) {
let echo = {echo: false, ignore: true, capture: false}
if (verbose) {
console.log('cleang journal')
echo = {echo: true, ignore: true, capture: false}
Utils.warning('cleaning journald')
}
await exec('journalctl --rotate')
await exec('journalctl --vacuum-time=1s')
await exec('journalctl --rotate', echo)
await exec('journalctl --vacuum-time=1s', echo)
}

static async cleanApt(verbose = false) {
static async cleanSystemCache(verbose = false) {
let echo = {echo: false, ignore: true, capture: false}
if (verbose) {
console.log('cleang apt')
echo = {echo: true, ignore: true, capture: false}
Utils.warning('cleaning system cache')
}
await exec('apt clean')
await exec('apt autoclean')
// Clear PageCache only.
await exec('sync; echo 1 > /proc/sys/vm/drop_caches', echo)

// Clear dentries and inodes.
await exec('sync; echo 2 > /proc/sys/vm/drop_caches', echo)

// Clear PageCache, dentries and inodes.
await exec('sync; echo 3 > /proc/sys/vm/drop_caches', echo)
}
}

/**
* Elenco pulitori bleachbit
* Solo quelli pertinenti root
*/

/*

# apt
# bash.history

// deepscan.backup
// deepscan.ds_store
// deepscan.thumbs_db
// deepscan.tmp

gnome.run
gnome.search_history

journald.clean

// kde.cache
// kde.recent_documents
// kde.tmp

# system.cache
system.clipboard // xclip
system.custom
system.desktop_entry
system.free_disk_space
system.localizations
system.memory
system.recent_documents
system.rotated_logs
system.tmp
system.trash

wine.tmp
winetricks.temporary_files

x11.debug_logs

yum.clean_all
yum.vacuum
*/

+ 3
- 4
src/lib/utils.ts View File

@@ -8,16 +8,15 @@
*
* @returns {Promise<{code: number, data: string | undefined, error: Object}>}
*/
export function exec(command: string, { echo = false, ignore = false, capture = false } = {}) {
export function exec(command: string, { echo = false, ignore = false, capture = false } = {}) {
if (echo) {
console.log(command)
}

const spawn = require('child_process').spawn;
// const childProcess = spawn('bash', ['-c', command], { stdio: capture ? 'pipe' : 'inherit' });
//const childProcess = spawn('bash', ['-c', command], { stdio: capture ? 'pipe' : ignore ? 'ignore' : 'inherit' });
// const childProcess = spawn('bash', ['-c', command], { stdio: capture ? 'pipe' : 'inherit' });
// const childProcess = spawn('bash', ['-c', command], { stdio: capture ? 'pipe' : ignore ? 'ignore' : 'inherit' });
const childProcess = spawn('bash', ['-c', command], { stdio: ignore ? 'ignore' : capture ? 'pipe' : 'inherit' });

return new Promise((resolve, reject) => {
let stdout = ''


Loading…
Cancel
Save