This repository was archived by the owner on Jan 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathec2
More file actions
executable file
·151 lines (129 loc) · 4.05 KB
/
ec2
File metadata and controls
executable file
·151 lines (129 loc) · 4.05 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /bin/bash
##################################
# Easy Coding 2 #
##################################
# get script path
export SCRIPT_PATH=$(readlink -f "${BASH_SOURCE[0]}")
export SCRIPT_DIR=$(dirname $SCRIPT_PATH)
# clean up
unset TEXT_LS
# function to import other scripts
function import() {
# $1: path & parameters
source "$SCRIPT_DIR/$1"
}
# imports
import "utility"
##########################################
# TODO: Initialize
#=============================
# get project name
if [ $1 ]; then
PROJECT_NAME="$1"
shift
#=============================
# load cmd list
loadCmdList "$SCRIPT_DIR" "CMD_LIST"
#=============================
# load cfg list
loadCfgList "$SCRIPT_DIR" "CFG_LIST"
#=============================
# check project name with cfg list
result="0"
for name in ${CFG_LIST[@]}; do
if [ $name == $PROJECT_NAME ]; then
result="1"
break
fi
done
# check result
if [ "$result" == "0" ]; then
print e "Error! Project name is invalide"
print w "Available project names are:"
for name in ${CFG_LIST[@]}; do
print w " $name"
done
else
# clean up
unset result
unset name
#=============================
# prepare config
#import "config/$PROJECT_NAME"
loadCfg "$PROJECT_NAME"
#=============================
# check user cmds
if [ "$#" -eq "0" ]; then
print e "Error! No command found"
help
else
unset PARAMS
unset CMDS
params="$@"
until [ -z "$params" ]; do
# get section by ","
len=`expr index "$params" ","`
if [ "$len" -eq "0" ]; then
section="$params" # "," not found, may be get the last part
else
section="${params:0:$len}"
fi
params="${params#$section}" # remove obtained section from params
section="${section%,}" # remove ",'
eval section="\$(echo $section)" # remove blank on left/right
# get cmd
cmd="${section%% *}"
eval cmd="\$(echo $cmd)" # remove blank on left/right
# get parameter
param="${section#*$cmd}"
eval param="\$(echo $param)" # remove blank on left/right
# check cmd with cmd list
result="0"
for c in ${CMD_LIST[@]}; do
if [ $c == $cmd ]; then
result="1"
break
fi
done
# check result
if [ "$result" == "0" ]; then
print e "Error! Invalide CMD: $cmd"
print w "Available CMDs are:"
for c in ${CMD_LIST[@]}; do
print w " $c"
done
break
fi
# add the section to section list
CMDS[${#CMDS[@]}]=$cmd
PARAMS[${#PARAMS[@]}]=$param
#SECTIONS[${#SECTIONS[@]}]=$section
done
# clean up
unset params
unset len
unset section
unset cmd
unset result
unset c
#=============================
# execute cmds
n=${#CMDS[@]}
i="0"
until [ "$i" -eq "$n" ]; do
#pushd . > "/dev/null" # save current path
execute "${CMDS[$i]}" "${PARAMS[$i]}"
i=$((i+1))
#popd > "/dev/null" # recover current path
done
# clean up
unset n
unset i
unset CMDS
unset PARAMS
fi
fi
else
print e "Error! Project name missed"
help
fi