#!/bin/bash
root_right=755
user_right=750
root_ini_right=444
user_ini_right=400
script_right=500
mindstudio_msprof_spc_right=500
root_libmsprofiler_right=444
user_libmsprofiler_right=440
package_arch=$(uname -m)
PATH_LENGTH=4096
MSPROF_RUN_NAME="mindstudio-profiler"
LIB_MS_PROFILER="libmsprofiler.so"
LIB_PROF_API="libprofapi.so"
LIB_PROF_IMPL="libprofimpl.so"
ACL_PROF_H="acl_prof.h"
GE_PROF_H="ge_prof.h"
ANALYSIS="analysis"
MSPROF="msprof"
SAMPLE="samples"
ANALYSIS_PATH="tools/profiler/profiler_tool"
SAMPLE_PATH="tools/mstx/samples"
MSPROF_PATH="tools/profiler/bin"
SHARE_INFO_DIR="share/info"
UNINSTALL_SCRIPT="uninstall.sh"
UTILS_SCRIPT="utils.sh"
CANN_UNINSTALL_SCRIPT="cann_uninstall.sh"
VERSION_INFO="version.info"
PLATFORM_PROFILER_RUN="platform-profiler.run"
function print() {
if [ ! -f "$log_file" ]; then
echo "[${MSPROF_RUN_NAME}] [$(date +"%Y-%m-%d %H:%M:%S")] [$1]: $2"
else
echo "[${MSPROF_RUN_NAME}] [$(date +"%Y-%m-%d %H:%M:%S")] [$1]: $2" | tee -a $log_file
fi
}
function remove() {
local target_path=${1}
if [ ! -d "${target_path}" ] && [ ! -f "${target_path}" ]; then
return
fi
local parent_dir=$(dirname ${target_path})
local parent_right=$(stat -c '%a' ${parent_dir})
chmod u+wx ${parent_dir}
chmod -R u+wx ${target_path}
rm -rf ${target_path}
chmod ${parent_right} ${parent_dir}
}
function get_log_file() {
local log_dir
if [ "$UID" = "0" ]; then
log_dir="/var/log/ascend_seclog"
else
log_dir="${HOME}/var/log/ascend_seclog"
fi
mkdir -p "${log_dir}"
echo "${log_dir}/ascend_install.log"
}
function log_init() {
if [ ! -f "$log_file" ]; then
touch $log_file
if [ $? -ne 0 ]; then
print "ERROR" "touch $log_file permission denied"
exit 1
fi
fi
chmod 640 $log_file
}
function check_path() {
local path_str=${1}
if [ ! -e "${path_str}" ]; then
print "ERROR" "The path ${path_str} does not exist, please check."
exit 1
fi
if [ ${#path_str} -gt ${PATH_LENGTH} ]; then
print "ERROR" "parameter error $path_str, the length exceeds ${PATH_LENGTH}."
exit 1
fi
if [[ ! "${path_str}" =~ ^/.* ]]; then
print "ERROR" "parameter error $path_str, must be an absolute path."
exit 1
fi
if echo "${path_str}" | grep -Eq '/{2,}|\.{3,}'; then
print "ERROR" "The path ${path_str} is invalid, cannot contain the following characters: // ...!"
exit 1
fi
if echo "${path_str}" | grep -Eq '^~?[a-zA-Z0-9./_-]*$'; then
return
else
print "ERROR" "The path ${path_str} is invalid, only [a-z,A-Z,0-9,-,_] is support!"
exit 1
fi
}
function check_cann_path() {
local cann_path=${1}
local current_user=$(whoami)
local cann_path_owner=$(stat -c '%U' "$cann_path")
if [ "$current_user" != "root" ]; then
if [ "$current_user" != "$cann_path_owner" ]; then
print "ERROR" "Current user ($current_user) is not the same as the owner of cann_path ($cann_path_owner)."
exit 1
fi
if [ ! -w "$cann_path" ]; then
print "ERROR" "cann_path ($cann_path) is not writable by the current user ($current_user)."
exit 1
fi
fi
}
log_file=$(get_log_file)
log_init