I have been tinkering with a bigger OPI zero 2w setup script for my “2005” TV streaming setup, including; xfce, pulseaudio, pavucontrol, x11vnc, Chromium adblock extension moonlight qt and a lot more!
To get to the point, I wanted it all automated. The injection sadly broke the automation and I asked AI how it could be done differently.
Not sure if the sleep is necessary, but it works for me every single time
— Wait for /boot/dietpiEnv.txt to be ready —
echo “Waiting for /boot/dietpiEnv.txt to be ready…”
while [ ! -r /boot/dietpiEnv.txt ]; do
sleep 1
done
sleep 2 # extra buffer time
sed -i ‘s/^user_overlays=.*/user_overlays=sound-hdmi-jack-i2s0-hat/’ /boot/dietpiEnv.txt
IA is a bad companion for who search to go further
If you have a look at the end of the Dietpi-globals function, you can
understand why it’s better to use G-config-inject function for login
and password instead to use the sed command
see here for more detail dietpi-globals on github’s Michaing
The question is how implement the G-* command in your script
i search for mine too
It is a bash script, so you need to execute it with bash. sh is bourne shell, dash practically on Debian.
Or you just add a shebang #!/bin/bash as first line, make it executable, and execute it directly.
Btw, at which point is this script needed? /boot/dietpiEnv.txt should always exist .
G_CONFIG_INJECT is mainly useful in cases where you do not know whether the setting key is present in a config file already or not, or whether it is commented:
If the setting is present already, it just updates it.
If the setting is present, but commented, like #user_overlays=foo, it us uncommented and updated.
If the setting is not present, it is added to the end of the file, optionally after a specific line matched with an optional 4th argument.
And it has some more options, e.g. to mask passwords from terminal output, which it produces about what is done, useful for our scripts for transparency.
In this particular case: user_overlays is present in all recent DietPi images, to a sed like you did should work as well.