Fix apt command

This commit is contained in:
ABelliqueux 2024-04-09 14:07:25 +02:00
parent 98c5007545
commit f8ca448056
3 changed files with 318 additions and 11 deletions

View File

@ -7,7 +7,7 @@
viewBox="0 0 297 210"
version="1.1"
id="svg5"
inkscape:version="1.2.1 (9c6d41e410, 2022-07-14)"
inkscape:version="1.2.1 (9c6d41e410, 2022-07-14, custom)"
xml:space="preserve"
sodipodi:docname="diagramme.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
@ -28,8 +28,8 @@
shape-rendering="auto"
showguides="true"
inkscape:zoom="1.1011145"
inkscape:cx="560.79545"
inkscape:cy="475.4274"
inkscape:cx="561.70362"
inkscape:cy="476.33557"
inkscape:window-width="1920"
inkscape:window-height="1043"
inkscape:window-x="0"
@ -294,12 +294,12 @@
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.23333px;font-family:Sans;-inkscape-font-specification:'Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;stroke:none;stroke-width:1.05833px"
x="182.77737"
y="170.53987"
id="tspan6454">- commandes systèmes (reboot, extinctions, clign.)</tspan><tspan
id="tspan6454">- commandes systèmes (reboot, extinction, clign.)</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.23333px;font-family:Sans;-inkscape-font-specification:'Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;stroke:none;stroke-width:1.05833px"
x="182.77737"
y="177.96199"
id="tspan6470">- synchro fichiers config, medias</tspan><tspan
id="tspan464">- synchro fichiers config, medias via http_upload</tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.23333px;font-family:Sans;-inkscape-font-specification:'Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;stroke:none;stroke-width:1.05833px"
x="182.77737"
@ -314,7 +314,7 @@
id="tspan6462"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.23333px;font-family:Sans;-inkscape-font-specification:'Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;stroke:none;stroke-width:1.05833px"
x="182.77737"
y="189.57613">(rsync ?) : </tspan><tspan
y="189.57613">rsync, scp : </tspan><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.23333px;font-family:Sans;-inkscape-font-specification:'Sans, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;fill:#000000;stroke:none;stroke-width:1.05833px"
x="182.77737"

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -99,8 +99,8 @@ fi
REMOTE_MEDIA_DIR="$ROOTFS_MOUNT/home/$PI_USER/Videos"
# WIFI AP config
IP_RANGE="10.42.0.1"
SSID="omen"
PASSWD="EpQmSmXH123"
SSID="foo"
PASSWD="bar"
IFW="wlo1"
#Band (bg = 2.4Ghz, a= 5Ghz)
BAND="bg"

View File

