summaryrefslogtreecommitdiff
path: root/roles
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2024-03-09 04:37:29 +0100
committerChristian Pointner <equinox@spreadspace.org>2024-03-09 04:37:29 +0100
commit2f548a512345e9208991219443315df305724997 (patch)
treea996a155bdcf142a2cae319231cf1fcd67e2789f /roles
parentadd ch-zimablade (diff)
raspios: add support for bookworm
Diffstat (limited to 'roles')
-rw-r--r--roles/raspios/image/filter_plugins/main.py43
-rw-r--r--roles/raspios/image/tasks/fetch.yml7
-rw-r--r--roles/raspios/image/tasks/main.yml14
-rw-r--r--roles/raspios/image/templates/firstrun.sh.j263
4 files changed, 73 insertions, 54 deletions
diff --git a/roles/raspios/image/filter_plugins/main.py b/roles/raspios/image/filter_plugins/main.py
index a8086f66..5ac2d5ab 100644
--- a/roles/raspios/image/filter_plugins/main.py
+++ b/roles/raspios/image/filter_plugins/main.py
@@ -6,42 +6,32 @@ from ansible import errors
from urllib.parse import urlparse, urlunparse
-def raspios_extract_download_base_url(os_list, variant, codename, arch):
- try:
- os_name = 'Raspberry Pi OS '
- if variant != 'desktop':
- os_name += '%s ' % variant.capitalize()
- os_name += {'armhf': '(32-bit)', 'arm64': '(64-bit)'}[arch]
+def _raspios_extract_latest_image_download_url_recursive(items, image_name_suffix):
+ for item in items:
+ if not item['name'].startswith('Raspberry Pi OS '):
+ continue
- for item in os_list:
- if item['os_name'] != os_name:
+ if 'url' in item:
+ result = urlparse(item['url'])
+ if not os.path.basename(result.path).endswith(image_name_suffix):
continue
- if item['version'] != codename:
- continue
- result = urlparse(item['os_info'])
- result = result._replace(path=os.path.dirname(result.path))
- return urlunparse(result)
- except Exception as e:
- raise errors.AnsibleFilterError("raspios_extract_download_base_url(): %s" % str(e))
- raise errors.AnsibleFilterError("unable to find base url for: %s / %s / %s" % (variant, codename, arch))
-
-
-def _raspios_extract_latest_image_download_url_recursive(items, base_url):
- base_url = base_url.replace('http://', 'https://')
- for item in items:
- if 'url' in item and item['url'].replace('http://', 'https://').startswith(base_url):
- return item['url']
+ return urlunparse(result)
if 'subitems' in item:
- result = _raspios_extract_latest_image_download_url_recursive(item['subitems'], base_url)
+ result = _raspios_extract_latest_image_download_url_recursive(item['subitems'], image_name_suffix)
if result:
return result
return None
-def raspios_extract_latest_image_download_url(os_list, base_url):
+def raspios_extract_latest_image_download_url(os_list, variant, codename, arch):
try:
- result = _raspios_extract_latest_image_download_url_recursive(os_list, base_url)
+ image_name_suffix = 'raspios-%s-%s' % (codename, arch)
+ if variant != 'desktop':
+ image_name_suffix += '-%s' % variant
+ image_name_suffix += '.img.xz'
+
+ result = _raspios_extract_latest_image_download_url_recursive(os_list, image_name_suffix)
if result:
return result
@@ -54,7 +44,6 @@ def raspios_extract_latest_image_download_url(os_list, base_url):
class FilterModule(object):
filter_map = {
- 'raspios_extract_download_base_url': raspios_extract_download_base_url,
'raspios_extract_latest_image_download_url': raspios_extract_latest_image_download_url,
}
diff --git a/roles/raspios/image/tasks/fetch.yml b/roles/raspios/image/tasks/fetch.yml
index b9294415..c58b647c 100644
--- a/roles/raspios/image/tasks/fetch.yml
+++ b/roles/raspios/image/tasks/fetch.yml
@@ -7,12 +7,15 @@
- name: fetch imageutility os list from download server
check_mode: no
uri:
- url: "{{ raspios_download_url }}/os_list_imagingutility_v3.json"
+ url: "{{ raspios_download_url }}/os_list_imagingutility_v4.json"
body_format: json
register: raspios_os_list_imagingutility
- set_fact:
- raspios_download_url_image: "{{ raspios_os_list_imagingutility.json.os_list | raspios_extract_latest_image_download_url(raspios_download_base_url) }}"
+ raspios_download_url_image: "{{ raspios_os_list_imagingutility.json.os_list | raspios_extract_latest_image_download_url(raspios_variant, raspios_codename, raspios_arch) }}"
+
+- debug:
+ var: raspios_download_url_image
- name: download the raspios image
block:
diff --git a/roles/raspios/image/tasks/main.yml b/roles/raspios/image/tasks/main.yml
index b6a56bd2..b8296f9a 100644
--- a/roles/raspios/image/tasks/main.yml
+++ b/roles/raspios/image/tasks/main.yml
@@ -5,16 +5,6 @@
that:
- "'raspios' in group_names"
-- name: fetch os list from download server
- check_mode: no
- uri:
- url: "{{ raspios_download_url }}/os_list_v3.json"
- body_format: json
- register: raspios_os_list
-
-- set_fact:
- raspios_download_base_url: "{{ raspios_os_list.json.os_list | raspios_extract_download_base_url(raspios_variant, raspios_codename, raspios_arch) }}"
-
- name: fetch base image
run_once: true
import_tasks: fetch.yml
@@ -83,9 +73,9 @@
- name: edit boot/cmdline.txt
lineinfile:
path: "{{ raspios_image_mount_point }}/cmdline.txt"
- regexp: '^(.*)( systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target)?(.*?)$'
+ regexp: '^(.*)( systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.run_failure_action=none systemd.unit=kernel-command-line.target)?(.*?)$'
backrefs: yes
- line: '\1 systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target \3'
+ line: '\1 systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.run_failure_action=none systemd.unit=kernel-command-line.target \3'
always:
- name: unmount image
diff --git a/roles/raspios/image/templates/firstrun.sh.j2 b/roles/raspios/image/templates/firstrun.sh.j2
index d5e72fcc..9e398751 100644
--- a/roles/raspios/image/templates/firstrun.sh.j2
+++ b/roles/raspios/image/templates/firstrun.sh.j2
@@ -1,6 +1,12 @@
#!/bin/bash
set +e
+if [ -x /usr/lib/raspberrypi-sys-mods/get_fw_loc ]; then
+ FW_LOC=$(/usr/lib/raspberrypi-sys-mods/get_fw_loc)
+else
+ FW_LOC=/boot
+fi
+
raspi-config nonint do_hostname "{{ host_name }}"
echo "{{ host_name }}" > /etc/hostname
raspi-config nonint do_change_locale "{{ raspios_locale }}"
@@ -10,7 +16,8 @@ raspi-config nonint do_configure_keyboard "{{ raspios_keyboard_layout }}"
{# 0 -> predictable interface names, 1 -> legacy (eth0...) #}
raspi-config nonint do_net_names 1
-{% if not (install_dhcp | default(false)) %}
+{% if raspios_codename == 'bullseye' %}
+{% if not (install_dhcp | default(false)) %}
cat <<EOF >> /etc/dhcpcd.conf
#
@@ -20,39 +27,69 @@ static routers={{ network.primary.gateway }}
static domain_name_servers={{ network.nameservers | join(' ') }}
EOF
systemctl restart dhcpcd.service
+{% endif %}
+systemctl disable hciuart.service
+{% if 'wifi' in network.primary %}
+raspi-config nonint do_wifi_ssid_passphrase "{{ network.primary.wifi.ssid }}" "{{ network.primary.wifi.key }}"
+raspi-config nonint do_wifi_country "AT"
+{% else %}
+systemctl disable wpa_supplicant.service
+{% endif %}
+{% else %}
+cat <<EOF >> /etc/network/interfaces
+
+auto {{ network.primary.name }}
+{% if (install_dhcp | default(false)) %}
+iface {{ network.primary.name }} inet dhcp
+{% else %}
+iface {{ network.primary.name }} inet static
+ address {{ network.primary.address | ansible.utils.ipaddr('address') }}
+ netmask {{ network.primary.address | ansible.utils.ipaddr('netmask') }}
+ gateway {{ network.primary.gateway }}
+{% endif %}
+{% if 'wifi' in network.primary %}
+ wpa-ssid {{ network.primary.wifi.ssid }}
+ wpa-psk {{ network.primary.wifi.key }}
+{% endif %}
+EOF
+{% if not (install_dhcp | default(false)) %}
+cat <<EOF > /etc/resolv.conf
+# Generated by ansible
+search {{ network.domain }}
+{% for nameserver in network.nameservers %}
+nameserver {{ nameserver }}
+{% endfor %}
+EOF
+{% endif %}
+systemctl disable wpa_supplicant.service
+rfkill unblock wlan
+ifup {{ network.primary.name }}
{% endif %}
{% if ansible_port != 22 %}
sed -e 's/^\s*#*\s*Port\s\s*[0-9][0-9]*$/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
+install -m 0644 "$FW_LOC/firstrun.authorized_keys" /root/.ssh/authorized_keys
{# 0 -> enable ssh, 1 -> disable ssh #}
raspi-config nonint do_ssh 0
-systemctl disable hciuart.service
-{% if 'wifi' in network.primary %}
-raspi-config nonint do_wifi_ssid_passphrase "{{ network.primary.wifi.ssid }}" "{{ network.primary.wifi.key }}"
-raspi-config nonint do_wifi_country "AT"
-{% else %}
-systemctl disable wpa_supplicant.service
-{% endif %}
export DEBIAN_FRONTEND=noninteractive
export SUDO_FORCE_REMOVE=yes
apt-get purge -q -y userconf-pi avahi-daemon triggerhappy rsync dpkg-dev patch gdb make strace ssh-import-id network-manager udisks2 p7zip p7zip-full sudo
apt-get autoremove -q -y
dpkg -l | grep "^rc" | awk "{ print(\$2) }" | xargs -r dpkg -P
-sed 's#systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target##' -i /boot/cmdline.txt
+sed 's#systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.run_failure_action=none 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 "$FW_LOC/firstrun.authorized_keys"
+rm "$FW_LOC/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
+apt-get dist-upgrade -y -q
{# B1 -> Console, B2 -> console autologin, B3 -> desktop, B4 -> desktop autologin #}
raspi-config nonint do_boot_behaviour B1