-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontrol.sh
executable file
·188 lines (160 loc) · 3.19 KB
/
control.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
MAKE_ENABLED=false
INVALID_OPTIONS=false
validates_distro() {
if [ "$COMMAND" == "package" ]; then
if [ "$DISTRO" == "debian" ] || [ "$DISTRO" == "redhat" ]; then
true
else
INVALID_OPTIONS=true
fi
else
INVALID_OPTIONS=true
fi
}
validates_tag() {
if [ "$COMMAND" == "archive" ] || [ "$COMMAND" == "package" ]; then
true
else
INVALID_OPTIONS=true
fi
}
previous=
for i in "$@"; do
case $i in
build|make|run|all|clear|package|archive)
COMMAND=$i
shift
;;
--make)
MAKE_ENABLED=true
shift
;;
--distro)
DISTRO=$2
shift 2
;;
--tag)
TAG=$2
shift 2
;;
*)
if [ -z "$COMMAND" ]; then
INVALID_OPTIONS=true
elif [ "$previous" == "--distro" ]; then
validates_distro
elif [ "$previous" == "--tag" ]; then
validates_tag
else
INVALID_OPTIONS=true
fi
;;
esac
previous=$i
done
if $INVALID_OPTIONS; then
echo "E: missing command or invalid options" >&2
echo "" >&2
echo "Usage: `basename $0` <command> [options]" >&2
echo "" >&2
echo "* <command> = {build|make|run|all|clear}" >&2
echo "* [options] = --make" >&2
echo " --distro <debian|redhat>" >&2
echo " --tag <git-tag>" >&2
exit 2
fi
do_build() {
# Remove existing build directory
echo "Removing build dir"
rm -rf build/
# Creating build directory
echo "Creating build file"
mkdir build
# Enter build and run Cmake
echo "Running cmake"
cd build && cmake ..
cd ..
}
do_make() {
# Remove existing bin directory
echo "Removing build dir"
rm -rf bin
# Creating build directory
echo "Creating build file"
mkdir bin
# Running make
echo "Running make command"
cd build
make
# Move binary files to bin folder
echo "Moving binary files to bin directory"
mv mindscape ../bin/
cd ..
}
do_run() {
cd bin
./mindscape
}
do_all() {
do_build
do_make
do_run
}
do_archive(){
echo "Creating archive."
git archive --format=tar.gz --prefix=mindscape-${TAG:1}/ $TAG > mindscape-${TAG:1}.tar.gz
mkdir -p archives
mv mindscape-${TAG:1}.tar.gz archives/
echo "Done."
}
do_clear() {
rm -rf archives
rm -rf build
rm -rf bin
}
do_package() {
generate_${DISTRO}_package
}
generate_debian_package() {
echo "Generating debian package for TAG: $TAG"
echo
rm -rf .vagrant
do_clear
do_archive
echo "Moving archives to parent directory."
mv archives/mindscape-${TAG:1}.tar.gz ../
echo "Cleaning directory"
do_clear
old_dir=`pwd`
new_dir=mindscape-${TAG:1}
echo "Renaming $old_dir to $new_dir"
cd ..
mv $old_dir $new_dir
cd $new_dir
echo "Running dh_make."
do_clear
dh_make -f ../mindscape-${TAG:1}.tar.gz
echo "Running debuild."
debuild -us -uc --source-option=--include-binaries
echo "Renaming mindscape name to the older."
cd ..
mv $new_dir $old_dir
cd $old_dir
}
generate_redhat_package(){
echo "Generating rpm package for TAG: $TAG"
echo
do_archive
cd rpm/
./packager.sh
cd ..
}
if $MAKE_ENABLED && [ "$COMMAND" = 'build' ]; then
do_build
do_make
elif $MAKE_ENABLED && [ "$COMMAND" = 'run' ]; then
do_make
do_run
else
do_$COMMAND
fi
exit 0