-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean-boot
More file actions
executable file
·85 lines (66 loc) · 2.2 KB
/
clean-boot
File metadata and controls
executable file
·85 lines (66 loc) · 2.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
#!/bin/bash
# boot dir size in bytes: 463832
BOOT_SIZE=$(du -s /boot/ | cut -d "/" -f 1 | xargs)
# max dir size for boot dir
MAX_DIR_SIZE=450000
FILES=$(ls /boot/ | grep "\-generic")
echo "list of files:"
echo "$FILES"
echo ""
if [[ $BOOT_SIZE -lt $MAX_DIR_SIZE ]]; then
echo "size of /boot/ is less than $MAX_DIR_SIZE"
exit
fi
echo "size of /boot/ is $BOOT_SIZE out of $MAX_DIR_SIZE"
echo ""
OLDEST_VERSION=$(ls /boot/ | grep "\-generic" | sort | head -1 | cut -d "-" -f 2-3)
OLDEST_MAJOR_VERSION=$(echo "$OLDEST_VERSION" | cut -d "." -f 1)
OLDEST_MINOR_VERSION=$(echo "$OLDEST_VERSION" | cut -d "." -f 2)
OLDEST_PATCH_VERSION=$(echo "$OLDEST_VERSION" | cut -d "." -f 3 | cut -d "-" -f 1)
OLDEST_SUFFIX_VERSION=$(echo "$OLDEST_VERSION" | cut -d "-" -f 2)
for FILE in $FILES
do
VERSION=$(echo $FILE | cut -d "-" -f 2-3)
VERSION_SUFFIX=$(echo $VERSION | tr -d '.-')
MAJOR_VERSION=$(echo "$VERSION" | cut -d "." -f 1)
MINOR_VERSION=$(echo "$VERSION" | cut -d "." -f 2)
PATCH_VERSION=$(echo "$VERSION" | cut -d "." -f 3 | cut -d "-" -f 1)
SUFFIX_VERSION=$(echo "$VERSION" | cut -d "-" -f 2)
if [[ $MAJOR_VERSION -lt $OLDEST_MAJOR_VERSION ]]; then
OLDEST_MAJOR_VERSION="$MAJOR_VERSION"
if [[ $MINOR_VERSION -lt $OLDEST_MINOR_VERSION ]]; then
OLDEST_MINOR_VERSION="$MINOR_VERSION"
if [[ $PATCH_VERSION -lt $OLDEST_PATCH_VERSION ]]; then
OLDEST_PATCH_VERSION="$PATCH_VERSION"
if [[ $SUFFIX_VERSION -lt $OLDEST_SUFFIX_VERSION ]]; then
OLDEST_SUFFIX_VERSION="$SUFFIX_VERSION"
fi
fi
fi
fi
done
OLDEST_VERSION="$OLDEST_MAJOR_VERSION.$OLDEST_MINOR_VERSION.$OLDEST_PATCH_VERSION-$OLDEST_SUFFIX_VERSION"
LIST_OF_FILES_TO_CLEAN=$(ls /boot/ | grep "$OLDEST_VERSION")
echo ""
echo "list of files to remove:"
echo ""
for FILE in $LIST_OF_FILES_TO_CLEAN
do
echo "/boot/$FILE"
done
echo ""
read -n 1 -p "To confirm insert (y/N): " CONFIRM
CONFIRM=${CONFIRM:-n}
echo ""
if [[ $CONFIRM =~ ^[Yy]$ ]]; then
for FILE in $LIST_OF_FILES_TO_CLEAN
do
rm /boot/$FILE
done
fi
BOOT_SIZE=$(du -s /boot/ | cut -d "/" -f 1 | xargs)
echo "new size of /boot/ is $BOOT_SIZE out of $MAX_DIR_SIZE"
FILES=$(ls /boot/ | grep "\-generic")
echo "list of files:"
echo "$FILES"
echo ""