-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove
executable file
·62 lines (50 loc) · 1.17 KB
/
remove
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
#!/bin/bash
PROGRAM=$(basename $0)
function usage() {
echo "Usage: $PROGRAM [--container container_to_stop_and_remove] [--image image_to_remove]"
echo "-------------------------------------------------------------------------------------"
echo "Example: $PROGRAM --container dev1 --image dev"
}
function error() {
echo $1
echo ""
usage
exit 1
}
while true; do
case $1 in
--container) CONTAINER="$2" ; shift ;;
--image) IMAGE="$2" ; shift ;;
--dryrun) DEBUG=true ;;
--help) usage ; exit 0; shift ;;
(--) shift;;
(-*) error "$PROGRAM: unrecognized option \"$1\"";;
(*) break;;
esac
shift
done
if [ ! -z "$CONTAINER" ]
then
CONTAINER_REMOVAL_CMD="docker container stop $CONTAINER && docker container rm $CONTAINER"
fi
if [ ! -z "$IMAGE" ]
then
IMAGE_REMOVAL_CMD="docker image rm $IMAGE"
fi
if [ ! -z "$CONTAINER_REMOVAL_CMD" ] && [ ! -z "$IMAGE_REMOVAL_CMD" ]
then
DIVIDER=" && "
fi
CMD="$CONTAINER_REMOVAL_CMD$DIVIDER$IMAGE_REMOVAL_CMD"
if [ "$DEBUG" = true ] ; then
echo "Command to be executed:"
echo ""
echo "\"$CMD\""
exit 0
fi
if [ -z "$CMD" ]
then
echo "Nothing to do"
exit 0
fi
eval $CMD