-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
89 lines (77 loc) · 1.72 KB
/
main.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
#!/bin/bash
echo -------------------------------------------------------
if [ "$1" == "build" ]
then
task=build
elif [ "$1" == "deploy" ]
then
task=deploy
else
echo unknown task
fi
echo Task: $task
save_device=0
save_workingdir=0
save_srcpath=0
for arg in "$@"
do
if [ $save_device == 1 ]
then
save_device=0
device="$arg"
elif [ $save_workingdir == 1 ]
then
workingdir="$arg"
save_workingdir=0
elif [ $save_srcpath == 1 ]
then
srcpath="$arg"
save_srcpath=0
else
case "$arg" in
"--device" ) save_device=1;;
"--workingdir" ) save_workingdir=1;;
"--srcpath" ) save_srcpath=1;;
esac
fi
done
echo Device: $device
if [ ! -z ${srcpath+x} ]
then
echo Source path: $srcpath
fi
if [ $device == "edison" ]
then
imagename="zhijzhao/edison"
elif [ $device == "raspberrypi" ]
then
imagename="zhijzhao/raspberrypi"
else
echo unknow device name
fi
echo Image name: $imagename
if [ $task == "deploy" ]
then
if [[ -d $srcpath ]]; then
workingdir=$srcpath
srcpathparam="--srcdockerpath /source/*"
elif [[ -f $srcpath ]]; then
workingdir=$srcpath/..
srcpathparam="--srcdockerpath /source/$(basename $srcpath)"
else
echo "$srcpath is not valid"
exit 1
fi
fi
echo Working directory: $workingdir
echo -------------------------------------------------------
echo Pulling docker image...
docker pull $imagename
echo -------------------------------------------------------
if [ $task == "deploy" ]
then
echo Deploying to device via docker container...
else
echo Building code inside docker container...
fi
docker run --rm -i -v $workingdir:/source $imagename /index.sh $task $srcpathparam $@