-
Notifications
You must be signed in to change notification settings - Fork 1
/
deb-squeaky-clean
executable file
·71 lines (59 loc) · 1.87 KB
/
deb-squeaky-clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
#
# NAME
#
# deb-squeaky-clean - clean a Debian desktop system
#
# SYNOPSIS
#
# deb-squeaky-clean
#
# DESCRIPTION
#
# deb-squeaky-clean clears APT's cache, removes residual
# and broken packages, removes other temporary and/or log
# files, etc.
#
[[ $(id -u) == 0 ]] || exec sudo -- "$0" "$@"
# Log files ------------------------------------------------------------
# Delete all old, gzipped, and rotated log files.
find /var/log -type f -name '*.gz' -delete
find /var/log -type f -name '*.[0-9]' -delete
find /var/log -type f -name '*.old' -delete
# Remove systemd log files that are older than 1 day.
# https://unix.stackexchange.com/q/130786
journalctl --vacuum-time=1d
# APT packages ---------------------------------------------------------
# Remove useless packages.
apt --yes --purge autoremove
apt --yes clean
# Purge residual packages.
IFS=$'\n' read -r -d '' -a pkgs < <(dpkg --list | grep '^rc' | cut -d ' ' -f 3)
[[ ${#pkgs[@]} == 0 ]] || dpkg --purge "${pkgs[@]}"
# Purge broken packages.
IFS=$'\n' read -r -d '' -a pkgs < <(dpkg --list | grep '^iU' | cut -d ' ' -f 3)
[[ ${#pkgs[@]} == 0 ]] || dpkg --purge "${pkgs[@]}"
# Network Manager -------------------------------------------------------
# Gets days since supplied date.
nm_days_unused() {
if [[ "$1" == "never" ]]
then
echo 1000000
else
before=$(date -d "$1" +%s)
today=$(date +%s)
echo $(( (today - before) / 86400 ))
fi
}
# Remove all WiFi connections that haven't been used in more than 180
# days.
while IFS= read -r line
do
uuid=$(echo "$line" | sed 's/\(^[^ \t]*\).*/\1/')
used=$(echo "$line" | sed 's/^[^ \t]*[ \t]*//;s/[ \t]*$//')
[[ "$used" == "TIMESTAMP-REAL" ]] && continue
if [[ $(nm_days_unused "$used") -gt 180 ]]
then
nmcli con delete uuid "$uuid"
fi
done < <(nmcli --fields UUID,TIMESTAMP-REAL con show)