-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathbuild.sh
52 lines (43 loc) · 1.13 KB
/
build.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
#!/usr/bin/env bash
function print_usage() {
echo "$0 <src-lib-dir> <dest-lib-dir> <dist-dir> <version>"
}
if [ $# -ne 4 ]; then
echo '# of argument MUST be 4 !'
print_usage
exit 1
fi
src_lib_dir="$1"
dest_lib_dir="$2"
dist_dir="$3"
version="$4"
if ! [ -d $src_lib_dir ]; then
echo "src_lib_dir:$src_lib_dir does not exist !"
exit -1
fi
if ! [ -d $dest_lib_dir ]; then
mkdir $dest_lib_dir
fi
if ! [ -d $dist_dir ]; then
mkdir $dist_dir
fi
# cp needed libs
cp -r $src_lib_dir/* $dest_lib_dir/
# packaging each lambda functions
src_lib_dir_name=`echo "$src_lib_dir" | awk -F '/' '{print $NF}'`
dist_lib_dir_name=`echo "$dist_dir" | awk -F '/' '{print $NF}'`
for l_dir in `find . -maxdepth 1 -type d | tail -n +2 | awk -F '/' '{print $NF}'`; do
if [ "$l_dir" == "$src_lib_dir_name" ] || [ "$l_dir" == "$dist_lib_dir_name" ] ; then
continue
fi
z_f="$l_dir-$version.zip"
pushd $dest_lib_dir/
zip -r $z_f *
[ $? -ne 0 ] && echo "make zip file for lambda:$l_dir failed !" && exit 1
mv $z_f ../$l_dir/
popd
pushd $l_dir/
zip -r $z_f *
mv $z_f $dist_dir/
popd
done