#cloud-config

name: "RPI configs"
stages:
  initramfs.before:
    # set a safe "near" date as default for rpi + alpine without rtc clock as otherwise
    # the swclock doesnt work as expected and we create a lot of files with their dates at unix epoch
    # which can lead to wrong calculations (days since login for example)
    # later in the boot process ntpd or other software clocks will trigger and update the date
    - name: "Set a safe date before user creation for RPI without hardware clocks"
      if: '[ -f "/sbin/openrc" ] && [ -f "/proc/device-tree/model" ] && grep -i "Raspberry Pi" "/proc/device-tree/model"'
      commands:
        - date -s "2006-08-14 02:34:56-06:00"
  rootfs.after:
    # Automatically expand persistent partition on Raspberry Pi 4
    - if: '[ ! -f /run/cos/recovery_mode ] && [ ! -f /run/cos/live_mode ] && [ -f "/sys/firmware/devicetree/base/model" ] && grep -i "Raspberry Pi 4" "/sys/firmware/devicetree/base/model"'
      name: "Grow persistent"
      layout:
        device:
          label: COS_PERSISTENT
        expand_partition:
          # Size 0 is required to specify all remaining space
          size: 0
