blob: 176a84c7fa34557813469268bd9e9586b4320287 (
plain)
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
declare container_name="pdkcontainer-client-1"
declare IMAGE="tizenpdk:v0.2"
declare VOLUMES="-v /dev/bus/usb:/dev/bus/usb"
#declare DEVICES="--devices=/dev/bus/usb"
declare PRIVILEGE="--privileged"
declare hostname=$(hostname)
declare container_id
VOLUMES=$(echo $VOLUMES "-v /etc/localtime:/etc/localtime:ro -v /etc/mic/:/etc/mic/")
HOSTNAME=" --hostname $(hostname) "
DirCheck()
{
remain_array=(home share var srv root tmp)
for i in ${remain_array[@]}
do
re=$(ls / | grep -w $i)
if [ $re ]
then
VOLUMES="$VOLUMES --volume=/$re:/$re"
fi
done
# echo $VOLUMES
}
PermissonCheck(){
docker ps >/dev/null
if [ $? -ne 0 ]
then
echo -e "\033[31m[Error]\033[0m:\033[33mYou haven't permission to run docker without 'sudo'.We suggest you to use docker without sudo. \033[0m"
exit
fi
}
# clear the $IMAGE container which is Exited status
Autoclean(){
ids=$(docker ps -a | grep -w $IMAGE | grep -w 'Exited' | awk '{print $1}')
for id in $ids
do
docker rm $id 1>/dev/null
done
}
# delte a container by id or container name
DeleteContainer()
{
docker stop $1 >/dev/null 2>&1
if [ $?==0 ]
then
docker rm $1 >/dev/null 2>&1
fi
}
# create a container
CreateContainer()
{
#Check mounting
# if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then
# mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
# fi
container_id=$(docker run -itd --name=$1 --network=pdknet ${PRIVILEGE} ${VOLUMES} ${IMAGE} /bin/bash)
}
# check whether the container is exists
CheckContainer()
{
container_id=$(docker ps | grep -w $1 | awk '{print $1}')
#echo $container_id "test"
# after try 10 times, if container_id always is 0, then exit
i=0
while [ -z $container_id ]
do
CreateContainer $1
i=1
done
if [ $i -ne 1 ]
then
echo "Can't create container, please check"
exit 0
else
echo "create container" $container_id "successful"
fi
}
DirCheck
PermissonCheck
Autoclean
CheckContainer $container_name
|