-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.sh
More file actions
executable file
·75 lines (59 loc) · 1.41 KB
/
common.sh
File metadata and controls
executable file
·75 lines (59 loc) · 1.41 KB
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
#!/bin/bash
set -e
exit_msg(){
echo "$1 \n Stopping."
exit 1
}
container_exists(){
docker ps -a --format "{{.Names}}" | grep -iq $1
}
container_running(){
docker ps --format "{{.Names}}" | grep -iq $1
}
verify_conflict(){
if container_exists $1; then
exit_msg "Conflicting container with name $1."
fi
}
verify_running(){
if ! container_running $1; then
exit_msg "$1 failed to start. Use docker logs $1."
else
echo "$1 seems to be running."
fi
}
verify_exists(){
if ! container_exists $1; then
exit_msg "Container $1 does not exists."
fi
}
full_path(){
# /absolute/path/without/trailing/slash/is/ok
# /this/will/fail/
# relative/path/fails/too
[[ $1 == /* && ! $1 == */ ]] || exit_msg "Invalid path $1. Must be absolute and *not* end with a slash."
}
install_config(){
if [ ! -e ${2}/$1 ]; then
exit_msg "Config file/folder $1 not found at ${2}."
fi
# Avoid dev mistakes by ensuring full path
full_path $2
full_path $3
if [ ! -d $3 ]; then
exit_msg "Destination dir $3 not found."
fi
cp -r ${2}/$1 ${3} || exit_msg "Failed to execute command: cp -r ${2}/$1 ${3}"
}
read_common_input(){
# General
LOGS_DIR='/var/log'
while test $# -gt 0
do
case "$1" in
# general
--logs-dir) full_path $2 && LOGS_DIR=$2 ;;
esac
shift
done
}