-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslapt.sh
More file actions
100 lines (90 loc) · 2.87 KB
/
Copy pathslapt.sh
File metadata and controls
100 lines (90 loc) · 2.87 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
#!/bin/bash
##
## /usr/local/script/slapt.sh
## Check and update software packages
##
## Created on 24 AUG 2014
## Version 1.1 dated 10 JUL 2015
## - added trim for the root filesystem on a solid state drive
## VErsion 1.2 dated 02 SEP 2017
## - replaced 'apt-get' with 'apt' where possible
##
# Set variables and default values
set -u
ERRORCODE=0 # We assume no errors will occur...
# Define functions
function checktocontinue() {
# Ask to continue
read -p "Continue (y/n)? " -n 1 -r
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
printf "\n"
else
printf "\nYou choose not to continue. Exiting.\n"
exit ${ERRORCODE}
fi
}
# Check if this script is run as root, otherwise exit.
if [[ $(whoami) != root ]]; then
printf "Must be root to execute this script. Exiting.\n"
exit 1
fi
# Step 1: update
printf "==== STEP 1. Update: resynchronizing the package index files from their sources
specified in /etc/apt/sources.list; this may take a few moments...\n"
apt-get update -qq; ERRORCODE=$?
if [[ ${ERRORCODE} != 0 ]]; then
printf " ** Error occured while updating package index files. "
checktocontinue
else
printf " == Done updating package index files.\n"
fi
# Step 2: autoclean
printf "==== STEP 2. Autoclean: clearing out the local repository of old package files
that can no longer be downloaded.\n"
apt-get autoclean; ERRORCODE=$?
if [[ ${ERRORCODE} != 0 ]]; then
printf " ** Error occured while autocleaning old packages from the local repository. "
checktocontinue
else
printf " == Done autocleaning old packages from the local repository.\n"
fi
# Step 3: Clean
printf "==== STEP 3. Clean: clearing out the local repository and cache.\n"
apt-get clean; ERRORCODE=$?
if [[ ${ERRORCODE} != 0 ]]; then
printf " ** Error occured while cleaning the local repository. "
checktocontinue
else
printf " == Done cleaning the local repository.\n"
fi
# Step 4: Upgrade
printf "==== STEP 4. Upgrade: installing the newest versions of all packages currently installed
on the system from the sources in /etc/apt/sources.list.\n"
apt upgrade; ERRORCODE=$?
if [[ ${ERRORCODE} != 0 ]]; then
printf " ** Error occured while upgrading software packages."
checktocontinue
else
printf " == Done upgrading installed software pacakges.\n"
fi
sync
# Step 5: Autoremove
printf "==== STEP 5. Autoremove: removing packages that were automatically installed to satisfy
dependencies for other packages and that are now no longer needed.\n"
apt-get autoremove; ERRORCODE=$?
if [[ ${ERRORCODE} != 0 ]]; then
printf " ** Error occured while removing unused packages without dependencies. "
checktocontinue
else
printf " == Done removing unused software pacakges.\n"
fi
# Step 6: Trim filesystem
printf "==== STEP 6. Filesystem TRIM for Solid State Drives.\n "
sync
ROOTDEVICE=$(findmnt -n -o SOURCE /)
if [[ ! -z $(hdparm -I $ROOTDEVICE | grep "TRIM supported") ]]; then
fstrim -v /
fi
# End of script
printf "All done. Exiting.\n"
exit 0