summaryrefslogtreecommitdiff
path: root/roles/raspios/image/templates/firstrun.sh.j2
blob: c91c952f1cf3f4dc123bf472f6f77f677ccfd8e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
set +e

{# https://loganmarchione.com/2021/07/raspi-configs-mostly-undocumented-non-interactive-mode/ #}

raspi-config nonint do_hostname "{{ host_name }}"
raspi-config nonint do_change_locale "{{ raspios_locale }}"
raspi-config nonint do_change_timezone "{{ raspios_timezone }}"
raspi-config nonint do_configure_keyboard "{{ raspios_keyboard_layout }}"

{# 0 -> predictable interface names, 1 -> legacy (eth0...) #}
raspi-config nonint do_net_names 0
{% if not (install_dhcp | default(false)) %}
cat <<EOF >> /etc/dhcpcd.conf

#
interface eth0
static ip_address={{ network.primary.address }}
static routers={{ network.primary.gateway }}
static domain_name_servers={{ network.nameservers | join(' ') }}
EOF
{% endif %}

{% if ansible_port != 22 %}
sed -e 's/^#*Port .*$/Port {{ ansible_port }}/' -i /etc/ssh/sshd_config
{% endif %}
install -m 0700 -d /root/.ssh
install -m 0644 /boot/firstrun.authorized_keys /root/.ssh/authorized_keys
{# 0 -> enable ssh, 1 -> disable ssh #}
raspi-config nonint do_ssh 0

DEBIAN_FRONTEND=noninteractive dpkg -P userconf-pi
sed 's#systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target##' -i /boot/cmdline.txt
sed 's#\s*$##' -i /boot/cmdline.txt
rm /boot/firstrun.authorized_keys
rm /boot/firstrun.sh