up.sh
2.5 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
86
87
#! /bin/bash
echo "_____up.sh start_____";
#变量命名
Update_judgment_file="/root/Update_judgment_file"
Update_PsdkPack="JZ_U3S_V*" #升级包名字
MD5saveFile=UpdateMD5num #md5文件内部的md5值
TarPackage_second=UpgradePackage.tar.gz #二次解压包的名字
# 删除一切更新内容
delete_updateFile(){
rm -rf /root/upgrade.tar.gz; #删除一次压缩包
rm -rf /root/$MD5saveFile; #删除md5校准文件
rm -rf /root/$TarPackage_second; #删除二次压缩包
rm -rf /root/sdcard/${Update_PsdkPack} #删除更新包
}
#检查是否要回复出厂
if [ -f /root/sdcard/FactorySettingReset ]; then
echo "检查到恢复出厂"
cd /root/FactorySetting;
./FactoryReset.sh;
fi
if [ -f /root/sdcard/${Update_PsdkPack} ]; then
# 一次解压
cp /root/sdcard/${Update_PsdkPack} /root/upgrade.tar.gz;
cd /root/;
tar -zxvf upgrade.tar.gz;
# 执行删除
# 播报升级失败
# 计数 超过3次删除
# 1、检查是否存在更新文件
if [ ! -f ${Update_judgment_file} ]; then
echo "____更新判断文件不存在,创建一个___"
echo 1 > $Update_judgment_file
fi
#2、读取文件中的更新次数
while read numbers
do
number=$(cat $Update_judgment_file | grep -o '[0-9]*')
echo "____本次读到的更新次数为第$number ____"
done < $Update_judgment_file
#3、如果本次次数为第四次,删除更新文件,并取消这次更新
if [ $number -eq 4 ]; then
echo "____本次更新为第四次____"
echo "删除更新记录文件"
rm -rf $Update_judgment_file
echo "强制删除更新文件"
delete_updateFile; #删除更新文件
# 播报升级失败
./defeat;
exit
fi
#4、更新次数+1
number=$((number+1))
#把更新次数写入回去
echo $number | tee $Update_judgment_file > /dev/null #覆盖写
# 引导程序
./updata.sh; #识别硬件 和 软件版本号
# 检查 /root/sdcard/ 下是否存在 .bin 文件
if find /root/sdcard/ -type f -name "*.bin" | grep -q .; then
# 如果存在 .bin 文件
./defeat # 播报升级失败
else
# 如果不存在 .bin 文件
rm -rf $Update_judgment_file
rm /root/sdcard/update_log.txt
./upsucces # 播报升级成功并重启
reboot;
fi
fi
#序列号写入
if [ -f /root/sdcard/num ]; then
mv /root/sdcard/num /root/num;
fi
echo "___up.sh___";