From d285587754302f5913408f60f3224b354df422d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sun, 13 Apr 2025 20:50:47 +0200 Subject: [PATCH 1/5] Add more qemu tooling scripts. --- tools/build-in-qemu.sh | 24 +++++++++++++++++++++ tools/run-build-qemu-system.sh | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tools/run-build-qemu-system.sh diff --git a/tools/build-in-qemu.sh b/tools/build-in-qemu.sh index a14913f..ebd2093 100644 --- a/tools/build-in-qemu.sh +++ b/tools/build-in-qemu.sh @@ -1,4 +1,28 @@ #!/bin/sh +# +# build-in-qemu.sh +# +# Expects running armhf qemu system, builds the binary inside. +# +# ISC License +# +# Copyright 2025 Brmlab, z.s. +# Dominik Pantůček +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# if [ -z "$1" ] ; then echo "Usage: $0 password" diff --git a/tools/run-build-qemu-system.sh b/tools/run-build-qemu-system.sh new file mode 100644 index 0000000..c76d8b8 --- /dev/null +++ b/tools/run-build-qemu-system.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# +# run-build-qemu-system.sh +# +# Runs the emulated armhf system for building the application. +# +# ISC License +# +# Copyright 2025 Brmlab, z.s. +# Dominik Pantůček +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +qemu-system-armhf \ + -machine raspi2b \ + -nographic \ + -dtb bcm2710-rpi-3-b-plus.dtb \ + -m 1G \ + -smp 4 \ + -kernel kernel7.img \ + -sd 2019-04-08-raspbian-stretch.img \ + -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootdelay=1 dwc_otg.fiq_fsm_enable=0" \ + -usb \ + -device usb-net,netdev=net0 \ + -netdev user,id=net0,hostfwd=tcp::2222-:22 From b65740e21438bda18dd5a2e5d4f64c696f937f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sun, 13 Apr 2025 20:51:02 +0200 Subject: [PATCH 2/5] Add the org file with plan. --- 0PLAN.org | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 0PLAN.org diff --git a/0PLAN.org b/0PLAN.org new file mode 100644 index 0000000..befe26b --- /dev/null +++ b/0PLAN.org @@ -0,0 +1,89 @@ +#+title: Frontend + +* Plan + +** 0.2 + +- [ ] use localStorage to store user + - [ ] add barcode scanner to get the user + - [ ] allow editing + - [ ] add UserSelect component +- [X] integrate script for starting build qemu system +- [X] add org file to the repository after cleanup + +** 0.3 + +- [ ] versioned schema support + - [ ] barschema table + - [ ] function to check + - [ ] function to set + - [ ] initial creation of tables at version 1 assuming OK if tables exist + +** 0.4 + +- [ ] add inventory check table +- [ ] add inventory item check table +- [ ] create new check +- [ ] check item +- [ ] close check +- [ ] inventory check component + +** Later + +- [ ] add static token support + - [ ] hardwired token for the React.JS app? +- [ ] authentication + - [ ] login/logout + - [ ] allow API calls only with login token + +* Finished + +** 0.1 + +- [X] statically compiled binary HTTP server +- [X] include directory tree contents +- [X] handle frontend with mime type +- [X] move app to / again +- [X] load certificates +- [X] deployment preparations + - [X] crosscompilation - no, compile in qemu or on separate host + - [X] connect to postgres + - [X] use qr-scanner - no, qr-barcode-scanner is needed + - [X] rsync + build in qemu or host without react (filters or something) +- [X] API infrastructure + - [X] handle API calls + - [X] API registry syntax + - [X] lookup barcode in DB + - [X] separate module brmbar-data for queries + - [X] separate module api-servlets + +* Qemu + +#+BEGIN_SRC +wget img zip # 2019-04-08-raspbian-stretch.zip +unzip 2019-04-08-raspbian-stretch.zip +sudo mkdir /mnt/image +sudo mount -o loop,offset=4194304 2019-04-08-raspbian-stretch.img /mnt/image/ +# In qemu-system-armhf terminal! +cp kernel, DT +umount /mnt/image +resize img +#+END_SRC + +sources.list - archive debian (remove rpi), archive raspberry +https://archive.raspberrypi.org/debian/ +https://archive.debian.org/debian/ +apt-get --no + +* React - Vite + +#+BEGIN_SRC sh + npm create vite@latest + # "frontend" + # React + # Javascript + cd frontend + npm install + npm run dev + npm run build +#+END_SRC From 0677419d40f90eadee40b2acb5b6a4242a2480a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sun, 13 Apr 2025 21:16:45 +0200 Subject: [PATCH 3/5] Start work on general workflow. --- frontend/src/App.jsx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 2f4a741..ce437fb 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -8,6 +8,38 @@ import './App.css'; import 'bootstrap/dist/css/bootstrap.min.css'; function App() { + // Ensure we have persistent (informal) user information + const [user, setUser] = useState(""); + useEffect(() => { + localStorage.setItem('user', user); + }, [user]); + useEffect(() => { + const user = localStorage.getItem('user'); + if (user) { + setUser(user); + } + }, []); + + // If no user, must be scanned/set otherwise + return ( + + {user === "" ? + + : + } + + ); +} + +function NoUserView({setUser}) { + return

