forked from Utappia/uCareSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ucaresystem-core
326 lines (288 loc) · 9.79 KB
/
ucaresystem-core
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#! /bin/bash
set -e
#
#
#_______________________________________________
#THIS IS THE Terminal Version of uCareSystem
#_______________________________________________
# Name : uCareSystem Core
# Licence: GPL3 (http://www.gnu.org/licenses/gpl.html)
# Author : Salih Emin
# WebSite: http://utappia.org
# Email : salih-(at)-utappia.org
# Date : 05-03-2020 (first release 19-02-2009)
# Version: 20.03.0
# System : Ubuntu Linux and derivatives. Partial support for Debian
# Description:
#This simple script will automatically refresh your package list, download and install
#updates (if there are any),
#remove any remaining packages and configuration files without interference.
#
## Script starts here
#Variables
DIST_CODENAME=$(lsb_release --codename | cut -f2)
DATE=(date +%F_%T)
UCARE_VERSION=(20.03.0)
# Checking if the user has run the script with "sudo" or not
if [[ $EUID -ne 0 ]] ; then
clear
echo ""
echo "uCareSystem Core must be run as root or with sudo. Now I will just exit..." 1>&2
echo ""
sleep 2
exit 1
fi
function WELCOME_SCREEN {
echo "_______________________________________________________"
echo " "
echo " uCareSystem Core $UCARE_VERSION "
echo " ~~~~~~~~~~~~~~~~~~~~~ "
echo " "
echo " Welcome to all-in-one System Update and maintenance "
echo " assistant app. "
echo " "
echo " "
echo " This simple script will automatically "
echo " refresh your packagelist, download and "
echo " install updates (if there are any), remove any old "
echo " kernels, obsolete packages and configuration files "
echo " to free up disk space, without any need of user "
echo " interference "
echo " "
echo " If you’ve found it useful and saved you time and you "
echo " think it is worth of your support, you can make a "
echo " donation via PayPal by clicking on the following: "
echo " "
echo " https://www.paypal.me/cerebrux "
echo "_______________________________________________________"
echo
echo " uCareSystem Core will start in 5 seconds... "
sleep 6
}
function MAINTENACE {
echo
echo
echo "#########################"
echo " Started"
echo "#########################"
echo
## Updates package lists
sudo apt update;
echo
echo "###############################"
echo "Finished updating package lists"
echo "###############################"
sleep 1
## Updates packages and libraries
sudo apt full-upgrade -y;
echo
echo "###############################################"
echo "Finished updating packages and system libraries"
echo "###############################################"
sleep 1
echo
## Removes unneeded packages
sudo apt-get -y --purge autoremove; # Debian Jessie uses old apt. So
echo # for the time being I use old implementation
echo "###################################"
echo "Finished removing unneeded packages"
echo "###################################"
sleep 1
echo
# purge-old-kernels - remove old kernel packages
# Copyright (C) 2012 Dustin Kirkland <kirkland -(at)- ubuntu.com>
#
# Authors: Dustin Kirkland <kirkland-(at)-ubuntu.com>
# Kees Cook <kees-(at)-ubuntu.com>
#
# NOTE: This script will ALWAYS keep the currently running kernel
# NOTE: Default is to keep 2 more, user overrides with --keep N
KEEP=2
# NOTE: Any unrecognized option will be passed straight through to apt
APT_OPTS=
while [ ! -z "$1" ]; do
case "$1" in
--keep)
# User specified the number of kernels to keep
KEEP="$2"
shift 2
;;
*)
APT_OPTS="$APT_OPTS $1"
shift 1
;;
esac
done
# Build our list of kernel packages to purge
CANDIDATES=$(ls -tr /boot/vmlinuz-* | head -n -${KEEP} | grep -v "$(uname -r)$" | cut -d- -f2- | awk '{print "linux-image-" $0 " linux-headers-" $0}' )
for c in $CANDIDATES; do
dpkg-query -s "$c" >/dev/null 2>&1 && PURGE="$PURGE $c"
done
if [ -z "$PURGE" ]; then
echo "No kernels are eligible for removal"
fi
sudo apt $APT_OPTS remove -y --purge $PURGE;
echo
echo "###################################"
echo "Finished removing old kernels"
echo "###################################"
sleep 1
echo
## Removes unused config files
sudo deborphan -n --find-config | xargs sudo apt-get -y --purge autoremove;
echo
echo "#####################################"
echo "Finished removing unused config files"
echo "#####################################"
sleep 1
echo
## Removes package files that can no longer be downloaded and everything except
# the lock file in /var/cache/apt/archives, including directories.
sudo apt-get -y autoclean; sudo apt-get -y clean;
echo
echo "######################################"
echo " Cleaned downloaded temporary packages"
echo "######################################"
echo
sleep 1
echo
echo "#########################################"
echo " Checking to see if a reboot is required "
echo "#########################################"
echo
## Check to see if a reboot is required
if [ -f /var/run/reboot-required ]; then
echo
echo "* * * * * * * * * * * * * * * * * *"
echo "* *"
echo "* Consider rebooting your system *"
echo "* to finish applying updates *"
echo "* *"
echo "* * * * * * * * * * * * * * * * * *"
echo
fi
}
function UPGRADE_EOL_TO_NEXT {
cp "/etc/apt/sources.list" "/etc/apt/sources.eol_${DATE}"
cat <<EOT > /etc/apt/sources.list
deb http://old-releases.ubuntu.com/ubuntu/ $DIST_CODENAME main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ $DIST_CODENAME-updates main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ $DIST_CODENAME-security main restricted universe multiverse
EOT
sudo apt-get install update-manager-core
sudo apt-get -y dist-upgrade
sudo do-release-upgrade
}
function UPGRADE_TO_NEXT_RELEASE {
sleep 1
echo "##########################################"
echo "uCareSystem will now check for the "
echo "availabillity of the next version "
echo "and it will start the upgrade "
echo "##########################################"
echo ""
sleep 1
do-release-upgrade
sleep 2
}
function UPGRADE_TO_DEVEL_RELEASE {
sleep 1
echo "##########################################"
echo "uCareSystem will now check for the "
echo "availabillity of the next development "
echo "version and it will start the upgrade "
echo "##########################################"
echo ""
sleep 1
do-release-upgrade -d
sleep 2
}
function SHOW_HELP {
cat << EOF
uCareSystem Core
~ $UCARE_VERSION ~
All-in-one system update and maintenance app
Usage: sudo ucaresystem-core <parameter>
If no parameter is specified, it will just do the regular
maintenance:
* Updates the list of available packages
* Downloads and installs the available updates
* Checks if there are older Linux kernels on the system and removes
them. However it keeps the current and one previous version of
the kernel.
* Cleans the cache of the downloaded packages
* Removes obsolete packages
* Removes orphan packets
* Deletes package configuration files from packages that have been
uninstalled by you.
Parameter:
-h display this help and exit
-u Upgrade to the next release. Note: If you use a
regular release it will upgrade to the next one. If
you are on a LTS version, it will upgrade only to
the next LTS.
-d Upgrade to the next development release
-eol CAUTION: Do not use this if your Ubuntu has not
reached its End of life support.
Check https://wiki.ubuntu.com/Releases
This option is for Ubuntu releases that have
reached their EOL and the user wants to upgrade
it to the next supported version.
-r After completing all the tasks, reboot the system
-s After completing all the tasks, shutdown the system
EOF
}
function GOODBYE {
sleep 2
echo
echo
echo "#########################"
echo " All Done... GOODBYE"
echo "#########################"
}
function SHUT_DOWN {
sleep 1
echo
echo
echo "#########################"
echo " Shutting down"
echo "#########################"
sudo shutdown now
}
function RE_BOOT {
sleep 1
echo
echo
echo "#########################"
echo " Rebooting"
echo "#########################"
sudo reboot
## End of script
}
# The main process starts
while [ "$1" != "" ]; do
case $1 in
-u | --upgrade ) WELCOME_SCREEN && MAINTENACE && UPGRADE_TO_NEXT_RELEASE
exit
;;
-d | --development ) WELCOME_SCREEN && MAINTENACE && UPGRADE_TO_DEVEL_RELEASE
exit
;;
-h | --help ) SHOW_HELP
exit
;;
-eol | --end-of-life-upgrade ) UPGRADE_EOL_TO_NEXT
exit
;;
-s | --shutdown ) WELCOME_SCREEN && MAINTENACE && GOODBYE && SHUT_DOWN
exit
;;
-r | --reboot ) WELCOME_SCREEN && MAINTENACE && GOODBYE && RE_BOOT
exit
;;
* ) SHOW_HELP
exit 1
esac
done
## If no parameter is given just do the regular maintenance
WELCOME_SCREEN && MAINTENACE && GOODBYE