Skip to content

Commit

Permalink
[FIX] hw_posbox_homepage: Fix IoT auto-upgrade
Browse files Browse the repository at this point in the history
If we start a self flash and we refresh the page
we are able to start again the upgrade.

So now we check if a upgrade is not already started

closes odoo/odoo#48330

X-original-commit: 7189111
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
  • Loading branch information
qle-odoo committed Mar 25, 2020
1 parent 74df5cb commit e41e64b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion addons/hw_posbox_homepage/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def check_version(self):
def perform_flashing_create_partition(self):
try:
response = subprocess.check_output(['sudo', 'bash', '-c', '. /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/upgrade.sh; create_partition']).decode().split('\n')[-2]
if response == 'Error_Card_Size':
if response in ['Error_Card_Size', 'Error_Upgrade_Already_Started']:
raise Exception(response)
return Response('success', status=200)
except subprocess.CalledProcessError as e:
Expand Down
2 changes: 1 addition & 1 deletion addons/hw_posbox_homepage/views/upgrade_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block head %}
<script type="text/javascript" src="/web/static/lib/jquery/jquery.js"></script>
<script>
$(async function() {
$(function() {
var updating = false;
$('#upgrade').click(function() {
if (!updating) {
Expand Down
13 changes: 12 additions & 1 deletion addons/point_of_sale/tools/posbox/configuration/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ file_exists () {
create_partition () {
mount -o remount,rw /

if [ -f start_upgrade ]
then
echo "Error_Upgrade_Already_Started"
exit 0
fi

touch start_upgrade

echo "Fdisking"

PARTITION=$(lsblk | awk 'NR==2 {print $1}')
Expand All @@ -15,6 +23,7 @@ create_partition () {

if [ "${SECTORS_SIZE}" -lt 15583488 ] # self-flash not permited if SD size < 16gb
then
rm start_upgrade
echo "Error_Card_Size"
exit 0
fi
Expand Down Expand Up @@ -52,7 +61,7 @@ create_partition () {
}

download_raspbian () {
if ! file_exists *raspbian*.img ; then
if [ ! -f *raspbian*.img ] ; then
# download latest Raspbian image and check integrity
LATEST_RASPBIAN=$(curl -LIsw %{url_effective} http://downloads.raspberrypi.org/raspbian_lite_latest | tail -n 1)
wget -c "${LATEST_RASPBIAN}"
Expand All @@ -66,6 +75,7 @@ download_raspbian () {
# Clean raspbian img
rm "${RASPBIAN}" "${RASPBIAN}".sha256

rm start_upgrade
echo "Error_Raspbian_Download"
exit 0
fi
Expand Down Expand Up @@ -119,6 +129,7 @@ copy_raspbian () {
if [ "${CHECK}" != "iotbox-latest.zip: OK" ]
then
# Checksum is not correct so clean and reset self-flashing
rm start_upgrade
echo "Error_Iotbox_Download"
exit 0
fi
Expand Down

0 comments on commit e41e64b

Please sign in to comment.