-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen-shell.sh
78 lines (68 loc) · 1.76 KB
/
open-shell.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
#!/usr/bin/env bash
# VARIABLES ########################################################
docker_image="chrisemills/gallerydl:dev"
container_name="gallerydl"
debug_args="--entrypoint //bin/sh"
extra_args=''
# FUNCTIONS ########################################################
docker_run () {
echo " Use 'exit' in the container shell to escape.
"
docker run -it --rm \
--name $container_name \
-e 'UMASK'='000' \
-e 'PUID'='99' \
-e 'PGID'='100' \
-v "/$(pwd)/output":/output:rw \
-v "/$(pwd)/config":/config:rw \
$extra_args $docker_image
}
docker_remove () {
if [ $(docker ps -q -f name=$container_name) ]; then
docker rm $container_name
fi
}
docker_autocheck () {
if [ $(docker ps -q -f name=$container_name) ]
then
echo "Auto: $container_name is already running... let's take a peek!"
docker attach $container_name
elif [ $(docker ps -aq -f status=exited -f name=$container_name) ]
then
echo "Auto: $container_name is stopped... let's start over!"
docker rm $container_name
docker_run
else
echo "Auto: $container_name doesn't exist... let's fix that!"
docker_run
fi
}
usage() {
echo "$0 usage:" && grep " .)\ #" $0; exit 0;
}
# MAIN ##############################################################
if [ $# -eq 0 ]; then
usage;
exit 1;
fi
while getopts 'had' flag; do
case "${flag}" in
a) # Auto operation, check docker container status and run/attach.
docker_autocheck
;;
d) # Use the debug Entrypoint and run a new container.
extra_args=$debug_args
docker_remove
docker_run
;;
h | *) # Display help.
usage; exit 1;
;;
:)
echo "argument missing for $flag"; exit 1;
;;
\?)
echo "Something is wrong"; exit 1;
;;
esac
done