[FIX] point_of_sale: Update raspberry pi os for iot use

With this update the version of python goes to 3.9.2
In addition, a unique password system has been put in place

closes odoo/odoo#127975

X-original-commit: a0feb285ff2ff4a9b82f87ff5abefb307847f25a
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
This commit is contained in:
lejeune quentin
2023-07-10 18:16:33 +02:00
parent 489566d4bb
commit 5eeae30fd3
6 changed files with 54 additions and 10 deletions
+17
View File
@@ -19,6 +19,8 @@ from threading import Thread
import time
import contextlib
import requests
import crypt
import secrets
from odoo import _, http, service
from odoo.tools.func import lazy_property
@@ -188,6 +190,21 @@ def save_conf_server(url, token, db_uuid, enterprise_code):
write_file('odoo-db-uuid.conf', db_uuid or '')
write_file('odoo-enterprise-code.conf', enterprise_code or '')
def generate_password():
"""
Generate an unique code to secure raspberry pi
"""
alphabet = 'abcdefghijkmnpqrstuvwxyz23456789'
password = ''.join(secrets.choice(alphabet) for i in range(12))
shadow_password = crypt.crypt(password, crypt.mksalt())
subprocess.call(('sudo', 'usermod', '-p', shadow_password, 'pi'))
with writable():
subprocess.call(('sudo', 'cp', '/etc/shadow', '/root_bypass_ramdisks/etc/shadow'))
return password
def get_certificate_status(is_first=True):
"""
Will get the HTTPS certificate details if present. Will load the certificate if missing.
@@ -253,6 +253,11 @@ class IoTboxHomepage(Home):
'loading_message': 'Configure Domain Server'
})
# Get password
@http.route('/hw_posbox_homepage/password', type='json', auth='none', method=['POST'])
def view_password(self):
return helpers.generate_password()
@http.route('/remote_connect', type='http', auth='none', cors='*')
def remote_connect(self):
"""
@@ -26,6 +26,18 @@
}
});
});
$(function() {
$('.view-password').click(function() {
$.ajax({
url:'/hw_posbox_homepage/password',
type: 'post',
contentType: 'application/json',
data: JSON.stringify({ params: {action: 'view'} }),
}).done(function(password) {
$('.password').val(password['result']);
});
});
});
</script>
{% endblock %}
{% block content %}
@@ -36,6 +48,8 @@
you trust.
</p>
<div class='text-center'>
<input type="text" placeholder="pi user password" disabled>
<a class="btn view-password" style="margin: 18px auto;"href="#">Generate password</a><br/>
<input type="text" id="auth_token" size="42" placeholder="Authentication Token"/> <br/>
<a class="btn" style="margin: 18px auto;" id="enable_debug" href="#">Enable Remote Debugging</a>
</div>
View File
@@ -25,6 +25,11 @@ apt-get update && apt-get -y upgrade
# Do not be too fast to upgrade to more recent firmware and kernel than 4.38
# Firmware 4.44 seems to prevent the LED mechanism from working
# At the first start it is necessary to configure a password
# This will be modified by a unique password on the first start of Odoo
password="$(openssl rand -base64 32)"
echo "pi:${password}" | chpasswd
PKGS_TO_INSTALL="
console-data \
cups \
@@ -45,13 +50,15 @@ PKGS_TO_INSTALL="
nginx-full \
openbox \
printer-driver-all \
python-cups \
python3 \
python3-cups \
python3-babel \
python3-dateutil \
python3-dbus \
python3-decorator \
python3-dev \
python3-docutils \
python3-geoip2 \
python3-jinja2 \
python3-ldap \
python3-libsass \
@@ -99,14 +106,15 @@ rm -rfv /usr/share/doc
# Even in stretch, we had an error with langid (but worked otherwise)
# We fixe the version of evdev to 1.2.0 because in 1.3.0 we have a RuntimeError in 'get_event_loop()'
PIP_TO_INSTALL="
evdev==1.2.0 \
evdev==1.6.0 \
gatt \
polib \
pycups \
pyusb \
v4l2 \
pysmb==1.2.9.1 \
cryptocode==0.1"
cryptocode==0.1 \
rjsmin==1.1.0"
pip3 install ${PIP_TO_INSTALL}
@@ -142,7 +150,6 @@ systemctl disable dphys-swapfile.service
systemctl enable ssh
systemctl set-default graphical.target
systemctl disable getty@tty1.service
systemctl enable autologin@.service
systemctl disable systemd-timesyncd.service
systemctl unmask hostapd.service
systemctl disable hostapd.service
@@ -29,12 +29,12 @@ MOUNT_POINT="${__dir}/root_mount"
OVERWRITE_FILES_BEFORE_INIT_DIR="${__dir}/overwrite_before_init"
OVERWRITE_FILES_AFTER_INIT_DIR="${__dir}/overwrite_after_init"
VERSION=16.0
VERSION_IOTBOX=22.11
VERSION_IOTBOX=23.07
REPO=https://github.com/odoo/odoo.git
if ! file_exists *raspios*.img ; then
wget 'https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2021-05-28/2021-05-07-raspios-buster-armhf-lite.zip' -O raspios.img.zip
unzip raspios.img.zip
wget 'https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2023-05-03/2023-05-03-raspios-bullseye-armhf-lite.img.xz' -O raspios.img.xz
unxz --verbose raspios.img.xz
fi
RASPIOS=$(echo *raspios*.img)
@@ -76,10 +76,9 @@ dd if=/dev/zero bs=1M count=2048 status=progress >> iotbox.img
echo "Fdisking"
SECTORS_BOOT_START=$(sudo fdisk -l iotbox.img | tail -n 2 | awk 'NR==1 {print $2}')
SECTORS_BOOT_END=$((SECTORS_BOOT_START + 1048576)) # sectors to have a partition of ~512Mo
SECTORS_BOOT_END=$((SECTORS_BOOT_START + 1056767)) # sectors to have a partition of ~512Mo
SECTORS_ROOT_START=$((SECTORS_BOOT_END + 1))
START_OF_ROOT_PARTITION=$(fdisk -l iotbox.img | tail -n 1 | awk '{print $2}')
(echo 'p'; # print
echo 'd'; # delete
echo '2'; # number 2
@@ -103,12 +102,14 @@ LOOP_RASPIOS=$(kpartx -avs "${RASPIOS}")
LOOP_RASPIOS_ROOT=$(echo "${LOOP_RASPIOS}" | tail -n 1 | awk '{print $3}')
LOOP_RASPIOS_PATH="/dev/${LOOP_RASPIOS_ROOT::-2}"
LOOP_RASPIOS_ROOT="/dev/mapper/${LOOP_RASPIOS_ROOT}"
LOOP_RASPIOS_BOOT=$(echo "${LOOP_RASPIOS}" | head -n 1 | awk '{print $3}')
LOOP_RASPIOS_BOOT="/dev/mapper/${LOOP_RASPIOS_BOOT}"
LOOP_IOT=$(kpartx -avs iotbox.img)
LOOP_IOT_ROOT=$(echo "${LOOP_IOT}" | tail -n 1 | awk '{print $3}')
LOOP_IOT_PATH="/dev/${LOOP_IOT_ROOT::-2}"
LOOP_IOT_ROOT="/dev/mapper/${LOOP_IOT_ROOT}"
LOOP_IOT_BOOT=$(echo "${LOOP_IOT}" | tail -n 2 | awk 'NR==1 {print $3}')
LOOP_IOT_BOOT=$(echo "${LOOP_IOT}" | head -n 1 | awk 'NR==1 {print $3}')
LOOP_IOT_BOOT="/dev/mapper/${LOOP_IOT_BOOT}"
mkfs.ext4 -v "${LOOP_IOT_ROOT}"