[Request] Wifi settings change on boot

Hello,

How can I change WiFi settings on a system running without monitor,keyboard, etc?
For example, WiFi radio made from RPi+DietPi worked fine in my house, then I give it to my friend (another wifi network). But he is not familiar with Linux and SSH, all he need is radio working with his Wifi spot.
Maybe he will give radio to someone else later, and I can not change ssid settings every time for every user.

So how can I program simple replace of /etc/network/interfaces file on boot, or there is another way exists?

(sorry for poor English, I’m russian)

Although you mentioned the system will be headless. For the sake of simplicity, when your friend runs the Pi for the 1st time, just plug a keyboard + Monitor in, then run

dietpi-config 8 1

Select Wifi, then scan and connect, exit, job done :slight_smile:

If you want to automate the modifications to your /etc/network/interfaces file on boot, you would need to create a script during boot phase that reads a file/settings from /boot (fat partition on sd), then modifies the /etc/network/interfaces file before network is loaded.

RPi is inside of radio case, with many soldered wires, and it’s impossible to attach monitor to it.

I’m talking about automation. Where can I write command to execute bash script (python will be better) on system boot? I read about udev rules, created one (created additional file), but it does not works. Whether there are other ways to run my script? - I want to detect plugged usb stick, read file from it, and copy that file to /etc/network/
So, first run will be with wrong wifi settings, than I’m insert usb stick, replace interfaces file, and second start gonna be ok. Is it correct way?

You can also change the dietpi.txt in the root of the SDCard. It has WiFi settings there.

Dietpi.txt works on first boot, as I know

There is a few ways to do what you need:
The easiest would be to add your script to /etc/rc.local. As this runs last, you would need to code a system that disconnects the wifi, changes /etc/network/interfaces and reconnects wifi (eg: ifdown wlan0 & ifup wlan0).

If you want to do this as as service, on wheezy, here is an example service: https://github.com/Fourdee/DietPi/blob/master/dietpi/conf/dietpi-service. You would be best to run your script before $network. This way you can just modify the /etc/network/interfaces file

Jessie, you can use systemd. Here is an example service:
You would be best to run your script before network, i believe its network-pre.target. This way you can just modify the /etc/network/interfaces file. You can simply use ExecStart=/My/Script.sh

cat << _EOF_ > /etc/systemd/system/dietpi-service.service
[Unit]
Description=DietPi Bootup and Shutdown Service
Before=network-pre.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/DietPi/dietpi/conf/dietpi-service start
ExecStop=/DietPi/dietpi/conf/dietpi-service stop
StandardOutput=tty

[Install]
WantedBy=multi-user.target
_EOF_
systemctl enable dietpi-service
systemctl daemon-reload

As for waiting for a USB device to be connected, you would need to run a while loop. Example:
https://github.com/Fourdee/DietPi/blob/master/dietpi/dietpi-external_drive_setup#L41-L53. You would be best waiting for a UUID rather than /dev/sda

Correct.