#!/bin/bash

apt install --reinstall astra-plasma-mobile-configs
genfly-dmconf

if [[ $(astra-modeswitch get) != "2" ]]; then
    sed -i "s/UserList=.*/UserList=true/" "$CHROOT_DIR"/etc/X11/fly-dm/fly-dmrc
    sed -i "s/PreselectUser=.*/PreselectUser=Previous/" "$CHROOT_DIR"/etc/X11/fly-dm/fly-dmrc
fi

/usr/sbin/astra-mobile-rootfs-update
/usr/sbin/set_wait_timeout.sh
/usr/sbin/astra-mobile-hardware-tuning-host

sudis_check=$(dpkg -l | grep -i "fly_dmgreet_sudis")
if [ ! -z "$sudis_check" ]; then
    if [ ! -z /var/lib/dpkg/info/fly_dmgreet_sudis.postinst ]; then
        /var/lib/dpkg/info/fly_dmgreet_sudis.postinst
    fi
fi

MACHINE_TYPE=""
if [ -e /etc/astra/machine_type ]; then
    MACHINE_TYPE=`cat /etc/astra/machine_type | head -1 | tr -s ' '`
    echo "astra-mobile: detected machine type $MACHINE_TYPE"
fi

if [[ $MACHINE_TYPE == *"KVADRAT.arm64.v1.rev1"* ]]; then
    apt install -qq librockchip-mpp1 librockchip-vpu0 libv4l-rkmpp
fi
