#!/bin/sh
# stdin: default config
# stdout: modified config
set -e

# save stdin in variable
stdin="$(cat)"

# assert HOOKS is as expected
echo "$stdin" | grep --quiet '^HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)'

# assert no COMPRESSION option is enabled yet
! echo "$stdin" | grep --quiet '^COMPRESSION='

# assert lz4 COMPRESSION is uncommented
echo "$stdin" | grep --quiet '^#COMPRESSION="lz4"'

# note: MODULES is also modified by de-p1st-gpu-*

# 1) add to start of MODULES array; 2 replace HOOKS; 3) uncomment lz4 COMPRESSION
echo "$stdin" | sed '
  s|^MODULES=(|MODULES=(crc32c-intel |;
  s|^#COMPRESSION="lz4".*$|COMPRESSION="lz4"|;
  s|^HOOKS=(.*$|HOOKS=(base udev modconf block keyboard keymap encrypt lvm2 btrfs filesystems fsck resume)|
  '