forked from muhasturk/ukupgrade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathukupgrade
executable file
·164 lines (131 loc) · 3.89 KB
/
ukupgrade
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
#!/bin/bash
# @author Mustafa Hasturk
# @mail [email protected]
# @author Caio Oliveira
# @mail [email protected]
# @author Christoph Kepler
# @mail [email protected]
# @author Usb Key
# @mail [email protected]
help="Usage: ukupgrade [OPTION]...
Dowload and install last available kernel for ubuntu systems.
Settings can be saved if no options provided or by running setup script
-r, Get Release Candidate kernel (default: Stable kernel)
-l, Get Low Latency kernel (default: Generic kernel)
-a, Run ukpurge script after upgrade
-h, Show this help
-simple, Use default settings (stable, generic, no purge)
Examples:
ukupgrade -simple Download, install the last kernel using defaults settings
ukupgrade -a Same behavior of previous but uninstall old kernels
"
#Follow symlink and cd to right directory
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
cd "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
if ! which lynx > /dev/null; then sudo apt-get install lynx -y; fi
arch=$(dpkg --print-architecture)
function download() {
wget -q --show-progress -P /tmp $(lynx -dump -listonly -dont-wrap-pre $kernelURL | grep "$1" | grep "$2" | grep "$arch" | cut -d ' ' -f 4 | tail -1)
if [ $? == "1" ]; then
echo "Download failed!"
exit 1
fi
}
function cleanup() {
sudo rm -rf /tmp/linux*.deb
}
if [ "$1" = "-simple" ]; then
source ./sample.uku.cfg ;
else
if [ $# -eq 0 ]; then
if [ ! -f ./uku.cfg ]; then ./setup ; fi
source ./uku.cfg ;
else
source ./sample.uku.cfg ;
while getopts 'rlph' flag; do
case "${flag}" in
r) kernelrc=1 ;;
l) kernelmode='lowlatency' ;;
p) arm=1 ;;
h) echo "${help}";
exit;
;;
*) echo "Unexpected option ${flag}";
echo "${help}";
exit;
;;
esac
done
fi ;
fi
case "$kernelrc" in
1) kernelURL=$(lynx -dump -nonumbers http://kernel.ubuntu.com/~kernel-ppa/mainline/ | tail -1) ;;
*) kernelURL="http://kernel.ubuntu.com/~kernel-ppa/mainline/"$(lynx -dump -nonumbers http://kernel.ubuntu.com/~kernel-ppa/mainline/ | grep -v rc | rev | cut -d '/' -f 2 | rev | grep -E 'v.+' | sort -V | rev | cut -d ' ' -f 1 | rev | tail -1)"/" ;;
esac
# Same version test
reqVersion=$(echo $kernelURL | awk -F "/v" '{print $2}' | cut -d '/' -f 1)
locVersion=$(dpkg -l | grep linux-image | grep $kernelmode | awk '{print $3}' | sed -e 's/.0-.*rc/.rc/' | cut -d '-' -f 1 | sed -e 's/.rc/-rc/')
if echo "$locVersion" | grep -Fxq "$reqVersion"; then
echo 'Kernel up to date. Finishing'
exit
fi
# Cleaning up tmp dir
cat << EOF
Cleaning old downloads in /tmp
EOF
cleanup
# Download Kernel Modules
cat << EOF
Downloading the latest $kernelmode kernel module...
EOF
download $kernelmode module
# Download Kernel Image
cat << EOF
Downloading the latest $kernelmode kernel image...
EOF
download $kernelmode image
# Download Kernel Header
cat << EOF
Downloading the latest $kernelmode kernel header...
EOF
download $kernelmode header
# Download Shared Kernel Header
cat << EOF
Downloading the shared kernel header...
EOF
wget -q --show-progress -P /tmp $(lynx -dump -listonly -dont-wrap-pre $kernelURL | grep all | grep headers | cut -d ' ' -f 4 | tail -1)
if [ $? == '1' ]; then
echo 'Download failed!'
exit 1
fi
# Install Kernel
cat << EOF
Installing Kernel and Headers...
EOF
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
sleep 0.5
done
sudo dpkg -i /tmp/linux-modules*.deb
sudo dpkg -i /tmp/linux-header*.deb
sudo dpkg -i /tmp/linux-image*.deb
cleanup
touch /tmp/ukupgrade.nr
cat << EOF
Finished.
EOF
if [ $arm -eq 1 ]; then ./ukpurge ; fi
if [ $cron = 0 ]; then
read -p 'Do you want to reboot system now? (y/n)(10s to No): ' -n 1 -t 10 -s rs
case "$rs" in
y | Y)
echo "Yes, reboot this now!"
sleep 2
sudo reboot ;;
*) echo 'No, stay this wake uped!' ;;
esac ;
fi