#!/bin/bash

if [[ `id -u` != 0 ]]; then
    echo "Script will work only with root rights"
    exit 1
fi

# apps default fix orientation
WAYDROID_ORIENTATION_CONFIG='
[APPORIENTATION]
WaydroidDefaultOrientation=4
# Сканер ГИБДД (Принудительный портретный режим под поворот камеры)
waydroid.ru.ppr.mpauto=1
# Дефолтная камера (Принудительный портретный режим под поворот камеры)
waydroid.com.android.camera2=1
'

sed -i '/\[APPORIENTATION\]/d' /etc/xdg/plasmamobilerc
sed -i '/WaydroidDefaultOrientation=*/d' /etc/xdg/plasmamobilerc
echo "$WAYDROID_ORIENTATION_CONFIG" >> /etc/xdg/plasmamobilerc

#default orientation
sed -i "s/rotation\": 8/rotation\": 2/" /usr/share/kscreen/generic-config
sed -i "s/DSI-1/eDP-1/" /usr/share/kscreen/generic-config

kwriteconfig5 --file /etc/xdg/kdeglobals --group KScreen --key ScaleFactor 1
kwriteconfig5 --file /etc/xdg/kdeglobals --group KScreen --key ScreenScaleFactors eDP-1=1

# udev rule
echo "ENV{IIO_SENSOR_PROXY_TYPE}==\"*accel*\", ENV{ACCEL_MOUNT_MATRIX}=\"0,-1,0;-1,0,0;0,0,1\"" > /etc/udev/rules.d/99-astra-mobile-orientation.rules
echo >> /etc/udev/rules.d/99-astra-mobile-orientation.rules

echo 'Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "Goodix Capacitive TouchScreen"
        Option  "Calibration"   "0 1200  0 1920"
        Option "TransformationMatrix"  "0 -1 1 1 0 0 0 0 1"
EndSection

' > /etc/X11/xorg.conf.d/99-calibration.conf

sed -i "s/normal/left_side_up/g" /etc/default/grub
/usr/sbin/update-grub
