forked from ExtremeFiretop/MerlinAutoUpdate-Router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnuton_webs_update.sh
More file actions
117 lines (96 loc) · 4.53 KB
/
gnuton_webs_update.sh
File metadata and controls
117 lines (96 loc) · 4.53 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
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
#!/bin/sh
readonly SCRIPT_VERSTAG="25072411"
wget_options="-q -t 2 -T 30"
fwsite="https://raw.githubusercontent.com/gnuton/asuswrt-merlin.ng/master/updates"
nvram set webs_state_update=0 # INITIALIZING
nvram set webs_state_flag=0 # 0: Don't do upgrade 1: Do upgrade
nvram set webs_state_error=0
nvram set webs_state_url=""
#openssl support rsa check
IS_SUPPORT_NOTIFICATION_CENTER=$(nvram get rc_support|grep -i nt_center)
if [ "$IS_SUPPORT_NOTIFICATION_CENTER" != "" ]; then
. /tmp/nc/event.conf
fi
# current firmware information
current_base=$(nvram get firmver | sed "s/\.//g")
current_firm=$(nvram get buildno | cut -d. -f1)
current_buildno=$(nvram get buildno | cut -d. -f2)
current_extendno="$(nvram get extendno | awk -F'[_-]' '{print $1}')"
current_gnuton="$(nvram get extendno | sed -n 's/.*gnuton\([0-9]\+\).*/\1/p')"
[ -z "$current_gnuton" ] && current_gnuton=0
echo "$(nvram get extendno)" | grep -qiE 'beta|alpha' && current_is_beta=1 || current_is_beta=0
# get firmware information
model=$(nvram get productid)
model="$model#"
if [ "$current_base" = "3006" ]; then
manifest_file="manifest_3006.txt"
else
manifest_file="manifest2.txt"
fi
echo "---- update real normal----" > /tmp/webs_upgrade.log
/usr/sbin/wget $wget_options "$fwsite/$manifest_file" -O /tmp/wlan_update.txt
if [ "$?" != "0" ]; then
nvram set webs_state_error=1
else
fullver="$(grep "$model" /tmp/wlan_update.txt | tail -n1 | sed 's/.*#FW//')"
fullver=$(echo $fullver | sed s/#.*//;)
firmbase=$(echo $fullver | cut -d. -f1)
firmver=$(echo $fullver | cut -d. -f2)
buildno=$(echo $fullver | cut -d. -f3)
extendno="$(grep "$model" /tmp/wlan_update.txt | tail -n1 | sed 's/.*#EXT//')"
extendno=$(echo $extendno | sed s/#.*//;)
lextendno=$(echo $extendno | sed s/-g.*//;)
new_gnuton="$(echo $extendno | sed -n 's/.*gnuton\([0-9]\+\).*/\1/p')"
[ -z "$new_gnuton" ] && new_gnuton=0
echo "$extendno" | grep -qiE 'beta|alpha' && new_is_beta=1 || new_is_beta=0
nvram set webs_state_info=${firmbase}_${firmver}_${buildno}_${extendno}
rm -f /tmp/wlan_update.*
fi
echo "---- Have ${current_base}.${current_firm}.${current_buildno}_${current_extendno}----" >> /tmp/webs_upgrade.log
echo "---- Stable available ${firmbase}.${firmver}.${buildno}_${extendno}----" >> /tmp/webs_upgrade.log
update_webs_state_info=$(nvram get webs_state_info)
last_webs_state_info=$(nvram get webs_last_info)
if [ "$firmbase" == "" ] || [ "$firmver" == "" ] || [ "$buildno" == "" ] || [ "$lextendno" == "" ]; then
nvram set webs_state_error=1 # exist no Info
else
if [ "$current_base" -lt "$firmbase" ]; then
newfirm=1
elif [ "$current_base" -eq "$firmbase" ] && [ "$current_firm" -lt "$firmver" ]; then
newfirm=1
elif [ "$current_base" -eq "$firmbase" ] && [ "$current_firm" -eq "$firmver" ] && [ "$current_buildno" -lt "$buildno" ]; then
newfirm=1
elif [ "$current_base" -eq "$firmbase" ] && [ "$current_firm" -eq "$firmver" ] && [ "$current_buildno" -eq "$buildno" ] && [ "$current_extendno" -lt "$lextendno" ]; then
newfirm=1
elif [ "$current_base" -eq "$firmbase" ] && [ "$current_firm" -eq "$firmver" ] && [ "$current_buildno" -eq "$buildno" ] && [ "$current_extendno" -eq "$lextendno" ] && [ "$current_gnuton" -lt "$new_gnuton" ]; then
newfirm=1
elif [ "$current_base" -eq "$firmbase" ] && [ "$current_firm" -eq "$firmver" ] && [ "$current_buildno" -eq "$buildno" ] && [ "$current_extendno" -eq "$lextendno" ] && [ "$current_gnuton" -eq "$new_gnuton" ] && [ "$current_is_beta" -eq 1 ] && [ "$new_is_beta" -eq 0 ]; then
newfirm=1
else
newfirm=0
fi
if [ "$newfirm" -eq "1" ]; then
echo "---- Update available" >> /tmp/webs_upgrade.log
nvram set webs_state_flag=1 # Do upgrade
if [ "$IS_SUPPORT_NOTIFICATION_CENTER" != "" ]; then
if [ "$last_webs_state_info" != "$update_webs_state_info" ]; then
Notify_Event2NC "$SYS_FW_NWE_VERSION_AVAILABLE_EVENT" "{\"fw_ver\":\"$update_webs_state_info\"}"
nvram set webs_last_info="$update_webs_state_info"
fi
fi
fi
fi
# download releasee note
webs_state_flag=$(nvram get webs_state_flag)
if [ "$webs_state_flag" -eq "1" ]; then
releasenote_file0=$(nvram get webs_state_info)_note.txt
releasenote_path0="/tmp/release_note0.txt"
echo "---- download real release note ----" >> /tmp/webs_upgrade.log
/usr/sbin/wget $wget_options $fwsite/$releasenote_file0 -O $releasenote_path0
if [ "$?" != "0" ]; then
echo "---- download $fwsite/$releasenote_file0 failed ----" >> /tmp/webs_upgrade.log
nvram set webs_state_error=1
else
echo "---- $fwsite/$releasenote_file0 ----" >> /tmp/webs_upgrade.log
fi
fi
nvram set webs_state_update=1