#!/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"

# 白名單放寬為依專案別的尾綴（_test_<game> / _live_<game>），n1 仍命中、向下相容
case "${FILENAME}" in
    S_RootCmds.ini_test_*|S_RootCmds.ini_live_*)
        echo "sudo cp -arf /home/${USER}/bin/${FILENAME} ${MANAGE_DIR}/." >> ${MANAGE_DIR}/from_log.txt
        sudo cp -arf /home/${USER}/bin/${FILENAME} ${MANAGE_DIR}/.
        ;;
esac

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