# !/bin/sh

RedisConfDir=/usr/local/db/bin/conf
OMCEtcDir=/usr/local/omc/etc
FERootDir=/usr/local/omc/htdocs/front
CFileList="restconf.yaml crontask.yaml tasks.yaml sshsvc.yaml capconf.yaml"

echo ""
echo "* To start/stop/restart/status omc service, please run:"
echo "    sudo systemctl start/stop/restart/status restagent.service"
echo "    sudo systemctl start/stop/restart/status crontask.service"
echo "    sudo systemctl start/stop/restart/status sshsvc.service"
echo "    sudo systemctl start/stop/restart/status captrace.service"
echo "    sudo systemctl start/stop/restart/status adb.service"
echo "    or run: "
echo "    sudo /usr/local/omc/bin/omcsvc.sh start/stop/restart/status"
echo ""

systemctl enable restagent.service
systemctl enable crontask.service
systemctl enable sshsvc.service
systemctl enable captrace.service
systemctl enable adb.service
chmod +rx /usr/local/db/bin/*
systemctl daemon-reload
for CFile in ${CFileList}; do
    if [ ! -e "${OMCEtcDir}/${CFile}" ]; then
        cp ${OMCEtcDir}/default/${CFile} ${OMCEtcDir};
    fi                 
done
if [ ! -e "${RedisConfDir}/redis.conf" ]; then
    cp ${RedisConfDir}/default/redis.conf ${RedisConfDir};
fi
if [ ! -e "${FERootDir}/config.js" ]; then    
    cp ${FERootDir}/default/config.js ${FERootDir}; 
fi        
if ! id -u omc >/dev/null 2>&1 ; then     
    useradd -d /opt/omc -m -s /bin/bash -pomc123 omc; 
    mkdir -p /opt/omc/ftp
else 
    echo "user omc exist"; 
fi

