-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_pro.sh
More file actions
executable file
·113 lines (92 loc) · 2.06 KB
/
my_pro.sh
File metadata and controls
executable file
·113 lines (92 loc) · 2.06 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
my_shell_ipc_path=/opt/work/shell/shell_ipc
quiet_mode=0
source $my_shell_ipc_path/log.sh
source $my_shell_ipc_path/bar.sh
output=/dev/stdout
logfile=/dev/stdout
# export var to child script
export output
export logfile
# module script file rule:
# <module_name>.sh
# - <module_name>_usage()
module_array=(
"test"
"copy"
)
module_num=${#module_array[@]}
# source all module scripts
for i in ${module_array[*]}
do
source ${i}.sh
done
function show_all_module_usage()
{
local i=
C_Info "This is ywj's project handy script, include this module:"
for i in ${module_array[*]}
do
echo "module ${i}:"
eval ${i}_usage
echo ""
done
C_Info "All modules list:"
i=0
while [ $i -lt $module_num ]
do
echo -e "\t$i : ${module_array[$i]}"
let i++
done
}
function show_user_method_use_module()
{
echo ""
C_Info "You can use module like this:"
echo -e "\t$0 0 arg1 arg2"
echo -e "\t or"
echo -e "\t$0 test arg1 arg2"
echo -e "\t mean excute test module script with argus(arg1, arg2)"
}
function get_module_id_by_arg()
{
local str=$1
local __module_id=$2
local i=0
if [ -z "$1" -o -z "$2" ];then
Error "Argus error, arg1[$1], arg2[$2]..."
return 1
fi
while [ $i -lt $module_num ]
do
if [ "$str" = "${module_array[$i]}" ];then
eval $__module_id="'$i'"
return 0
fi
if [ $str -eq $i ];then
eval $__module_id="'$i'"
return 0
fi
let i++
done
Error "Can't find the module by arg[$1]."
return 1
}
if [ $# -lt 1 ];then
show_all_module_usage
show_user_method_use_module
exit 0
fi
choice_module_id=
get_module_id_by_arg $1 choice_module_id
if [ $? -ne 0 ];then
exit 1
fi
shift 1
C_Info "Execute module cmd: ./${module_array[$choice_module_id]}.sh $*"
echo ""
sh ${module_array[$choice_module_id]}.sh $*
statu=$?
if [ $statu -ne 0 ];then
Error "Execute ${module_array[$choice_module_id]}.sh failed, exit status:$statu !"
fi