-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
executable file
·302 lines (264 loc) · 6.43 KB
/
functions.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
function init_tmp {
mkdir tmp
cd tmp
}
function needs_download {
_has_url=$(jq 'select(.repoUrl != null)' ${CONFIG_FILE} | wc -l | bc)
if [ "${_has_url}" -ne 0 ]
then
echo 1
else
echo 0
fi
}
function download_pkg {
echo "Downloading $PACKAGE_URL"
wget $PACKAGE_URL
}
function pre_extract_commands {
actual_array_size=$( jq -r ".preExtractCommands | length " < $CONFIG_FILE )
if [ $actual_array_size -ne 0 ]
then
useable_array_size=$(echo $actual_array_size-1 | bc)
commands=""
for i in $(seq 0 $useable_array_size);
do
eval_command=$(jq -r .preExtractCommands[$i] < $CONFIG_FILE)
echo $eval_command
eval $eval_command
done
fi
}
function is_zip {
zipfile=$(echo $PACKAGE_NAME | grep -c ".zip$" >/dev/null 2>&1; echo $?)
if [ "$zipfile" -eq 0 ]
then
echo 0
else
echo 1
fi
}
function unpack {
echo "Extracting package $PACKAGE_NAME"
ar x $PACKAGE_NAME
rm $PACKAGE_NAME
}
function extract_data {
echo "Extracting data.tar.gz into tmp/data"
mkdir data
tar -xvf data.tar.gz -C data
}
function extract_control {
echo "Extracting control.tar.gz into tmp/control"
mkdir control
tar -xvf control.tar.gz -C control
}
function unpack_zip {
echo "Unpacking zipfile"
mkdir zip_data
unzip $PACKAGE_NAME -d zip_data
}
function pre_config_commands {
actual_array_size=$( jq -r ".preConfigCommands | length " < $CONFIG_FILE )
if [ $actual_array_size -ne 0 ]
then
useable_array_size=$(echo $actual_array_size-1 | bc)
commands=""
for i in $(seq 0 $useable_array_size);
do
eval_command=$(jq -r .preConfigCommands[$i] < $CONFIG_FILE)
echo $eval_command
eval $eval_command
done
fi
}
function get_source {
config=$1
app_name=$2
index=$3
echo $(jq -r .configs[$index].source < $CONFIG_FILE)
}
function get_destination {
config=$1
app_name=$2
index=$3
echo $(jq -r .configs[$index].destination < $CONFIG_FILE)
}
function cp_configs {
config=$1
app_name=$2
actual_array_size=$( jq -r ".configs | length " < $CONFIG_FILE )
useable_array_size=$(echo $actual_array_size-1 | bc)
for i in $(seq 0 $useable_array_size);
do
file_source=$(get_source $config $APP_NAME $i);
destination=$(get_destination $config $APP_NAME $i)
echo "$file_source -> $destination";
if [ $(is_zip) -ne "0" ]
then
mkdir -p data/$destination;
cp $(pwd)/../$file_source data/$destination/.;
else
mkdir -p zip_data/$destination;
cp $(pwd)/../$file_source zip_data/$destination/.;
fi
done
}
function get_map_source {
config=$1
app_name=$2
index=$3
echo $(jq -r .mappings[$index].source < $CONFIG_FILE)
}
function get_map_destination {
config=$1
app_name=$2
index=$3
echo $(jq -r .mappings[$index].destination < $CONFIG_FILE)
}
function map_files {
config=$1
app_name=$2
actual_array_size=$( jq -r ".mappings | length " < $CONFIG_FILE )
useable_array_size=$(echo $actual_array_size-1 | bc)
for i in $(seq 0 $useable_array_size);
do
file_source=$(get_map_source $config $APP_NAME $i);
destination=$(get_map_destination $config $APP_NAME $i)
echo "$file_source -> $destination";
if [ $(is_zip) -ne "0" ]
then
mkdir -p $(dirname data/$destination);
cp -r $(pwd)/../$file_source data/$destination/.;
else
mkdir -p $(dirname zip_data/$destination);
cp -r $(pwd)/../$file_source zip_data/$destination/.;
fi
done
}
function pre_install {
rm preinst
pre_install=$(cat $CONFIG_FILE | jq -r .pre_install)
if [ -f "tmp/control/preinst" ]
then
cp tmp/control/preinst preinst
fi
if [ $pre_install != "null" ]
then
cp $pre_install preinst
fi
}
function post_install {
rm postinst
post_install=$(cat $CONFIG_FILE | jq -r .post_install)
if [ -f "tmp/control/postinst" ]
then
cp tmp/control/postinst postinst
fi
if [ $post_install != "null" ]
then
cp $post_install postinst
fi
}
function post_remove {
rm postremove
post_remove=$(cat $CONFIG_FILE | jq -r .post_remove)
if [ -f "tmp/control/postremove" ]
then
cp tmp/control/postremove postremove
fi
if [ $post_remove != "null" ]
then
cp $post_remove postremove
fi
}
function upstart_script {
upstart_script=$(cat $CONFIG_FILE | jq -r .upstart)
rm $(basename "$upstart_script")
if [ $upstart_script != "null" ]
then
cp $upstart_script $(basename "$upstart_script")
echo $(basename "$upstart_script")
fi
}
function pkg_pre_dependencies {
config=$1
app_name=$2
actual_array_size=$( jq -r ".pre_dependencies | length " < $CONFIG_FILE )
useable_array_size=$(echo $actual_array_size-1 | bc)
dependecies_flags=""
if [ $actual_array_size -ne 0 ]
then
for i in $(seq 0 $useable_array_size);
do
dependencies=$(jq -r .pre_dependencies[$i] < $CONFIG_FILE)
dependecies_flags="$dependecies_flags --deb-pre-depends $dependencies "
done
echo $dependecies_flags
fi
}
function pkg_dependencies {
config=$1
app_name=$2
actual_array_size=$( jq -r ".dependencies | length " < $CONFIG_FILE )
useable_array_size=$(echo $actual_array_size-1 | bc)
dependecies_flags=""
if [ $actual_array_size -ne 0 ]
then
for i in $(seq 0 $useable_array_size);
do
dependencies=$(jq -r .dependencies[$i] < $CONFIG_FILE)
dependecies_flags="$dependecies_flags --depends $dependencies "
done
echo $dependecies_flags
fi
}
function cleanup {
if [ -d "build" ]
then
rm -rf build
fi
if [ -d "tmp" ]
then
rm -rf tmp
fi
if [ -f 0 ]
then
rm 0
fi
}
# possibly safe to remove
# --- below this line ---
function pkg_exists {
bucket=$1
package=$2
version=$3
return $(deb-s3 show --bucket=$bucket $package $version amd64 >/dev/null 2>&1; echo $?)
}
function repo_url {
echo $(cat $CONFIG_FILE | jq -r .repoUrl)
}
function package_name {
echo $(cat $CONFIG_FILE | jq -r .packageName)
}
function version {
echo $(cat $CONFIG_FILE | jq -r .version)
}
function has_configs {
actual_array_size=$( jq -r ".configs | length " < $CONFIG_FILE )
if [ $actual_array_size -ne 0 ]
then
echo 0
else
echo 1
fi
}
function default_configs {
d_configs=$( jq -r ".default_configs " < $CONFIG_FILE )
if [ $d_configs == "true" ]
then
echo 0
else
echo 1
fi
}