#!/bin/bash
readonly PACKAGE_NAME="Ascend-spc_pyACL"
PACKAGE_VERSION=""
spc_path="$(
cd "$(dirname "$0")/../.."
pwd
)"
if [ $(id -u) -ne 0 ]; then
log_dir="${HOME}/var/log/ascend_seclog"
else
log_dir="/var/log/ascend_seclog"
fi
log_file="${log_dir}/ascend_install.log"
function print() {
echo "[pyACL] [$(date +"%Y-%m-%d %H:%M:%S")] [$1]: $2" | tee -a $log_file
}
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 del_file() {
file_path=$1
if [ -f "${file_path}" ]; then
rm -f "${file_path}"
if [ $? = 0 ]; then
print "INFO" "delete file ${file_path} successfully"
else
print "ERROR" "delete file ${file_path} fail"
exit 1
fi
else
print "WARNING" "the file ${file_path} is not exist"
fi
}
function del_dir() {
local dir_path=$1
if [ -n "${dir_path}" ] && [[ ! "${dir_path}" =~ ^/+$ ]]; then
if [ -d "${dir_path}" ]; then
chmod 750 -R ${dir_path}
rm -rf "${dir_path}"
if [ $? = 0 ]; then
print "INFO" "delete directory ${dir_path} successfully"
else
print "ERROR" "delete directory ${dir_path} fail"
exit 1
fi
else
print "WARNING" "the directory ${dir_path} is not exist"
fi
else
print "WARNING" "the directory ${dir_path} path is NULL"
fi
}
function remove_empty_dir() {
[ ! -d "$1" ] && return 1
if [ -z "$(ls -A $1 2>&1)" ]; then
rm -rf "$1"
if [ $? = 0 ]; then
print "INFO" "delete directory $1 successfully"
else
print "ERROR" "delete directory $1 fail"
exit 1
fi
fi
}
function deal_uninstall() {
version_file_path="${spc_path}/backup/pyACL/pyACL/version.info"
spc_python_path=$spc_path/backup/pyACL/python/site-packages/acl.so
if [ -d "$spc_path/backup/pyACL" ]; then
chmod 750 -R $spc_path/backup/pyACL
fi
if [ -d "$spc_path/backup/pyACL" ]; then
del_dir "$spc_path/backup/pyACL"
fi
del_dir "$spc_path/script/pyACL"
remove_empty_dir "$spc_path/backup"
remove_empty_dir "$spc_path/script"
print "INFO" "${PACKAGE_NAME}-${PACKAGE_VERSION} uninstalled successfully, the directory spc/backup/pyACL has been deleted"
}
log_init
deal_uninstall