-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcleanup
executable file
·130 lines (124 loc) · 4.45 KB
/
cleanup
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#
# Update the list of packages in 'data/purge.list' to suit your preferences
# Listed packages that are are not any system-crucial software to avoid breakage
# Remove unused preinstalled apps
function purge_unused {
echo_message title "Starting 'purge_unused' function..."
# Check list
PURGED=$(dirname "$0")'/data/purge.list'
# Draw window
if (eval `resize` && whiptail \
--title "Remove Un-used Pre-installed Applications" \
--yesno "Current list of pre-installed applications to remove: \n\n$(for LINE in $(cat $PURGED); do echo ' '$LINE; done) \n\nAre you sure you want proceed?" \
$LINES $COLUMNS $(( $LINES - 12 )) \
--scrolltext ) then
# Remove loop
echo_message info 'Removing unused pre-installed applications...'
for PACKAGE in $(cat $PURGED); do
# Check if package is installed
check_packages $PACKAGE
EXITSTATUS=$?
# If package is not installed
if [ $EXITSTATUS = 1 ]; then
# Show already installed message
echo "Package '$PACKAGE' is already removed."
else
# Remove package
echo_message info "'$PACKAGE' is installed. Removing..."
# Admin privileges
elevate_privilege "apt purge -y $PACKAGE"
# Done
echo_message success "'$PACKAGE' removal is complete."
fi
done
# Done
echo_message success 'Removal of unused packages complete.'
whiptail --title "Finished" --msgbox "Your list of unwanted pre-installed applications have been removed." 8 64
cleanup
else
cleanup
fi
}
# Remove Orphaned Packages
function remove_orphans {
echo_message title "Starting 'remove_orphans' function..."
echo_message info 'Removing orphaned packages...'
# Admin privileges
elevate_privilege "apt autoremove -y $PACKAGE"
# Done
echo_message success 'Removal of orphaned packages complete.'
whiptail --title "Finished" --msgbox "Orphaned packages have been successfully removed." 8 64
cleanup
}
# Remove Leftover Config files
function remove_leftover_config {
echo_message title "Starting 'remove_leftover_config' function..."
echo_message info 'Removing leftover configuration files...'
# Admin privileges
elevate_privilege "dpkg --purge $(COLUMNS=200 dpkg -l | grep '^rc' | tr -s ' ' | cut -d ' ' -f 2)"
# Done
echo_message success 'Removal of leftover configuration files complete.'
whiptail --title "Finished" --msgbox "Leftover configuration files have been removed." 8 64
cleanup
}
# Clean apt cache
function clean_apt_cache {
echo_message title "Starting 'clean_apt_cache' function..."
echo_message info 'Cleaning package cache...'
# Admin privileges
elevate_privilege "apt clean"
# Done
echo_message success 'Package cache cleaned.'
whiptail --title "Finished" --msgbox "Package cache has been cleaned." 8 64
cleanup
}
# Remove old kernels
function clean_old_kernels {
if (whiptail --title "Remove Outdated Kernels" --yesno "If you're not currently using the newest kernel installed on your system, the following may break it. \n\nAre you sure you want proceed?" 10 60) then
echo_message title "Starting 'clean_old_kernels' function..."
echo_message info 'Removing outdated kernel(s)...'
# Admin privileges
elevate_privilege "dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | grep -v linux-libc-dev | xargs apt -y purge"
# Done
echo_message success 'Kernels cleaned.'
whiptail --title "Finished" --msgbox "Outdated kernels have been successfully removed." 8 78
cleanup
else
cleanup
fi
}
# Remove old log crash
function clean_old_crash {
echo_message title "Starting 'clean_apt_cache' function..."
echo_message info 'Cleaning old log crash...'
# Admin privileges
elevate_privilege "rm /var/crash/*"
# Done
echo_message success 'Old log crash cleaned.'
whiptail --title "Finished" --msgbox "Old log crash has been cleaned." 8 78
cleanup
}
# Cleanup System
function cleanup {
echo_message title "Starting 'cleanup' function..."
EXITSTATUS=$?
if [ $EXITSTATUS = 0 ]; then
# Draw window
$(eval `resize`&& whiptail \
--notags \
--title "System Cleanup" \
--menu "\nWhat would you like to do?" \
--cancel-button "Go Back" \
$LINES $COLUMNS $(( $LINES - 12 )) \
clean_apt_cache 'Clean package cache' \
remove_leftover_config 'Remove leftover configuration files' \
remove_orphans 'Remove orphaned packages' \
purge_unused 'Remove unused pre-installed packages' \
clean_old_crash 'Remove old log crash' \
clean_old_kernels 'Remove old kernel(s)' \
3>&1 1>&2 2>&3)
else
main
fi
}