#!/bin/bash

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

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

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

if [ "${FILENAME}" == "S_RootCmds.ini_test_n1" ] || [ "${FILENAME}" == "S_RootCmds.ini_live_n1" ]; then
    echo "sudo cp -arf /home/${USER}/bin/${FILENAME} ${MANAGE_DIR}/." >> ${MANAGE_DIR}/from_log.txt
    sudo cp -arf /home/${USER}/bin/${FILENAME} ${MANAGE_DIR}/.
fi

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