Skip to content

Commit 7a743ef

Browse files
committed
[New] WebUI Pre-Release install & Minor Wording Change
1 parent 24af7d0 commit 7a743ef

File tree

5 files changed

+162
-14
lines changed

5 files changed

+162
-14
lines changed

src/www/httpd/cgi-bin/fw_upgrade.sh

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
YI_HACK_PREFIX="/tmp/sd/yi-hack-v5"
44
MODEL_SUFFIX=`cat /home/app/.camver`
55
FW_VERSION=`cat /tmp/sd/yi-hack-v5/version`
6+
BASELINE_VERSION=`cat /home/yi-hack-v5/version`
67

78
export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/home/base/tools:/home/app/localbin:/home/base:/tmp/sd/yi-hack-v5/bin:/tmp/sd/yi-hack-v5/sbin:/tmp/sd/yi-hack-v5/usr/bin:/tmp/sd/yi-hack-v5/usr/sbin
89
export LD_LIBRARY_PATH=/lib:/usr/lib:/home/lib:/home/qigan/lib:/home/app/locallib:/tmp/sd:/tmp/sd/gdb:/tmp/sd/yi-hack-v5/lib
@@ -19,15 +20,16 @@ if [ "$VAL" == "info" ] ; then
1920
printf "Content-type: application/json\r\n\r\n"
2021

2122
FW_VERSION=`cat /tmp/sd/yi-hack-v5/version`
22-
LATEST_FW=`/usr/bin/wget -O - https://api.github.com/repos/alienatedsec/yi-hack-v5/releases/latest 2>&1 | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`
23-
23+
LATEST_FW=`/usr/bin/wget -O - https://api.github.com/repos/alienatedsec/yi-hack-v5/releases/latest 2>&1 | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`
24+
PRERELEASE_FW=`/usr/bin/wget -O - https://api.github.com/repos/alienatedsec/yi-hack-v5/releases 2>&1 | grep -B 4 '"prerelease": true' | awk -F '"' '{print $4; exit}'`
25+
2426
printf "{\n"
25-
printf "\"%s\":\"%s\",\n" "fw_version" "$FW_VERSION"
26-
printf "\"%s\":\"%s\"\n" "latest_fw" "$LATEST_FW"
27+
printf "\"%s\":\"%s\",\n" "fw_version" "$FW_VERSION"
28+
printf "\"%s\":\"%s\",\n" "latest_fw" "$LATEST_FW"
29+
printf "\"%s\":\"%s\"\n" "prerelease_fw" "$PRERELEASE_FW"
2730
printf "}"
2831

2932
elif [ "$VAL" == "upgrade" ] ; then
30-
3133
FREE_SD=$(df /tmp/sd/ | grep mmc | awk '{print $4}')
3234
if [ -z "$FREE_SD" ]; then
3335
printf "Content-type: text/html\r\n\r\n"
@@ -89,9 +91,82 @@ elif [ "$VAL" == "upgrade" ] ; then
8991
printf "Content-type: text/html\r\n\r\n"
9092
printf "Download completed, rebooting and upgrading."
9193