@ -43,6 +43,10 @@ echo 'options brcmfmac roamoff=1 feature_disable=0x82000' | sudo tee /etc/modpro
Ajouter les lignes suivantes au fichier `/boot/config.txt` :
```
#hdmi_force_hotplug=1
#hdmi_drive=2
# Forcer HDMI Full HD
hdmi_group=1
hdmi_mode=16 # fullHD@60
@ -176,9 +180,11 @@ echo -e "
## Limiter le nombre de paquets installés par APT
```
echo -e "APT::Get::Install-Recommends "false";\nAPT::Get::Install-Suggests "false";" | sudo tee -a /etc/apt/apt.conf
echo -e 'APT::Install-Suggests "0";\nAPT::Install-Recommends "0";' | sudo tee -a /etc/apt/apt.conf.d/80noclutter
```
## Rendre le démarrage du RPI complètement silencieux (écran noir)
### cmdline.txt
@ -186,7 +192,7 @@ echo -e "APT::Get::Install-Recommends "false";\nAPT::Get::Install-Suggests "fals
Editer le fichier `/boot/cmdline.txt` et ajouter les options suivantes à la fin de la première ligne:
```
console=tty3 loglevel=3 vt.global_cursor_default=0 logo.nologo consoleblank=1
console=tty3 loglevel=3 vt.global_cursor_default=0 logo.nologo quiet consoleblank=1
```
### Login silencieux
@ -674,3 +680,304 @@ sudo dkms install -m rtl8821cu -v 5.12.0 -k $kernel_version # rtl8192eu/1.0
# The module should loaded automatically but just if needed...
sudo modprobe 8821cu # 8192eu
```
## Udev & systemd - Running a graphic environment when a USB device is plugged in
## Summary :
At a GNU/Linux console prompt, no GUI.
When a USB device of type [HID](https://en.wikipedia.org/wiki/Human_interface_device) (keyboard/mouse mainly) is plugged in, we want the X server to start and launch VLC's graphical interface, fullscreen, no borders.
When this device is removed, VLC is shut down and the X server too, and we end up back at the console prompt.
### Proposed solution:
1. [Udev](https://wiki.archlinux.org/title/Udev) rules are triggered when the USB device is plugged/unplugged to create a file in '/tmp' named '.vlc_gui'.
2. A systemd [user](https://wiki.archlinux.org/title/Systemd/User) service starts a script on startup.
3. This script uses [inotifywait](https://man.archlinux.org/man/inotifywait.1) to monitor a file's creation/deletion in the '/tmp' folder, and act accordingly;
4. Start/close a minimal graphical environment with [openbox](http://openbox.org/) running [VLC](https://videolan.org).
## 1. Udev configuration
### Run script on USB HID (mouse/kb) connect
We want a rule that triggers when a device has SUBSYSTEM=="usb" and DRIVER=="usbhid".
In '/etc/udev/rules.d/01-vlc_gui.rules' :
```
# On plug
ACTION=="add" SUBSYSTEM=="usb", DRIVER=="usbhid", RUN+="/usr/bin/touch /tmp/.vlc_gui"
# On un-plug
ACTION=="remove" SUBSYSTEM=="usb", RUN+="/usr/bin/rm -f /tmp/.vlc_gui"
```
The rules above create a '.vlc_gui' file in '/tmp' when a usbhid device is plugged in, and removes it when unplugged.
### Change read permissions on tty7
By default, permissions on '/dev/tty*' are 0620 (`crw--w----`). So members of group `tty` can write, but not read to ttys.
This will be a problem for the X server, so we need to change those permissions to have read writes for our group too.
Let's change the permissions on the tty that we need to 0660 (`crw-rw----`) so that we can run our X session on it.
Inspect how udev sees your TTY (tty7 here):
`udevadm info --attribute-walk --path=/sys/class/tty/tty7`
```
looking at device '/devices/virtual/tty/tty7':
KERNEL=="tty7"
SUBSYSTEM=="tty"
DRIVER==""
ATTR{power/control}=="auto"
ATTR{power/runtime_active_time}=="0"
ATTR{power/runtime_status}=="unsupported"
ATTR{power/runtime_suspended_time}=="0
```
So we want a rule that matches 'KERNEL=="tty7"' and 'SUBSYSTEM=="tty"' and set it to mode '0660':
`SUBSYSTEM=="tty", KERNEL=="tty7", MODE:="0660"`
Notice the [immutable operator](https://www.freedesktop.org/software/systemd/man/udev.html#Operators) ":=" for "MODE"; it makes shure this won't be changed by another rule.
[Udev rules order read](https://forums.opensuse.org/t/udev-rules-priority-disallow-change-by-other-rules-with-operator/100210)
Test which rules are triggered by a specific device with :
`udevadm test /class/tty/tty7`
Reload and apply the new rules with :
```
udevadm control --reload-rules
udevadm trigger
```
Of course, don't forget to add your user to the 'tty' group :
`sudo adduser USERNAME tty`
On some system, you might have to use usermod :
`sudo usermod -a -G tty USERNAME`
then log out/in and check with `groups` that 'tty' appears in the listed groups.
## 2. Systemd user unit
We can create [user units](https://wiki.archlinux.org/title/systemd/User) in '~/.config/systemd/user/', e.g :
`nano ~/.config/systemd/user/vlc_gui.service`
```yaml
[Unit]
Description=VLC GUI launcher service
[Service]
# %h specifier resolves to user home (~ equivalent)
ExecStart="%h"/vlc_gui.sh
Restart=always
[Install]
WantedBy=default.target
```
Reload the units with `systemctl --user daemon-reload`
and start/enable the service with
`systemctl --user start vlc_gui.service` / `systemctl --user enable vlc_gui.service`.
More about systemd specifiers:
[https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers](https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers)
### Starting a user unit as root
If running [systemd version >= 248 (2021-03)](https://github.com/systemd/systemd/blob/28795f2c138203fb700fc394f0937708af886116/NEWS#L2809), you can [start a user unit as root](https://www.freedesktop.org/software/systemd/man/systemctl.html#-M), i.e ;
using `sudo systemctl` or in a root shell, with e.g:
`sudo systemctl --user --machine USERNAME@ start foo.service`
On prior versions, you have to use either
`su - USERNAME -c 'systemctl --user start foo.service'` or
`runuser -l USERNAME -c 'systemctl --user start foo.service'` instead.
## 3. inotifywait : watch for a file's creation/deletion
### Install the tool :
`sudo apt-get install inotify-tools`
### Create the script :
In '~/vlc_gui.sh' :
```bash
#!/usr/bin/env bash
inotifywait -m /tmp -e create -e delete |
while read directory action file; do
if [[ "$file" == ".vlc_gui" ]]; then
if [[ "$action" == "CREATE" ]]; then
echo "Starting VLC GUI."
# Start X environment on tty7
DISPLAY=:0 startx -- vt7 &
elif [[ "$action" == "DELETE" ]]; then
echo "Killing VLC GUI"
pkill vlc
fi
fi
done
```
Don't forget to set execution bit : `sudo chmod +x ~/vlc_gui.sh`
## 4. Minimal X environment & Launching VLC
Install the following packages :
`sudo apt-get install -y --no-install-recommends --no-install-suggests xinit xserver-xorg xserver-xorg-core xserver-xorg-input-evdev xserver-xorg-input-kbd openbox feh`
### Xinit config
We start the X environment with `startx`, which sources "~/.xinitrc".
Let's start openbox session there.
`cp /etc/X11/xinit/xinitrc ~/.xinitrc`
Then in "~/.xinitrc" :
```bash
#!/bin/sh
# /etc/X11/xinit/xinitrc
#
# global xinitrc file, used by all X sessions started by xinit (startx)
# invoke global X session script
. /etc/X11/Xsession
exec openbox-session
```
Set execution bit :
`sudo chmod +x ~/.xinitrc`
### Openbox configuration
Now Openbox config files are in '~/.config/openbox' and there are two of them :
#### autostart.sh
In '~/.config/openbox/autostart.sh' :
```bash
#!/bin/bash
# Exit openbox when VLC is closed
vlc --vout=gles2 && openbox --exit
# on rpi with 3d kms driver, can be --vout=drm_vout
```
Set execution bit :
`sudo chmod +x ~/.config/openbox/autostart.sh`
#### rc.xml
`cp /etc/xdg/openbox/rc.xml ~/.config/openbox/`
We want the VLC gui launching fullscreen, with no window decoration.
In openbox's [<applications\>](http://openbox.org/wiki/Help:Applications) section of '~/.config/openbox/rc.xml', l.656, add:
```markup
<application name="vlc" role="vlc-main">
<decor>no</decor>
<maximized>yes</maximized>
</application>
```
## Troubleshooting
### Udev rules
You can increase udev's log verbosity with `sudo udevadm control --log-priority=debug`
then run `journalctl -f` to see if an error message comes up when plugging/unplugging the USB HID.
### Xserver
You can see what's going on by launching `journalctl -f` in a SSH session, then plug/unplug the USB HID.
If you encounter an error with the X server complaining about permission to tty7 like this
```
(EE) xf86OpenConsole: Cannot open virtual console 7 (Permission denied)
```
try rebooting.
### Slow mouse cursor
If you experience laggy mouse cursor movements, you can try adding `usbhid.mousepoll=0` to '/boot/cmdline.txt'.
Other values you might want to try are :
| value | speed |
| :-: | :-: |
| 0 | device request |
| X | 1000/X Hz |
source: [https://peppe8o.com/fixing-slow-mouse-with-raspberry-pi-os/](https://peppe8o.com/fixing-slow-mouse-with-raspberry-pi-os/)
## Systemd unit : run unit every X seconds with timer
/etc/systemd/system/nvlc.service
/etc/systemd/system/nvlc.timer
In '.config/systemd/user/nvlc.service' :
```
[Unit]
Description=VLC Ncurse UI service
[Service]
Type=oneshot
#User=pil
WorkingDirectory=/home/pil/
ExecStart=/home/pil/vlc_gui.sh
#ExecStart=/usr/bin/nvlc -I ncurses --no-osd --file-caching=5000
[Install]
WantedBy=default.target
```
In '.config/systemd/user/nvlc.timer' :
```[Unit]
Description=NVLC test
[Timer]
OnUnitActiveSec=10s
OnBootSec=10s
[Install]
WantedBy=timers.target
```
then to start timer :
```
systemctl --user start nvlc.timer
```
list timers :
```
systemctl --user list-timers --all
```
## Timedate
To sync time/date , add dns to '/etc/resolv.conf', then
```
sudo timedatectl
```
systemd unit :
```
systemctl status systemd-timesyncd
```