No user!

; +} + +function UserView({user}) { + return

User={user}

; +} + +function BarItemScanner() { const [reqAccount, setReqAccount] = useState(''); const [actAccount, setActAccount] = useState(''); const [balance, setBalance] = useState(-1); From a0752bb73a72f3e0d12495fb1ad663264ee3cfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sun, 13 Apr 2025 21:20:59 +0200 Subject: [PATCH 4/5] Ensure it compiles with posix-groups egg as well. --- install-eggs-arm.sh | 64 --------------------------------------------- install-eggs.sh | 1 + 2 files changed, 1 insertion(+), 64 deletions(-) delete mode 100644 install-eggs-arm.sh diff --git a/install-eggs-arm.sh b/install-eggs-arm.sh deleted file mode 100644 index fbd5da6..0000000 --- a/install-eggs-arm.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh -# -# install-eggs.sh -# -# Local installer of CHICKEN eggs required for building. -# -# ISC License -# -# Copyright 2023 Brmlab, z.s. -# Dominik Pantůček -# -# Permission to use, copy, modify, and/or distribute this software -# for any purpose with or without fee is hereby granted, provided -# that the above copyright notice and this permission notice appear -# in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL -# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE -# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR -# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -# Source root directory -owd=$(pwd) -cd $(dirname "$0") -SRCDIR=$(pwd) -cd "$owd" - -# Make temporary prefix directory (eggs shared throwaway files) -TMPDIR=$(mktemp -d) - -# Installs given egg locally -chicken_install() { - echo "Installing $1 ..." - # CHICKEN_INSTALL_PREFIX="$TMPDIR" \ - # CHICKEN_REPOSITORY_PATH="$SRCDIR/eggs-arm":`./cross-chicken-arm/bin/arm-chicken-install -repository` \ - # CHICKEN_INSTALL_REPOSITORY="$SRCDIR/eggs-arm" \ - # ./cross-chicken-arm/bin/arm-chicken-install "$1" 2>&1 | \ - # sed -u 's/^/ /' -# CHICKEN_INSTALL_PREFIX="$TMPDIR" \ - ./cross-chicken-arm/bin/arm-chicken-install "$1" 2>&1 | \ - sed -u 's/^/ /' -} - -# Removes throwaway files -chicken_cleanup() { - echo "Cleaning up ..." - rm -fr ${TMPDIR} -} - -# Always cleanup -trap chicken_cleanup INT QUIT - -# Install required eggs -chicken_install spiffy -chicken_install openssl -chicken_install postgresql - -# Normal termination cleanup -chicken_cleanup diff --git a/install-eggs.sh b/install-eggs.sh index 2bcb95c..08c098c 100644 --- a/install-eggs.sh +++ b/install-eggs.sh @@ -57,6 +57,7 @@ chicken_install openssl chicken_install spiffy chicken_install postgresql chicken_install json +chicken_install posix-groups # Normal termination cleanup chicken_cleanup From 1815547daf2ab260ca25ef5d46a6f65048ecfa7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Mon, 14 Apr 2025 12:16:04 +0200 Subject: [PATCH 5/5] Work on user selection. --- 0PLAN.org | 6 ++--- backend/brminv.scm | 6 ++++- frontend/src/App.jsx | 61 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/0PLAN.org b/0PLAN.org index befe26b..d985997 100644 --- a/0PLAN.org +++ b/0PLAN.org @@ -4,10 +4,10 @@ ** 0.2 -- [ ] use localStorage to store user +- [-] use localStorage to store user - [ ] add barcode scanner to get the user - - [ ] allow editing - - [ ] add UserSelect component + - [X] allow editing + - [X] add UserSelect component - [X] integrate script for starting build qemu system - [X] add org file to the repository after cleanup diff --git a/backend/brminv.scm b/backend/brminv.scm index 808bf70..48c5c28 100644 --- a/backend/brminv.scm +++ b/backend/brminv.scm @@ -47,6 +47,7 @@ (define -db-user- (make-parameter #f)) (define -db-name- (make-parameter #f)) (define -db-pass- (make-parameter #f)) +(define -db-enabled- (make-parameter #t)) (command-line print-help @@ -82,6 +83,8 @@ (-db-user- dbuser)) (-dp (dbpass) "Database password" (-db-pass- dbpass)) + (-dd () "Disable database" + (-db-enabled- #f)) ) (define ssl? (and (-certificate-) (-key-) #t)) @@ -120,7 +123,8 @@ (print "current user id: " (current-user-id)) (print "current effective user id: " (current-effective-user-id)) -(bar-db-init! (-db-name-) (-db-host-) (-db-user-) (-db-pass-)) +(when (-db-enabled-) + (bar-db-init! (-db-name-) (-db-host-) (-db-user-) (-db-pass-))) (define (handle-api-calls) (define plst (cdr (uri-path (request-uri (current-request))))) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index ce437fb..2ae663c 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,8 +1,12 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import BarcodeScannerComponent from 'react-qr-barcode-scanner'; -import { Container, Row, Col } from 'react-bootstrap'; +import Container from 'react-bootstrap/Container'; +import Row from 'react-bootstrap/Row'; +import Col from 'react-bootstrap/Col'; import Table from 'react-bootstrap/Table'; import Alert from 'react-bootstrap/Alert'; +import Form from 'react-bootstrap/Form'; +import Button from 'react-bootstrap/Button'; import './App.css'; import 'bootstrap/dist/css/bootstrap.min.css'; @@ -10,15 +14,15 @@ import 'bootstrap/dist/css/bootstrap.min.css'; function App() { // Ensure we have persistent (informal) user information const [user, setUser] = useState(""); - useEffect(() => { - localStorage.setItem('user', user); - }, [user]); useEffect(() => { const user = localStorage.getItem('user'); if (user) { setUser(user); } }, []); + useEffect(() => { + localStorage.setItem('user', user); + }, [user]); // If no user, must be scanned/set otherwise return ( @@ -26,17 +30,52 @@ function App() { {user === "" ? : - } + } ); } function NoUserView({setUser}) { - return

No user!

; + const [preUser, setPreUser] = useState(""); + return ( + <> + + + + User: + setPreUser(v.target.value)} /> + Which user is using this App? + + + + + + Scanner + + + + + + + + + ); } -function UserView({user}) { - return

User={user}

; +function UserView({user, setUser}) { + return ( + + + {user} + + + + + + + ); } function BarItemScanner() { @@ -69,7 +108,7 @@ function BarItemScanner() { }; return ( - + <> {statusMsg} - + ); }