forked from Lenyu2020/Actions-OpenWrt-x86
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diy-part1.sh
executable file
·343 lines (331 loc) · 13.8 KB
/
diy-part1.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/bash
#
# Copyright (c) 2019-2020 P3TERX <https://p3terx.com>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
# https://github.com/P3TERX/Actions-OpenWrt
# File name: diy-part1.sh
# Description: OpenWrt DIY script part 1 (Before Update feeds)
#
# Uncomment a feed source
# Add a feed source
sed -i "/helloworld/d" "feeds.conf.default"
echo "src-git helloworld https://github.com/fw876/helloworld.git;main" >> "feeds.conf.default"
echo "src-git passwall_packages https://github.com/xiaorouji/openwrt-passwall-packages.git;main" >> "feeds.conf.default"
echo "src-git passwall https://github.com/xiaorouji/openwrt-passwall.git;main" >> "feeds.conf.default"
mkdir -p files/usr/share
mkdir -p files/etc/
touch files/etc/lenyu_version
mkdir wget
touch wget/DISTRIB_REVISION1
touch wget/DISTRIB_REVISION3
touch files/usr/share/Check_Update.sh
touch files/usr/share/Lenyu-auto.sh
cat>rename.sh<<-\EOF
#!/bin/bash
rm -rf bin/targets/x86/64/config.buildinfo
rm -rf bin/targets/x86/64/feeds.buildinfo
rm -rf bin/targets/x86/64/openwrt-x86-64-generic-kernel.bin
rm -rf bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined-efi.vmdk
rm -rf bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.vmdk
rm -rf bin/targets/x86/64/openwrt-x86-64-generic-squashfs-rootfs.img.gz
rm -rf bin/targets/x86/64/openwrt-x86-64-generic.manifest
rm -rf bin/targets/x86/64/sha256sums
rm -rf bin/targets/x86/64/version.buildinfo
sleep 2
rename_version=`cat files/etc/lenyu_version`
str1=`grep "KERNEL_PATCHVER:=" target/linux/x86/Makefile | cut -d = -f 2` #判断当前默认内核版本号如5.10
ver414=`grep "LINUX_VERSION-4.14 =" include/kernel-4.14 | cut -d . -f 3`
ver419=`grep "LINUX_VERSION-4.19 =" include/kernel-4.19 | cut -d . -f 3`
ver54=`grep "LINUX_VERSION-5.4 =" include/kernel-5.4 | cut -d . -f 3`
ver510=`grep "LINUX_VERSION-5.10 =" include/kernel-5.10 | cut -d . -f 3`
ver515=`grep "LINUX_VERSION-5.15 =" include/kernel-5.15 | cut -d . -f 3`
ver61=`grep "LINUX_VERSION-6.1 =" include/kernel-6.1 | cut -d . -f 3`
if [ "$str1" = "5.4" ];then
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver54}_dev_Lenyu.img.gz
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined-efi.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver54}_uefi-gpt_dev_Lenyu.img.gz
elif [ "$str1" = "4.19" ];then
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver419}_dev_Lenyu.img.gz
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined-efi.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver419}_uefi-gpt_dev_Lenyu.img.gz
elif [ "$str1" = "4.14" ];then
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver414}_dev_Lenyu.img.gz
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined-efi.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver414}_uefi-gpt_dev_Lenyu.img.gz
elif [ "$str1" = "5.10" ];then
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver510}_dev_Lenyu.img.gz
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined-efi.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver510}_uefi-gpt_dev_Lenyu.img.gz
elif [ "$str1" = "5.15" ];then
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver515}_dev_Lenyu.img.gz
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined-efi.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver515}_uefi-gpt_dev_Lenyu.img.gz
elif [ "$str1" = "6.1" ];then
if [ ! $ver61 ]; then
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver61}0_dev_Lenyu.img.gz
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined-efi.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver61}0_uefi-gpt_dev_Lenyu.img.gz
else
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver61}_dev_Lenyu.img.gz
mv bin/targets/x86/64/openwrt-x86-64-generic-squashfs-combined-efi.img.gz bin/targets/x86/64/openwrt_x86-64-${rename_version}_${str1}.${ver61}_uefi-gpt_dev_Lenyu.img.gz
fi
fi
ls bin/targets/x86/64 | grep "gpt_dev_Lenyu.img" | cut -d - -f 3 | cut -d _ -f 1-2 > wget/op_version1
#md5
ls -l "bin/targets/x86/64" | awk -F " " '{print $9}' > wget/open_dev_md5
dev_version=`grep "_uefi-gpt_dev_Lenyu.img.gz" wget/open_dev_md5 | cut -d - -f 3 | cut -d _ -f 1-2`
openwrt_dev=openwrt_x86-64-${dev_version}_dev_Lenyu.img.gz
openwrt_dev_uefi=openwrt_x86-64-${dev_version}_uefi-gpt_dev_Lenyu.img.gz
cd bin/targets/x86/64
md5sum $openwrt_dev > openwrt_dev.md5
md5sum $openwrt_dev_uefi > openwrt_dev_uefi.md5
exit 0
EOF
cat>lenyu.sh<<-\EOOF
#!/bin/bash
lenyu_version="`date '+%y%m%d%H%M'`_dev_Len yu"
echo $lenyu_version > wget/DISTRIB_REVISION1
echo $lenyu_version | cut -d _ -f 1 > files/etc/lenyu_version
#######
new_DISTRIB_REVISION=`cat wget/DISTRIB_REVISION1`
grep "DISTRIB_REVISION=" package/lean/default-settings/files/zzz-default-settings | cut -d \' -f 2 > wget/DISTRIB_REVISION3
old_DISTRIB_REVISION=`cat wget/DISTRIB_REVISION3`
sed -i "s/${old_DISTRIB_REVISION}/${new_DISTRIB_REVISION}/" package/lean/default-settings/files/zzz-default-settings
#
grep "Check_Update.sh" package/lean/default-settings/files/zzz-default-settings
if [ $? != 0 ]; then
sed -i 's/exit 0/ /' package/lean/default-settings/files/zzz-default-settings
cat>> package/lean/default-settings/files/zzz-default-settings<<-EOF
sed -i '$ a alias lenyu="sh /usr/share/Check_Update.sh"' /etc/profile
chmod 755 /etc/init.d/romupdate
exit 0
EOF
fi
grep "Lenyu-auto.sh" package/lean/default-settings/files/zzz-default-settings
if [ $? != 0 ]; then
sed -i 's/exit 0/ /' package/lean/default-settings/files/zzz-default-settings
cat>> package/lean/default-settings/files/zzz-default-settings<<-EOF
sed -i '$ a alias lenyu-auto="sh /usr/share/Lenyu-auto.sh"' /etc/profile
chmod 755 /etc/init.d/romupdate
exit 0
EOF
fi
EOOF
cat>files/usr/share/Check_Update.sh<<-\EOF
#!/bin/bash
# https://github.com/Lenyu2020/Actions-OpenWrt-x86
# Actions-OpenWrt-x86 By Lenyu 20210505
#path=$(dirname $(readlink -f $0))
# cd ${path}
#检测准备
if [ ! -f "/etc/lenyu_version" ]; then
echo
echo -e "\033[31m 该脚本在非Lenyu固件上运行,为避免不必要的麻烦,准备退出… \033[0m"
echo
exit 0
fi
rm -f /tmp/cloud_version
# 获取固件云端版本号、内核版本号信息
current_version=`cat /etc/lenyu_version`
wget -qO- -t1 -T2 "https://api.github.com/repos/Lenyu2020/Actions-OpenWrt-x86/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g;s/v//g' > /tmp/cloud_ts_version
if [ -s "/tmp/cloud_ts_version" ]; then
cloud_version=`cat /tmp/cloud_ts_version | cut -d _ -f 1`
cloud_kernel=`cat /tmp/cloud_ts_version | cut -d _ -f 2`
#固件下载地址
new_version=`cat /tmp/cloud_ts_version`
DEV_URL=https://github.com/Lenyu2020/Actions-OpenWrt-x86/releases/download/${new_version}/openwrt_x86-64-${new_version}_dev_Lenyu.img.gz
DEV_UEFI_URL=https://github.com/Lenyu2020/Actions-OpenWrt-x86/releases/download/${new_version}/openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img.gz
openwrt_dev=https://github.com/Lenyu2020/Actions-OpenWrt-x86/releases/download/${new_version}/openwrt_dev.md5
openwrt_dev_uefi=https://github.com/Lenyu2020/Actions-OpenWrt-x86/releases/download/${new_version}/openwrt_dev_uefi.md5
else
echo "请检测网络或重试!"
exit 1
fi
####
Firmware_Type="$(grep 'DISTRIB_ARCH=' /etc/openwrt_release | cut -d \' -f 2)"
echo $Firmware_Type > /etc/lenyu_firmware_type
echo
if [[ "$cloud_kernel" =~ "4.19" ]]; then
echo
echo -e "\033[31m 该脚本在Lenyu固件Sta版本上运行,目前只建议在Dev版本上运行,准备退出… \033[0m"
echo
exit 0
fi
#md5值验证,固件类型判断
if [ ! -d /sys/firmware/efi ];then
if [ "$current_version" != "$cloud_version" ];then
wget -P /tmp "$DEV_URL" -O /tmp/openwrt_x86-64-${new_version}_dev_Lenyu.img.gz
wget -P /tmp "$openwrt_dev" -O /tmp/openwrt_dev.md5
cd /tmp && md5sum -c openwrt_dev.md5
if [ $? != 0 ]; then
echo "您下载文件失败,请检查网络重试…"
sleep 4
exit
fi
Boot_type=logic
else
echo -e "\033[32m 本地已经是最新版本,还更个鸡巴毛啊… \033[0m"
echo
exit
fi
else
if [ "$current_version" != "$cloud_version" ];then
wget -P /tmp "$DEV_UEFI_URL" -O /tmp/openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img.gz
wget -P /tmp "$openwrt_dev_uefi" -O /tmp/openwrt_dev_uefi.md5
cd /tmp && md5sum -c openwrt_dev_uefi.md5
if [ $? != 0 ]; then
echo "您下载文件失败,请检查网络重试…"
sleep 4
exit
fi
Boot_type=efi
else
echo -e "\033[32m 本地已经是最新版本,还更个鸡巴毛啊… \033[0m"
echo
exit
fi
fi
open_up()
{
echo
clear
read -n 1 -p " 您是否要保留配置升级,保留选择Y,否则选N:" num1
echo
case $num1 in
Y|y)
echo
echo -e "\033[32m >>>正在准备保留配置升级,请稍后,等待系统重启…-> \033[0m"
echo
sleep 3
if [ ! -d /sys/firmware/efi ];then
gzip -d openwrt_x86-64-${new_version}_dev_Lenyu.img.gz
sysupgrade /tmp/openwrt_x86-64-${new_version}_dev_Lenyu.img
else
gzip -d openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img.gz
sysupgrade /tmp/openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img
fi
;;
n|N)
echo
echo -e "\033[32m >>>正在准备不保留配置升级,请稍后,等待系统重启…-> \033[0m"
echo
sleep 3
if [ ! -d /sys/firmware/efi ];then
gzip -d openwrt_x86-64-${new_version}_dev_Lenyu.img.gz
sysupgrade -n /tmp/openwrt_x86-64-${new_version}_dev_Lenyu.img
else
gzip -d openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img.gz
sysupgrade -n /tmp/openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img
fi
;;
*)
echo
echo -e "\033[31m err:只能选择Y/N\033[0m"
echo
read -n 1 -p "请回车继续…"
echo
open_up
esac
}
open_op()
{
echo
read -n 1 -p " 您确定要升级吗,升级选择Y,否则选N:" num1
echo
case $num1 in
Y|y)
open_up
;;
n|N)
echo
echo -e "\033[31m >>>您已选择退出固件升级,已经终止脚本…-> \033[0m"
echo
exit 1
;;
*)
echo
echo -e "\033[31m err:只能选择Y/N\033[0m"
echo
read -n 1 -p "请回车继续…"
echo
open_op
esac
}
open_op
exit 0
EOF
cat>files/usr/share/Lenyu-auto.sh<<-\EOF
#!/bin/bash
# https://github.com/Lenyu2020/Actions-OpenWrt-x86
# Actions-OpenWrt-x86 By Lenyu 20210505
#path=$(dirname $(readlink -f $0))
# cd ${path}
#检测准备
if [ ! -f "/etc/lenyu_version" ]; then
echo
echo -e "\033[31m 该脚本在非Lenyu固件上运行,为避免不必要的麻烦,准备退出… \033[0m"
echo
exit 0
fi
rm -f /tmp/cloud_version
# 获取固件云端版本号、内核版本号信息
current_version=`cat /etc/lenyu_version`
wget -qO- -t1 -T2 "https://api.github.com/repos/Lenyu2020/Actions-OpenWrt-x86/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g;s/v//g' > /tmp/cloud_ts_version
if [ -s "/tmp/cloud_ts_version" ]; then
cloud_version=`cat /tmp/cloud_ts_version | cut -d _ -f 1`
cloud_kernel=`cat /tmp/cloud_ts_version | cut -d _ -f 2`
#固件下载地址
new_version=`cat /tmp/cloud_ts_version`
DEV_URL=https://github.com/Lenyu2020/Actions-OpenWrt-x86/releases/download/${new_version}/openwrt_x86-64-${new_version}_dev_Lenyu.img.gz
DEV_UEFI_URL=https://github.com/Lenyu2020/Actions-OpenWrt-x86/releases/download/${new_version}/openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img.gz
openwrt_dev=https://github.com/Lenyu2020/Actions-OpenWrt-x86/releases/download/${new_version}/openwrt_dev.md5
openwrt_dev_uefi=https://github.com/Lenyu2020/Actions-OpenWrt-x86/releases/download/${new_version}/openwrt_dev_uefi.md5
else
echo "请检测网络或重试!"
exit 1
fi
####
Firmware_Type="$(grep 'DISTRIB_ARCH=' /etc/openwrt_release | cut -d \' -f 2)"
echo $Firmware_Type > /etc/lenyu_firmware_type
echo
if [[ "$cloud_kernel" =~ "4.19" ]]; then
echo
echo -e "\033[31m 该脚本在Lenyu固件Sta版本上运行,目前只建议在Dev版本上运行,准备退出… \033[0m"
echo
exit 0
fi
#md5值验证,固件类型判断
if [ ! -d /sys/firmware/efi ];then
if [ "$current_version" != "$cloud_version" ];then
wget -P /tmp "$DEV_URL" -O /tmp/openwrt_x86-64-${new_version}_dev_Lenyu.img.gz
wget -P /tmp "$openwrt_dev" -O /tmp/openwrt_dev.md5
cd /tmp && md5sum -c openwrt_dev.md5
if [ $? != 0 ]; then
echo "您下载文件失败,请检查网络重试…"
sleep 4
exit
fi
gzip -d /tmp/openwrt_x86-64-${new_version}_dev_Lenyu.img.gz
sysupgrade /tmp/openwrt_x86-64-${new_version}_dev_Lenyu.img
else
echo -e "\033[32m 本地已经是最新版本,还更个鸡巴毛啊… \033[0m"
echo
exit
fi
else
if [ "$current_version" != "$cloud_version" ];then
wget -P /tmp "$DEV_UEFI_URL" -O /tmp/openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img.gz
wget -P /tmp "$openwrt_dev_uefi" -O /tmp/openwrt_dev_uefi.md5
cd /tmp && md5sum -c openwrt_dev_uefi.md5
if [ $? != 0 ]; then
echo "您下载文件失败,请检查网络重试…"
sleep 1
exit
fi
gzip -d /tmp/openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img.gz
sysupgrade /tmp/openwrt_x86-64-${new_version}_uefi-gpt_dev_Lenyu.img
else
echo -e "\033[32m 本地已经是最新版本,还更个鸡巴毛啊… \033[0m"
echo
exit
fi
fi
exit 0
EOF