include: - .base system_bootloader_pkgs: pkg.installed: - pkgs: - grub - grub-efi - mkinitfs - mkinitfs-doc - efibootmgr {% set CURRENT_SUBVOLUME_TIMESTAMP = salt['cmd.shell']('CURRENT_SUBVOLUME=$(LC_ALL=C btrfs sub show / | LC_ALL=C grep Name: | tr -d \'[:space:]\'); TIMESTAMP_FORMAT=\'[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}_[[:digit:]]{2}-[[:digit:]]{2}-[[:digit:]]{2}\'; echo "$CURRENT_SUBVOLUME" | grep -Eo "$TIMESTAMP_FORMAT"') %} {% set CURRENT_SUBVOLUME_TIMESTAMP_HUMAN = salt['cmd.shell']('CURRENT_SUBVOLUME_TIMESTAMP=\'' + CURRENT_SUBVOLUME_TIMESTAMP + '\'; echo "${CURRENT_SUBVOLUME_TIMESTAMP:0:10} ${CURRENT_SUBVOLUME_TIMESTAMP:11:2}:${CURRENT_SUBVOLUME_TIMESTAMP:14:2}"') %} {% set KERNEL_VERSION = salt['cmd.shell']('uname -r') %} system_bootloader_install: cmd.run: - name: "grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=alpine-{{ CURRENT_SUBVOLUME_TIMESTAMP }}" - require: - system_bootloader_pkgs system_bootloader_grub_dir: file.directory: - name: /efi/grub - makedirs: true - user: root - group: root - mode: '0755' - require: - system_bootloader_pkgs - system_bootloader_install system_bootloader_mkinitfs_conf: file.keyvalue: - name: /etc/mkinitfs/mkinitfs.conf - key_values: features: '"ata base cdrom ext4 btrfs keymap kms mmc nvme raid scsi usb virtio"' - separator: '=' - uncomment: '# ' - key_ignore_case: false - value_ignore_case: false - append_if_not_found: true - require: - system_base_pkgs - system_bootloader_pkgs system_bootloader_os-release: file.keyvalue: - name: /etc/os-release - key_values: VERSION_ID: '"Timestamp: {{ CURRENT_SUBVOLUME_TIMESTAMP_HUMAN }} | Kernel: {{ KERNEL_VERSION }}"' - separator: '=' - uncomment: '# ' - key_ignore_case: False - append_if_not_found: True system_bootloader_menuentry: file.blockreplace: - name: /etc/grub.d/40_custom - marker_start: "#!/bin/sh" - marker_end: "# the 'exec tail' line above." - source: salt://{{ tpldir }}/files/bootloader_menuentry - template: jinja - context: CURRENT_SUBVOLUME_TIMESTAMP_HUMAN: {{ CURRENT_SUBVOLUME_TIMESTAMP_HUMAN }} CURRENT_SUBVOLUME_TIMESTAMP: {{ CURRENT_SUBVOLUME_TIMESTAMP }} - prepend_if_not_found: true - require: - system_base_pkgs - system_bootloader_pkgs system_bootloader_menuentry_clean: file.replace: - name: /etc/grub.d/40_custom - pattern: {{ "# the 'exec tail' line above." | regex_escape }} - repl: null - require: - system_bootloader_menuentry system_bootloader_config: cmd.run: - name: 'grub-mkconfig -o /efi/grub/grub.cfg' - require: - system_bootloader_pkgs - system_bootloader_install - system_bootloader_grub_dir - system_bootloader_menuentry_clean system_bootloader_remove_default_menuentry: file.blockreplace: - name: /efi/grub/grub.cfg - marker_start: "### BEGIN /etc/grub.d/10_linux ###" - marker_end: "### END /etc/grub.d/10_linux ###" - content: null - require: - system_bootloader_install - system_bootloader_config