-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch
51 lines (41 loc) · 841 Bytes
/
watch
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
#!/bin/bash
if [[ $# -lt 4 ]]; then
echo "No arguments given. Abort."
exit
fi
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-d|--dir)
DIR="$2"
shift
;;
-p|--PORT)
PORT="$2"
shift
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
when-changed $DIR -c "bash deploy %f $DIR $PORT"
# clean up created container
DATE=`date +"%D %R:%S"`
printf "\e[0m"
echo -e "[$DATE] \e[1m\e[33mCleaning up"
printf "\e[0m"
PENS=`find . -maxdepth 1 -type d -name [^\.[^\.]\* | sed -E 's/\.\///'`
for PEN in $PENS; do
RES=`docker ps --format "{{.ID}} {{.Names}}"| grep $PEN`
ID=`echo $RES | cut -d ' ' -f1`
if [[ $ID == "" ]]; then
continue
fi
CONTAINER=`docker stop $ID`
echo -e "[$DATE] \e[1m\e[94mStopped container $CONTAINER"
docker rm $ID >> /dev/null
done
printf "\e[0m"