#!/bin/bash
binder_ok=$( lsmod | grep binder_linux )
if [[ -z "$binder_ok" ]];then
binder_path=/usr/lib/modules/$( uname -r )/binder/binder_linux.ko
if [[ -e "$binder_path" ]];then
echo $binder_path
/usr/sbin/insmod $binder_path
else
echo "/usr/share/sa/binder_linux.ko"
/usr/sbin/insmod /usr/share/sa/binder_linux.ko
fi
chmod 666 /dev/binder
fi

ashmem_ok=$( lsmod | grep ashmem_linux )
if [[ -z "$ashmem_ok" ]];then
ashmem_path=/usr/lib/modules/$( uname -r )/ashmem/ashmem_linux.ko
if [[ -e "$ashmem_path" ]];then
echo $ashmem_path
/usr/sbin/insmod $ashmem_path
else
echo "/usr/share/sa/ashmem_linux.ko"
/usr/sbin/insmod /usr/share/sa/ashmem_linux.ko
fi
chmod 666 /dev/ashmem
fi

curdir=$( pwd )
cd /dev/input
cur_users=$( users )
arrrys=${cur_users// / }
for var in ${arrrys[@]}
do
    setfacl -m user:${var}:rw- /dev/dri/card0
    allfiles=$( dir )
    for file in ${allfiles[@]}
    do
        tmpfile=/dev/input/${file}
        if [[ ! -d "$tmpfile" ]];then
            setfacl -m user:${var}:rw- ${tmpfile}
        fi
    done

done
cd $curdir

