Skip to content

Commit 2c4dd53

Browse files
committed
Add history cleaning script
1 parent 4d5ea87 commit 2c4dd53

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Diff for: maintenance.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"adobe_reader.*",
3535
"amsn.*",
3636
"amule.*",
37-
"apt.*",
3837
"audacious.*",
3938
"bash.*",
4039
"beagle.*",
@@ -66,7 +65,7 @@
6665
# "firefox.cookies",
6766
"firefox.crash_reports",
6867
"firefox.dom",
69-
"firefox.download_history",
68+
# "firefox.download_history",
7069
"firefox.forms",
7170
# "firefox.passwords",
7271
"firefox.session_restore",
@@ -140,6 +139,10 @@
140139
"yum.*"
141140
]
142141

142+
BLEACHBIT_ROOT: tp.List[str] = [
143+
"apt.*",
144+
]
145+
143146
BLEACHBIT_DEEP: tp.List[str] = [
144147
"deepscan.backup",
145148
"deepscan.ds_store",
@@ -193,9 +196,13 @@ def bleachbit(deep: bool = False, firefox: bool = False, thunderbird: bool = Fal
193196
args += BLEACHBIT_FIREFOX
194197
if thunderbird:
195198
args += BLEACHBIT_THUNDERBIRD
196-
# Bleachbit does not run with the run() function for some reason
199+
# Bleachbit does not run with the run() function for some reason.
200+
# Run both as root and as the current user.
197201
if os.geteuid() != 0:
198-
args.insert(0, "sudo")
202+
args2 = ["sudo", *args, *BLEACHBIT_ROOT]
203+
sp.run(args2, check=True)
204+
else:
205+
args += BLEACHBIT_ROOT
199206
sp.run(args, check=True)
200207

201208

@@ -358,6 +365,7 @@ def zgen() -> None:
358365

359366
def main():
360367
parser = argparse.ArgumentParser(description="Maintenance script")
368+
parser.add_argument("--bleachbit-only", help="Run only Bleachbit", action="store_true")
361369
parser.add_argument("--deep", help="Deep-clean all", action="store_true")
362370
parser.add_argument("--docker", help="Deep-clean Docker", action="store_true")
363371
parser.add_argument("--firefox", help="Deep-clean Firefox", action="store_true")
@@ -376,6 +384,10 @@ def main():
376384
if args.virtualbox:
377385
raise NotImplementedError("VirtualBox support does not work yet.")
378386

387+
if args.bleachbit_only:
388+
bleachbit(deep=args.deep, firefox=(args.deep or args.firefox), thunderbird=(args.deep or args.thunderbird))
389+
return
390+
379391
zero = get_zerofree_status(args)
380392

381393
print_info("Running maintenance script")

Diff for: security/clear_history.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
5+
REPO_DIR="$(dirname "${SCRIPT_DIR}")"
6+
7+
# Bash history
8+
# Handled by BleachBit
9+
# history -c
10+
11+
python3 "${REPO_DIR}/maintenance.py" --bleachbit-only
12+
13+
# https://askubuntu.com/a/155777/
14+
# https://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/
15+
sync
16+
echo 3 | sudo tee /proc/sys/vm/drop_caches
17+
18+
# TODO: Add BleachBit here
19+
20+
# TRIM free disk space
21+
fstrim -a -v

Diff for: zsh/custom/utils.zsh

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ apt-rdepends-installed () {
1010
apt-cache rdepends "$@" | grep " " | xargs apt list --installed
1111
}
1212

13+
clear-history() {
14+
"${HOME}/Git/linux-scripts/security/clear_history.sh"
15+
}
16+
1317
compress_7z() {
1418
if [ $# -lt 1 ]; then
1519
echo "Please give the file path."

0 commit comments

Comments
 (0)