#!/bin/bash

FILENAME=$1
MANAGE_DIR=$2
USER=$(whoami)

if [ -z "${MANAGE_DIR}" ]; then
    MANAGE_DIR="/home/${USER}/www/tools/files/config_manage"
fi

[ ! -d "${MANAGE_DIR}" ] && mkdir -p "${MANAGE_DIR}"
[ -f "${MANAGE_DIR}/from_log.txt" ] && rm -rf "${MANAGE_DIR}/from_log.txt"

if [ "${FILENAME}" == "config.ini" ]; then
    echo "sudo cp -arf /home/${USER}/common-TEST/bin/${FILENAME} ${MANAGE_DIR}/." >> ${MANAGE_DIR}/from_log.txt
    sudo cp -arf /home/${USER}/common-TEST/bin/${FILENAME} ${MANAGE_DIR}/.
elif [ "${FILENAME}" == "config00.ini" ]; then
    echo "sudo cp -arf /home/${USER}/servers1/${FILENAME} ${MANAGE_DIR}/." >> ${MANAGE_DIR}/from_log.txt
    sudo cp -arf /home/${USER}/servers1/${FILENAME} ${MANAGE_DIR}/.
fi

sudo chmod 777 ${MANAGE_DIR}/${FILENAME}
sudo chown ${USER}:${USER} ${MANAGE_DIR}/${FILENAME}
