Commit ff56ce42 authored by Jakob Moser's avatar Jakob Moser
Browse files

Merge branch 'auto-charge' into 'master'

Allow to automatically deposit into (i.e. re-charge) accounts by bank transactions

See merge request !38
parents 32e75bca b87a7804
Loading
Loading
Loading
Loading
Loading

.coveragerc

0 → 100644
+6 −0
Original line number Diff line number Diff line
[run]
command_line=-m pytest --junit-xml=testresults.xml tests
source=.

[report]
precision=2
 No newline at end of file

.gitlab-ci.yml

0 → 100644
+42 −0
Original line number Diff line number Diff line
lint-python:
    image: ghcr.io/astral-sh/uv:python3.12-bookworm
    stage: test
    before_script:
        - uv sync --locked
    script:
        - uv run ruff check .
        - uv run ruff format --check .
    allow_failure: true

typecheck-python:
    image: ghcr.io/astral-sh/uv:python3.12-bookworm
    stage: test
    before_script:
        - uv sync --locked
    script:
        - uv run mypy --strict . --cobertura-xml-report .mypycoverage --junit-xml typecheckresults.xml --junit-format per_file
    allow_failure: true
    artifacts:
        when: always
        reports:
            coverage_report:
                coverage_format: cobertura
                path: .mypycoverage/cobertura.xml
            junit: typecheckresults.xml

test:
    image: ghcr.io/astral-sh/uv:python3.12-bookworm
    stage: test
    before_script:
        - uv sync --locked
    script:
        - uv run coverage run
        - uv run coverage report
        - uv run coverage xml
    coverage: '/TOTAL .* (\d{1,3}.\d{2})%/'
    artifacts:
        reports:
            coverage_report:
                coverage_format: cobertura
                path: coverage.xml
            junit: testresults.xml
+8 −5
Original line number Diff line number Diff line
@@ -249,14 +249,17 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync --locked # to explicitly install dependencies now
```

As last step, deploy the systemd unit:
As last step, deploy the systemd units:

```bash
sudo cp /coli/poolpay/poolpay.service /etc/systemd/system
sudo systemctl enable poolpay
```
sudo cp /coli/poolpay/units/poolpay.service /etc/systemd/system
sudo cp /coli/poolpay/units/poolpay-ingest.service /etc/systemd/system

sudo cp /coli/poolpay/units/coli-usbee.mount /etc/systemd/system
sudo cp /coli/poolpay/units/coli-usbee.automount /etc/systemd/system

Reboot. The application should start automatically.
sudo systemctl enable --now poolpay poolpay-ingest coli-usbee.automount
```

You could now also launch tools, e.g., the card interfacing tool:

docs/deposits.md

0 → 100644
+22 −0
Original line number Diff line number Diff line
# How to deposit money

## User perspective

If you want to update the balance of your account on the PoolPayPi, send money to the IBAN in the pool (make sure you use the “Aufladen” purpose, otherwise, the money won't be added to your balance).

Then, be patient for a few days. The PoolPayPi is not connected to the internet for security purposes, so someone will need to manually transfer the deposits to the Pi via a USB stick.

## Gopher perspective

You will be granted access to the `c2` repository. It's contents are contained at root level on a USB stick. To transfer deposits to the Pi, do the following:

1. Take the USBee stick out of the Raspberry Pi.
2. Plug it into your computer.
3. Run `git pull` in the `c2` repo.
4. Take the USBee stick out of your computer.
5. Plug it into the Raspberry Pi.
6. That's it.

## Troubleshooting

Contact the maintainer (listed in [README.md](../README.md)).

docs/mount.md

0 → 100644
+126 −0
Original line number Diff line number Diff line
[Answer to: “How to execute a script after every systemd automount?”](https://unix.stackexchange.com/a/806542/246626), posted by [TuringTux](https://unix.stackexchange.com/users/246626/turingtux), [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/), reproduced here for the purposes of archiving.

---

My requirements were as follows: 

**Any time a partition becomes available at `/dev/sdb1`¹, it should be mounted to `/mnt`², and then a script should be executed.**

This is, sadly, not entirely what you needed, as I only care about the first partition on the device, not all, but maybe my solution can be generalized. 

Everything was tested on Manjaro KDE, with KDE's automount option disabled in the System Settings.

# Units to create

The units are all stored in `/etc/systemd/system`. 

## `mnt.mount`

_See also: [systemd.mount](https://www.freedesktop.org/software/systemd/man/latest/systemd.mount.html)_

Adjust `mnt` to your mountpoint. The mount point `/home/turingtux` would require the unit file name `home-turingtux.mount`.

```
[Unit]
Description=Mount point for the first partition of my USB stick

[Mount]
What=/dev/sdb1
Where=/mnt
```

Tips:

* You can list all mounts using `sudo systemctl list-units --type=mount --all`

## `mnt.automount`

_See also: [systemd.automount](https://www.freedesktop.org/software/systemd/man/latest/systemd.automount.html)_

Adjust `mnt` to your mountpoint. The mount point `/home/turingtux` would require the unit file name `home-turingtux.mount`.

```
[Unit]
Description=Automatically mount USB stick if accessed

[Automount]
Where=/mnt

[Install]
WantedBy=default.target
```

Enable it:

```bash
sudo systemctl enable --now mnt.automount
```

Tips:

* You can set (e.g.) `TimeoutIdleSec=5min` for systemd to automatically dismount again once the mount has become idle for long enough.
* You can list all automounts using `sudo systemctl list-units --type=automount --all`.

## `myscript.service`

_See also: [systemd.service](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html)_

You can give that any arbitrary name, this is just a “normal” systemd service.

```
[Unit]
Description=Execute a script of your choice once the USB stick is mounted

[Service]
Type=oneshot
ExecStart=/home/turingtux/somescript.sh

[Install]
WantedBy=dev-sdb1.device
```

Enable it:

```
sudo systemctl enable --now myservice
```

* You can list all device units to pick the one you want to depend on using `sudo systemctl list-units --type=device --all`.
* See the docs: [systemd.device](https://www.freedesktop.org/software/systemd/man/latest/systemd.device.html).
* For a oneshot service, you can put multiple `ExecStart=` lines if you want to run multiple commands.

# Test that it works

## Mount unit

You can test that it works (if you have a USB stick plugged in) by executing:

```bash
sudo systemctl start mnt.mount
ls /mnt
sudo systemctl stop mnt.mount
```

## Automount unit

Make sure the USB stick is dismounted. Run:

```bash
ls /mnt
```

It should block. Plug in the USB stick. It should take maybe a second, after which the command will return with the contents of the USB stick.

# The idea behind it

The automount unit makes sure that if _something tries to access `/mnt`_, `/dev/sdb1` will be mounted.

The mount unit is a required dependency of the automount unit (this is just how systemd does things).

The service unit, by depending on a device unit, makes sure that if `/dev/sdb1` becomes available, _something tries to access `/mnt`_.

---

¹ This is mostly be equivalent to “any time a USB stick is plugged in”, with a few caveats: Any block storage device counts, so a USB hard drive would also be counted, or if your computer has hot-swappable SATA drives and you plug one in, that would be counted... Also, this assumes that by default, `/dev/sda` is the last existing device (this is the case on many computers, but depending on the amount of preinstalled hard drives, it might be different in your case).

² Other directories are of course also possible.
 No newline at end of file
Loading