This repository was archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsystem_cleanup
More file actions
executable file
·136 lines (131 loc) · 4.2 KB
/
Copy pathsystem_cleanup
File metadata and controls
executable file
·136 lines (131 loc) · 4.2 KB
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
131
132
133
134
135
136
#!/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 pre-installed apps
function purge_unused_packages {
NAME="Unused Pre-installed Applications"
echo_message title "Removing ${NAME,,}..."
# Check list
LIST=$(dirname "$0")'/data/purge.list'
# Draw window
if (eval `resize` && whiptail \
--title "Remove $NAME" \
--yesno "Current list of ${NAME,,} to remove: \n\n$(cat $LIST) \n\nAre you sure you want proceed?" \
$LINES $COLUMNS $(( $LINES - 12 )) \
--scrolltext ) then
# Remove loop
for PACKAGE in $(cat $LIST); do
# Check if package is installed
if [ $(check_package_installed ${PACKAGE};) = 1 ]; then
# Show already removed message
echo_message info "Package '$PACKAGE' already removed."
else
# Remove package
echo_message info "'$PACKAGE' is installed. Removing..."
# Admin privileges
superuser_do "dnf remove -y $PACKAGE"
# Finished
echo_message success "'$PACKAGE' removal is complete."
fi
done
# Finished
echo_message success "Removal of ${NAME,,} complete."
whiptail --title "Finished" --msgbox "Unwanted ${NAME,,} have been removed." 8 56
system_cleanup
else
# Cancelled
echo_message success "Removal of ${NAME,,} cancelled."
system_cleanup
fi
}
# Remove Orphaned Packages
function remove_orphans {
NAME="Orphaned Packages"
echo_message title "Removing ${NAME,,}..."
# Check if there are orphaned packages
if [[ $(echo $(dnf list -q --autoremove | wc -l )) -gt 0 ]]; then
# Draw window
if (eval `resize` && whiptail \
--title "$NAME" \
--yesno "Current list of ${NAME,,} to remove: \n\n$(dnf list -q --autoremove) \n\nAre you sure you want proceed?" \
$LINES $COLUMNS $(( $LINES - 12 )) \
--scrolltext ) then
# Admin privileges
superuser_do "dnf autoremove -y"
# Finished
echo_message success "Removal of ${NAME,,} has been successful."
whiptail --title "Finished" --msgbox "Removal of ${NAME,,} has been successful." 8 56
system_cleanup
else
# Cancelled
echo_message success "Removal of ${NAME,,} cancelled."
system_cleanup
fi
else
# If there are no orphaned packages
echo_message info "No ${NAME,,} are present on this system."
whiptail --title "Finished" --msgbox "No ${NAME,,} are present on this system." 8 56
system_cleanup
fi
}
# Clean Cache
function clean_dnf_cache {
echo_message title "Cleaning package cache..."
# Admin privileges
superuser_do "dnf clean packages"
# Finished
echo_message success "Package cache has been cleaned.."
whiptail --title "Finished" --msgbox "Package cache has been cleaned." 8 56
system_cleanup
}
# Clean systemd journal
function clean_systemd_journal {
NAME="systemd Journal Archives"
# Remove logs older than the following (d = days)
TIMEFRAME="7d"
echo_message title "Removing ${NAME,,}..."
# Draw window
if (eval `resize` && whiptail \
--title "$NAME" \
--yesno "Current size of ${NAME} is: \n\n$(du -sh /var/log/journal) \n\nClear archives older than: ${TIMEFRAME}?" \
$LINES $COLUMNS $(( $LINES - 12 )) \
--scrolltext ) then
# Admin privileges
superuser_do "journalctl --vacuum-time=${TIMEFRAME}"
# Finished
echo_message success "Removal of old ${NAME,,} has been successful."
whiptail --title "Finished" --msgbox "Removal of old ${NAME,,} has been successful." 8 56
system_cleanup
else
# Cancelled
echo_message success "Removal of old ${NAME,,} cancelled."
system_cleanup
fi
}
# Cleanup System
function system_cleanup {
NAME="System Cleanup"
echo_message title "Starting ${NAME,,}..."
# Draw window
CLEANUP=$(eval `resize` && whiptail \
--notags \
--title "$NAME" \
--menu "\nWhat would you like to do?" \
--cancel-button "Go Back" \
$LINES $COLUMNS $(( $LINES - 12 )) \
clean_dnf_cache 'Clean package cache' \
remove_orphans 'Remove orphaned packages' \
purge_unused_packages 'Remove unused pre-installed packages' \
clean_systemd_journal 'Clean systemd journal archives' \
3>&1 1>&2 2>&3)
# check exit status
if [ $? = 0 ]; then
echo_message header "Starting '$CLEANUP' function"
$CLEANUP
else
# Cancelled
echo_message info "$NAME cancelled."
main
fi
}