94+
sync
95+
sync
96+
sync
97+
sleep 1
98+
reboot
99+
100+
elif [ "$VAL" == "preupgrade" ] ; then
101+
FREE_SD=$(df /tmp/sd/ | grep mmc | awk '{print $4}')
102+
if [ -z "$FREE_SD" ]; then
103+
printf "Content-type: text/html\r\n\r\n"
104+
printf "No SD detected."
105+
exit
106+
fi
107+
108+
if [ $FREE_SD -lt 100000 ]; then
109+
printf "Content-type: text/html\r\n\r\n"
110+
printf "No space left on SD."
111+
exit
112+
fi
113+
114+
# Clean old upgrades
115+
rm -rf /tmp/sd/${MODEL_SUFFIX}
116+
rm -rf /tmp/sd/${MODEL_SUFFIX}.conf
117+
rm -rf /tmp/sd/Factory
118+
rm -rf /tmp/sd/newhome
119+
rm /tmp/sd/rootfs*
120+
rm /tmp/sd/home*
121+
122+
mkdir -p /tmp/sd/${MODEL_SUFFIX}
123+
mkdir -p /tmp/sd/${MODEL_SUFFIX}.conf
124+
# cd /tmp/sd/${MODEL_SUFFIX}
125+
cd /tmp/sd
126+
127+
if [ -f /tmp/sd/${MODEL_SUFFIX}_x.x.x.tgz ]; then
128+
# mv /tmp/sd/${MODEL_SUFFIX}_x.x.x.tgz /tmp/sd/${MODEL_SUFFIX}/${MODEL_SUFFIX}_x.x.x.tgz
129+
PRERELEASE_FW="x.x.x"
130+
else
131+
PRERELEASE_FW=`/usr/bin/wget -O - https://api.github.com/repos/alienatedsec/yi-hack-v5/releases 2>&1 | grep -B 4 '"prerelease": true' | awk -F '"' '{print $4; exit}'`
132+
if [ "$FW_VERSION" == "$PRERELEASE_FW" ]; then
133+
printf "Content-type: text/html\r\n\r\n"
134+
printf "No new firmware available."
135+
exit
136+
elif [ "$BASELINE_VERSION" != "0.3.8" ]; then
137+
printf "Content-type: text/html\r\n\r\n"
138+
printf "Wrong baseline version"
139+
exit
140+
fi
141+
142+
/usr/bin/wget https://github.com/alienatedsec/yi-hack-v5/releases/download/$PRERELEASE_FW/${MODEL_SUFFIX}_${PRERELEASE_FW}.tgz
143+
144+
if [ ! -f ${MODEL_SUFFIX}_${PRERELEASE_FW}.tgz ]; then
145+
printf "Content-type: text/html\r\n\r\n"
146+
printf "Unable to download firmware file."
147+
exit
148+
fi
149+
fi
150+
151+
# Backup configuration
152+
cp -rf $YI_HACK_PREFIX/etc/* /tmp/sd/${MODEL_SUFFIX}.conf/
153+
rm /tmp/sd/${MODEL_SUFFIX}.conf/*.tar.gz
154+
155+
# Prepare new hack
156+
gzip -d ${MODEL_SUFFIX}_${PRERELEASE_FW}.tgz
157+
tar xvf ${MODEL_SUFFIX}_${PRERELEASE_FW}.tar
158+
rm ${MODEL_SUFFIX}_${PRERELEASE_FW}.tar
159+
mkdir -p /tmp/sd/${MODEL_SUFFIX}/yi-hack-v5/etc
160+
cp -rf /tmp/sd/${MODEL_SUFFIX}.conf/* /tmp/sd/${MODEL_SUFFIX}/yi-hack-v5/etc/
161+
162+
# Report the status to the caller
163+
printf "Content-type: text/html\r\n\r\n"
164+
printf "Download completed, rebooting and upgrading."
165+
92166
sync
93167
sync
94168
sync
95169
sleep 1
96170
reboot
97171
fi
172+

src/www/httpd/cgi-bin/status.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ printf "Content-type: application/json\r\n\r\n"
55
NAME="yi-hack-v5"
66
HOSTNAME=$(hostname)
77
FW_VERSION=$(cat /tmp/sd/yi-hack-v5/version)
8+
BASEFW_VERSION=$(cat /home/yi-hack-v5/version)
89
HOME_VERSION=$(cat /home/app/.appver)
910
MODEL_SUFFIX=$(cat /home/app/.camver)
1011
if [[ $MODEL_SUFFIX == "yi_dome_1080p" ]] || [[ $MODEL_SUFFIX == "yi_cloud_dome_1080p" ]] ; then
@@ -45,6 +46,7 @@ printf "{\n"
4546
printf "\"%s\":\"%s\",\n" "name" "$NAME"
4647
printf "\"%s\":\"%s\",\n" "hostname" "$HOSTNAME"
4748
printf "\"%s\":\"%s\",\n" "fw_version" "$FW_VERSION"
49+
printf "\"%s\":\"%s\",\n" "basefw_version" "$BASEFW_VERSION"
4850
printf "\"%s\":\"%s\",\n" "home_version" "$HOME_VERSION"
4951
printf "\"%s\":\"%s\",\n" "model_suffix" "$MODEL_SUFFIX"
5052
printf "\"%s\":\"%s\",\n" "hardware_id" $HARDWARE_ID

src/www/httpd/htdocs/js/modules/maintenance.js

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ APP.maintenance = (function($) {
88
registerEventHandler();
99
setRebootStatus("Camera is online.");
1010
getFwStatus();
11+
getPreFwStatus();
1112
}
1213

1314
function registerEventHandler() {
@@ -26,6 +27,9 @@ APP.maintenance = (function($) {
2627
$(document).on("click", '#button-upgrade', function(e) {
2728
upgradeFirmware();
2829
});
30+
$(document).on("click", '#button-preupgrade', function(e) {
31+
preupgradeFirmware();
32+
});
2933
}
3034

3135
function saveConfig() {
@@ -140,29 +144,53 @@ APP.maintenance = (function($) {
140144
},
141145
success: function(response) {
142146
setFwStatus(response);
143-
waitForUpgrade();
147+
waitForUpgrade("button-upgrade");
144148
}
145149
});
146150
}
147-
148-
function waitForUpgrade() {
151+
152+
function preupgradeFirmware() {
153+
$('#button-preupgrade').attr("disabled", true);
154+
setPreFwStatus("Pre-Release Firmware download in progress.");
155+
$.ajax({
156+
type: "GET",
157+
url: 'cgi-bin/fw_upgrade.sh?get=preupgrade',
158+
error: function(response) {
159+
console.log('error', response);
160+
$('#button-preupgrade').attr("disabled", false);
161+
},
162+
success: function(response) {
163+
setPreFwStatus(response);
164+
waitForUpgrade("button-preupgrade");
165+
}
166+
});
167+
}
168+
169+
function waitForUpgrade(buttonType) {
149170
setInterval(function() {
150171
$.ajax({
151172
url: 'index.html',
152173
cache: false,
153174
success: function(data) {
154-
setFwStatus("Camera is upgrading.");
155-
$('#button-upgrade').attr("disabled", false);
175+
if (buttonType === "button-upgrade") {
176+
setFwStatus("Camera is upgrading.");
177+
} else if (buttonType === "button-preupgrade") {
178+
setPreFwStatus("Pre-upgrade in progress...");
179+
}
180+
181+
$('#' + buttonType).attr("disabled", false);
156182
window.location.href = "index.html";
157183
},
158184
error: function(data) {
159185
setFwStatus("Waiting for the camera to come back online...");
186+
setPreFwStatus("Waiting for the camera to come back online...");
160187
},
161188
timeout: 3000,
162189
});
163190
}, 5000);
164191
}
165192

193+
166194
function setRebootStatus(text) {
167195
$('input[type="text"][data-key="STATUS"]').prop('value', text);
168196
}
@@ -174,6 +202,10 @@ APP.maintenance = (function($) {
174202
function setFwStatus(text) {
175203
$('input[type="text"][data-key="FW"]').prop('value', text);
176204
}
205+
206+
function setPreFwStatus(text) {
207+
$('input[type="text"][data-key="PREFW"]').prop('value', text);
208+
}
177209

178210
function getFwStatus() {
179211
$.ajax({
@@ -192,7 +224,25 @@ APP.maintenance = (function($) {
192224
}
193225
});
194226
}
195-
227+
228+
function getPreFwStatus() {
229+
$.ajax({
230+
type: "GET",
231+
url: 'cgi-bin/fw_upgrade.sh?get=info',
232+
dataType: "json",
233+
error: function(response) {
234+
console.log('error', response);
235+
setPreFwStatus("Error getting fw info");
236+
},
237+
success: function(data) {
238+
setPreFwStatus("Installed: " + data.fw_version + " - Available: " + data.prerelease_fw);
239+
if (data.fw_version == data.prelease_fw) {
240+
$('#button-preupgrade').attr("disabled", true);
241+
}
242+
}
243+
});
244+
}
245+
196246
return {
197247
init: init
198248
};

src/www/httpd/htdocs/pages/maintenance.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h5 class="tiny-margin strong">Reboot</h5>
5353
</tbody>
5454
</table>
5555

56-
<h5 class="tiny-margin strong">Reset to yi-hack default</h5>
56+
<h5 class="tiny-margin strong">Reset to YI-HACK-V5 defaults</h5>
5757
<hr class="no-margin"/>
5858

5959
<table class="u-full-width padded-table">
@@ -69,7 +69,7 @@ <h5 class="tiny-margin strong">Reset to yi-hack default</h5>
6969
</tbody>
7070
</table>
7171

72-
<h5 class="tiny-margin strong">Online FW upgrade</h5>
72+
<h5 class="tiny-margin strong">Latest FW upgrade</h5>
7373
<hr class="no-margin"/>
7474

7575
<table class="u-full-width padded-table">
@@ -79,10 +79,27 @@ <h5 class="tiny-margin strong">Online FW upgrade</h5>
7979
<input class="u-full-width" type="text" placeholder="" readonly="" data-key="FW" id="FW"/>
8080
</td>
8181
<td>
82-
<input class="button-primary" type="button" id="button-upgrade" value="Upgrade Firmware"/>
82+
<input class="button-primary" type="button" id="button-upgrade" value="Upgrade to Latest"/>
8383
</td>
8484
</tr>
8585
</tbody>
8686
</table>
87+
88+
<h5 class="tiny-margin strong">Pre-Release FW upgrade</h5>
89+
<hr class="no-margin"/>
90+
91+
<table class="u-full-width padded-table">
92+
<tbody>
93+
<tr class="row">
94+
<td>
95+
<input class="u-full-width" type="text" placeholder="" readonly="" data-key="PREFW" id="PREFW"/>
96+
</td>
97+
<td>
98+
<input class="button-primary" type="button" id="button-preupgrade" value="Upgrade to Pre-Release"/>
99+
</td>
100+
</tr>
101+
</tbody>
102+
</table>
103+
87104
</div>
88105
</div>

src/www/httpd/htdocs/pages/status.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ <h5 class="tiny-margin strong">System</h5>
5151
<td>Firmware Version</td>
5252
<td id="fw_version"></td>
5353
</tr>
54+
<tr>
55+
<td>Baseline Firmware Version</td>
56+
<td id="basefw_version"></td>
57+
</tr>
5458
<tr>
5559
<td>Base Version</td>
5660
<td id="home_version"></td>

0 commit comments

Comments
 (0)