Last active
August 27, 2024 19:59
-
-
Save fabiojmendes/0016cd7cc536173e1b60b01e84ab1165 to your computer and use it in GitHub Desktop.
Update headless raspberry pi using a script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Update script for headless pi | |
# Add these options to the end of cmdline.txt file | |
# systemd.run=/boot/firmware/update.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target | |
set -euo pipefail | |
# Remove options from cmdline for normal reboot | |
cleanup() { | |
exit_code=$? | |
sed -i 's/systemd.*//g' /boot/firmware/cmdline.txt | |
exit $exit_code | |
} | |
trap cleanup EXIT | |
CONN_NAME=foo | |
SSID=bar | |
PASSWORD=foobar | |
umask 177 | |
cat <<EOF >/etc/NetworkManager/system-connections/$CONN_NAME.nmconnection | |
[connection] | |
id=$CONN_NAME | |
uuid=$(uuid) | |
type=wifi | |
[wifi] | |
mode=infrastructure | |
ssid=$SSID | |
hidden=false | |
[ipv4] | |
method=auto | |
[ipv6] | |
addr-gen-mode=default | |
method=auto | |
[proxy] | |
[wifi-security] | |
key-mgmt=wpa-psk | |
psk=$PASSWORD | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment