-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_clr_kernel_rpm.sh
executable file
·149 lines (133 loc) · 4.01 KB
/
install_clr_kernel_rpm.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
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
RPM_NAME=$1
SCRIPT_PATH=$(pwd)
DATE=$(date +%Y-%m-%d_%H_%M)
INSTALL_LOG="/root/Install_kernel_record.log"
usage() {
cat <<__EOF
echo "no build.rpm:$build"
echo "usage: need give the rpm name in present path or absolute rpm path"
echo " or no parameter will search and install first matched rpm file"
__EOF
}
err_feedback() {
print_log "Please contact with [email protected] for this faiulre, thanks!"
exit 1
}
print_log() {
local log_info=$1
echo "$log_info"
echo "$DATE: $log_info" >> $INSTALL_LOG
}
install_kernel_rpm() {
local rpm_name=$1
local build=""
local result=""
local loader="/mnt/loader/loader.conf"
local swap_node=""
swap_node=$(cat /proc/swaps \
| grep dev \
| cut -d ' ' -f 1 \
| sed s'/.$//')
if [[ -n "$rpm_name" ]]; then
build=$rpm_name
else
build=$(ls -1 kernel-*rpm | head -n 1)
fi
[[ -e "$build" ]] || {
usage
exit 2
}
echo "build:$build"
print_log "install $build"
echo "rm -rf $SCRIPT_PATH/lib/modules"
rm -rf $SCRIPT_PATH/lib/modules
echo "rm -rf $SCRIPT_PATH/boot/System*"
rm -rf $SCRIPT_PATH/boot/System*
echo "rm -rf $SCRIPT_PATH/boot/vmlinu*"
rm -rf $SCRIPT_PATH/boot/vmlinu*
echo "rpm2cpio $build | cpio -idmv"
rpm2cpio $build | cpio -idmv
[[ $? -eq 0 ]] || {
echo "rpm2cpio failed, please: swupd bundle-add package-utils to try again"
print_log "rpm2cpio failed, please: swupd bundle-add package-utils to try again, failed"
exit 1
}
module=$(ls ${SCRIPT_PATH}/lib/modules/)
[[ -n "$module" ]] || {
echo "lib/modules is null:$module"
print_log "lib/modules is null:$module failed"
exit 1
}
# echo "rm -rf /usr/lib/modules/$module"
# rm -rf /usr/lib/modules/$module
sleep 1
echo "cp -rf ${SCRIPT_PATH}/lib/modules/$module /usr/lib/modules/"
cp -rf ${SCRIPT_PATH}/lib/modules/$module /usr/lib/modules/
sleep 1
echo "cd ${SCRIPT_PATH}/boot/"
cd ${SCRIPT_PATH}/boot/
vmlinuz=$(ls ${SCRIPT_PATH}/boot/vmlinuz*)
system=$(ls ${SCRIPT_PATH}/boot/System*)
config=$(ls ${SCRIPT_PATH}/boot/config*)
echo "installkernel $module $vmlinuz $system /boot"
installkernel $module $vmlinuz $system /boot
echo "cp -rf $config /lib/kernel/"
cp -rf $config /lib/kernel/
node=$(fdisk -l \
| grep -i EFI \
| cut -d ' ' -f 1)
[[ -n "$node" ]] || {
echo "could not find EFI node:$node!"
err_feedback
}
node_num=$(fdisk -l \
| grep -i EFI \
| cut -d ' ' -f 1 \
| wc -l)
[[ "$node_num" -gt 1 ]] && {
print_log "WARN:Found $node_num nodes:$node"
swap_node=$(cat /proc/swaps \
| grep dev \
| cut -d ' ' -f 1 \
| sed s'/.$//')
[[ -z "$swap_node" ]] && print_log "WARN:swap_node is null!"
print_log "swap_node:$swap_node"
node=$(echo "$node" | grep "$swap_node")
print_log "After auto check, boot EFI node:$node"
}
echo "umount -f /mnt"
umount -f /mnt 2>/dev/null
sleep 1
echo "mount $node /mnt"
mount "$node" /mnt
[[ -e "$loader" ]] || {
echo "no $loader file"
print_log "no $loader file, failed"
exit 1
}
default=$(cat $loader | grep default | head -n 1)
echo "$default"
[[ -n "$default" ]] || {
echo "no default in $loader, add it"
echo "sed -i 1idefault $module $loader"
sed -i "1idefault $module" $loader
echo "install $build with default successfully"
print_log "install $build with default successfully"
exit 0
}
print_log "install $build successfully"
echo "sed -i s/$default/default linux-$module/g $loader"
sed -i s/"$default"/"default linux-$module"/g $loader \
|| print_log "sed -i step return $?"
result=$(cat $loader | grep $module)
[[ -z "$result" ]] && {
print_log "Change $loader to linux-$module failed! Please change it manually!"
err_feedback
}
default=$(cat $loader | grep default | head -n 1)
echo "install $build successfully!"
print_log "$loader:$default"
echo "install record is located in $INSTALL_LOG"
}
install_kernel_rpm "$RPM_NAME"