summaryrefslogtreecommitdiff
path: root/roles/raspios/image/templates/firstrun.sh.j2
blob: 93aa3483a610ce84af6ace11a3821e46d0f9ad71 (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
37
38
39
40
41
42
43
44
45
46
#!/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
systemctl restart dhcpcd.service
{% 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

export DEBIAN_FRONTEND=noninteractive
dpkg -P userconf-pi
systemctl disable hciuart.service

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
rm -f /etc/sudoers.d/010_pi-nopasswd
rm -f /etc/apt/sources.list.d/vscode.list
rm -f /etc/apt/trusted.gpg.d/microsoft.gpg

apt-get update -q
apt-get upgrade -y -q