diff options
Diffstat (limited to 'pdkcommon-client-2')
-rwxr-xr-x | pdkcommon-client-2 | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/pdkcommon-client-2 b/pdkcommon-client-2 new file mode 100755 index 0000000..ebd16d5 --- /dev/null +++ b/pdkcommon-client-2 @@ -0,0 +1,89 @@ +#!/bin/bash + +declare container_name="pdkcontainer-client-2" +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 |