post_install() {
    # Enable services
        systemctl enable stop-dmesg.service
    # Edit files
        # fix wifi
        sed -i s/'boardflags3=0x48200100'/'boardflags3=0x44200100'/ /usr/lib/firmware/updates/brcm/brcmfmac43455-sdio.txt
    # Edit mkinitcpio.conf
        echo "Editing mkinitcpio.conf..."
        sed -i s/"MODULES=()"/"MODULES=(vc4)"/g /etc/mkinitcpio.conf
        sed -i 's/kms //' /etc/mkinitcpio.conf
        sed -i 's/vc4//' /etc/mkinitcpio.conf
    # Edit cmdline.txt
        echo "Editing cmdline.txt..."
        sed -i s!"plymouth.enable=0"!"quiet splash plymouth.ignore-serial-consoles"!g /boot/cmdline.txt
        sed -i s!"console=tty1"!"console=tty3"!g /boot/cmdline.txt
    # Edit config.txt
        echo "Editing config.txt..."
        echo "disable_splash=1" >> /boot/config.txt
    # Disable AMS on installs with kwin
        if [ -f /usr/bin/kwin_x11 ]; then
            echo "KWIN_DRM_NO_AMS=1" >> /etc/environment
        fi
    # Add config file for pi5
    if [ ! -d /etc/X11/xorg.conf.d ]; then
    mkdir -p /etc/X11/xorg.conf.d/
    fi
    if [ ! -f /etc/X11/xorg.conf.d/99-v3d.conf ]; then
cat << EOF > /etc/X11/xorg.conf.d/99-v3d.conf
Section "OutputClass"
  Identifier "vc4"
  MatchDriver "vc4"
  Driver "modesetting"
  Option "PrimaryGPU" "true"
EndSection
EOF
    fi
}

post_upgrade() {
    # Edit mkinitcpio.conf
        echo "Editing mkinitcpio.conf..."
        sed -i 's/kms //' /etc/mkinitcpio.conf
        sed -i 's/vc4//' /etc/mkinitcpio.conf
    # Disable AMS on installs with kwin
        if [[ $(grep "KWIN_DRM_NO_AMS=1" /etc/environment) ]]; then
            echo "AMS already disabled..."
        elif [ -f /usr/bin/kwin_x11 ]; then
            echo "KWIN_DRM_NO_AMS=1" >> /etc/environment
            echo "Disabling AMS..."
        fi
    # Add config file for pi5
    if [ ! -d /etc/X11/xorg.conf.d ]; then
    mkdir -p /etc/X11/xorg.conf.d/
    fi
    if [ ! -f /etc/X11/xorg.conf.d/99-v3d.conf ]; then
cat << EOF > /etc/X11/xorg.conf.d/99-v3d.conf
Section "OutputClass"
  Identifier "vc4"
  MatchDriver "vc4"
  Driver "modesetting"
  Option "PrimaryGPU" "true"
EndSection
EOF
    fi
}
