#!/bin/bash

#get user from /var/lib/fly-dm/fly-dmsts and use his kscreend config
users=`cat /var/lib/fly-dm/fly-dmsts | cut -d = -f2  2> /dev/null | tr '\n' ';' | tr '[' 'a' | tr ']' 'a'`
save_IFS="$IFS"
IFS=';'
for user_i in ${users}; do
  if [ ${user_i} = "aPrevUsera" ]; then
    continue
  fi
  if [ ${user_i} = "root" ]; then
    USER_HOME=/root
  else
    USER_HOME=/home/${user_i}
  fi
# echo user_home=$USER_HOME

  if [ -d $USER_HOME/.local/share/kscreen ]; then
    DM_HOME=/var/lib/fly-dm
    if [ ! -d $DM_HOME/.local/share/kscreen ]; then
     mkdir -p $DM_HOME/.local/share/kscreen
    fi
    cp $USER_HOME/.local/share/kscreen/* $DM_HOME/.local/share/kscreen

#   export KSCREEN_LOGGING=1
#   export QT_MESSAGE_PATTERN="[%{time hh::mm:s.zzz}] %{function}: %{message}"
    HOME=$DM_HOME /usr/bin/kscreend&

    break
  fi
done
IFS="$save_IFS"
