#!/bin/bash

if [ -z "$1" ]
then
>&2 echo "need conf file as parameter"
exit 1
fi

id -u clc &>/dev/null || useradd clc 

mkdir -p /etc/clc
cp "$1" /etc/clc/client.conf
chown -R clc:clc /etc/clc
chmod -f -R 760 /etc/clc || :
#rm /etc/clc/client.conf

DIRECTORY=`realpath $0`
DIRECTORY=`dirname $DIRECTORY`

mkdir -p /var/clc
chown -R clc:clc /var/clc
chmod -f -R 760 /var/clc/*.conf || :
chmod -f -R 760 /var/clc || :

mkdir -p /var/clclog/
chown -R clc:clc /var/clclog
chmod -f -R 744 /var/clclog || :

systemctl stop CLCClient
cp $DIRECTORY/CLCClient.service /lib/systemd/system/CLCClient.service
systemctl daemon-reload
systemctl start CLCClient
systemctl enable CLCClient

