-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
70 lines (55 loc) · 2.7 KB
/
uninstall.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# ----------------------------- kiwi bash lib start -------------------------------------
# Make sure to execute this script with bash. Bash works well on suse, redhat, aix.##
# 确保以bash执行此脚本。Bash在suse、redhat、aix上表现很出色。##
[ -z "$BASH" ] && echo "Please use bash to run this script [ bash $0 ] or make sure the first line of this script [ $0 ] is [ #!/bin/bash ]." && exit 1
# Set the bash debug info style to pretty format. +[T: <Time>, L: <LineNumber>, S: <ScriptName>, F: <Function>]##
# 设置bash的调试信息为漂亮的格式。+[T: <Time>, L: <LineNumber>, S: <ScriptName>, F: <Function>]##
[ -c /dev/stdout ] && export PS4_COLOR="32"
[ ! -c /dev/stdout ] && export PS4_COLOR=""
export PS4='+[$(debug_info=$(printf "T: %s, L:%3s, S: %s, F: %s" "$(date +%H%M%S)" "$LINENO" "$(basename $(cd $(dirname ${BASH_SOURCE[0]}) && pwd))/$(basename ${BASH_SOURCE[0]})" "$(for ((i=${#FUNCNAME[*]}-1; i>=0; i--)) do func_stack="$func_stack ${FUNCNAME[i]}"; done; echo $func_stack)") ; [ -z "$PS4_COLOR" ] && echo ${debug_info:0:94} ; [ -n "$PS4_COLOR" ] && echo -e "\e[${PS4_COLOR}m${debug_info:0:80}\e[0m")]: '
# 保存调试状态,用于调用子脚本。调用子脚本样例:bash $DEBUG_SWITCH subscript.sh##
# Save the debug state to invoke the subscript. Invoke the subscript example: bash $DEBUG_SWITCH subscript.sh##
(echo "${SHELLOPTS}" | grep -q "xtrace") && export DEBUG_SWITCH=-x
# Get the absolute path of this script.##
# 获取脚本的绝对路径。##
BASE_DIR=$(cd $(dirname $0) && pwd)
BASE_NAME=$(basename $0 .sh)
# 设置日志文件。##
# Set the log file.##
log=$BASE_DIR/$BASE_NAME.log
function print_error()
{
echo "[$(date "+%F %T")] ERROR: $*" | tee -a $log 1>&2
}
function print_info()
{
echo "[$(date "+%F %T")] INFO: $*" | tee -a $log
}
function log_error()
{
[ -n "$log" ] && echo "[$(date "+%F %T")] ERROR: $*" >>$log
}
function log_info()
{
[ -n "$log" ] && echo "[$(date "+%F %T")] INFO: $*" >>$log
}
function die()
{
print_error "$*"
print_error "See log [ $log ] for details."
exit 1
}
# ----------------------------- kiwi bash lib end ---------------------------------------
# Disable log.##
log=/dev/null
find $BASE_DIR -name "*.sh" | xargs dos2unix >>$log 2>&1
find $BASE_DIR -name "*.sh" | xargs chmod +x >>$log 2>&1
# 执行一级子目录下的卸载脚本,执行顺序与安装相反。##
for uninstall_script in $(find $BASE_DIR -mindepth 2 -maxdepth 2 -name "uninstall.sh" | sort -r)
do
print_info "Exe [ $uninstall_script ] start."
bash $DEBUG_SWITCH $uninstall_script 2>&1 | tee -a $log
[ "${PIPESTATUS[0]}" -ne 0 ] && die "Exe [ $uninstall_script ] fail."
print_info "Exe [ $uninstall_script ] finish."
done