-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel_update.sh
136 lines (125 loc) · 2.87 KB
/
kernel_update.sh
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
########################################
# filename: kernel_update.sh
# description: auto update kernel
#
# Author: Ral
# modified time:2018/01/19
########################################
#set -x
#kernel version and bug cause
allow_version='2.6.32-431.el6.x86_64'
netns=`ps aux | grep netns | grep -v grep`
kernel_conf="/root/update/grub.conf"
# exit the whole script
export TOP_PID=$$
trap 'exit 1' TERM
exit_script()
{
echo "EXIT ..."
kill -s TERM $TOP_PID
echo "Usage: `basename ${0}` filename"
}
# find kernel index for modify configure file
get_index()
{
if [[ -f $1 ]]; then
cat $1 | grep title | grep -n title | grep update | awk -F ":" '{ print $1 }'
else
echo "$1 not exist!!!"
exit_script
fi
}
# modify the kernel configure file
modify_index()
{
if [[ -f $1 ]]; then
sed -i -e "0,/default=([0-9]+)/s/default=([0-9]+)/default=$2/" $1
else
echo "$1 not exist!"
exit_script
fi
}
# decompress patch file
decompress()
{
local patch_file=""
for patch_file in $*
do
if [[ -f ${patch_file} ]]; then
# delete suffix
local patch_dir=${patch_file%.*}
# delete .tar suffix
patch_dir=${patch_dir/%.tar/}
if [[ -d ${patch_dir} ]]; then
echo "${patch_dir} existed, delete it ..."
rm -rf ${patch_dir}
fi
local file_type=${patch_file##*.}
case $file_type in
bz2 | gz)
echo "Using tar to decompress..."
tar -xvf ${patch_file}
echo "decompress finished!"
;;
zip)
echo "Using unzip to decompress..."
unzip ${patch_file}
echo "decompress finished!"
;;
*)
echo "Unknow filetype, exit..."
exit_script
;;
esac
fi
done
}
#install rpm package
rpm_install()
{
local rpm_zip=""
for rpm_zip in $*
do
# delete suffix
local rpm_dir=${rpm_zip%.*}
# delete .tar suffix
rpm_dir=${rpm_dir/%.tar/}
if [[ -d ${rpm_dir} ]]; then
cd ${rpm_dir}
rpm -ivh --force *.rpm
if [[ ${?} -ne 0 ]]; then
echo "rpm install FAILED, please check your files and try to UPDATE again!!!"
exit_script
fi
else
echo "maybe decompress failed..."
exit_script
fi
done
echo "rpm install successfully"
}
if [[ "$#" -eq "0" ]]; then
echo "no input parameter, please specify patch file name!"
exit_script
else
kernel_version=`uname -r`
if [[ ${kernel_version}x != ${allow_version}x ]]; then
echo "local kernel_version is ${kernel_version}, update forbid!"
exit_script
fi
if [[ ${netns}x == x ]]; then
echo "this kernel do NOT need update!"
exit_script
fi
echo "decompressing compressed file..."
decompress $*
echo "installing rpm package file..."
rpm_install $*
echo "processing kernel config file..."
echo "kernel config file is ${kernel_conf}"
index=`get_index ${kernel_conf}`
((index=${index}-1))
modify_index ${kernel_conf} ${index}
echo "update successfully, please REBOOT your system to enable this update!!!"
fi