-
Notifications
You must be signed in to change notification settings - Fork 2
/
init
executable file
·215 lines (168 loc) · 4.86 KB
/
init
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh
set -f
log()
{
echo "${1}"
}
log "Checking requirements..."
if [ -n $(which docker) ]; then
log "> docker => installed"
else
log "> docker => not installed"
exit 1
fi
log "Preparing..."
NO_CPU_LIMIT=$(docker info 2>&1 | grep -E "No cpu cfs (quota|period)")
GROUP_ID=$(id -g `whoami`)
USER_ID=$(id -u `whoami`)
DEFAULT_VOLUME=$(cd ~ && pwd -P)"/easyepg"
DEFAULT_SOCKET=$(find ~/ -type s -name "xmltv.sock" 2> /dev/null)
DEFAULT_TIMEZONE="Europe/Berlin"
DEFAULT_FREQUENCY="0 2 * * *"
DEFAULT_UPDATE="no"
DEFAULT_REPO="sunsettrack4"
DEFAULT_BRANCH="master"
DEFAULT_TAG="latest"
DEFAULT_PACKAGES=""
if [ -z "${NO_CPU_LIMIT}" ]; then
DEFAULT_CPU_LIMIT=$(docker info 2>&1 | grep -E "^ *CPUs: " | sed "s/^ *CPUs: //")
fi
read -p "Storage location [${DEFAULT_VOLUME}]: " VOLUME
while true; do
if [ -n "${DEFAULT_SOCKET}" ]; then
read -p "Use existing local xmltv.sock [Y/n]: " yn
case ${yn} in
[Nn]*)
break
;;
*)
read -p "Socket location [${DEFAULT_SOCKET}]: " SOCKET
break
;;
esac
else
read -p "Use custom location/directory for xmltv.sock [y/N]: " yn
case ${yn} in
[Yy]*)
read -p "Socket location [${DEFAULT_SOCKET}]: " SOCKET
break
;;
*)
break
;;
esac
fi
done
if [ -n "${DEFAULT_CPU_LIMIT}" ]; then
while true; do
read -p "Limit CPU usage [y/N]: " yn
case ${yn} in
[Yy]*)
read -p "CPU limit [${DEFAULT_CPU_LIMIT}]: " CPU_LIMIT
break
;;
*)
break
;;
esac
done
fi
read -p "Timezone [${DEFAULT_TIMEZONE}]: " TIMEZONE
read -p "Cronjob frequency [${DEFAULT_FREQUENCY}]: " FREQUENCY
read -p "Easyepg git repo [${DEFAULT_REPO}]: " REPO
read -p "Easyepg git branch [${DEFAULT_BRANCH}]: " BRANCH
if [ -z "${BRANCH}" ] || [ "${BRANCH}" = "master" ]; then
DEFAULT_UPDATE="yes"
while true; do
read -p "Autoupdate easyepg [Y/n]: " yn
case ${yn} in
[Nn]*)
UPDATE="no"
break
;;
*)
UPDATE="yes"
break
;;
esac
done
fi
read -p "Easyepg.minimal docker tag [${DEFAULT_TAG}]: " TAG
read -p "Additional OS packages [${DEFAULT_PACKAGES}]: " PACKAGES
if [ -z "${VOLUME}" ]; then
VOLUME=${DEFAULT_VOLUME}
fi
if [ -z "${SOCKET}" ]; then
SOCKET=${DEFAULT_SOCKET}
fi
if [ -z "${CPU_LIMIT}" ]; then
CPU_LIMIT=${DEFAULT_CPU_LIMIT}
fi
if [ -z "${TIMEZONE}" ]; then
TIMEZONE=${DEFAULT_TIMEZONE}
fi
if [ -z "${FREQUENCY}" ]; then
FREQUENCY=${DEFAULT_FREQUENCY}
fi
if [ -z "${UPDATE}" ]; then
UPDATE=${DEFAULT_UPDATE}
fi
if [ -z "${REPO}" ]; then
REPO=${DEFAULT_REPO}
fi
if [ -z "${BRANCH}" ]; then
BRANCH=${DEFAULT_BRANCH}
fi
if [ -z "${TAG}" ]; then
TAG=${DEFAULT_TAG}
fi
if [ -z "${PACKAGES}" ]; then
PACKAGES=${DEFAULT_PACKAGES}
fi
if [ ! -d "${VOLUME}" ]; then
mkdir -p ${VOLUME}
fi
if [ -z "${VOLUME}" ] || [ ! -d "${VOLUME}" ] || [ ! -w "${VOLUME}" ]; then
log "Storage location incorrect"
exit 1
fi
if [ ! -z "${SOCKET}" ]; then
if [ ! -S "${SOCKET}" ] && [ ! -d "${SOCKET}" ]; then
log "Socket location incorrect"
exit 1
fi
fi
# make paths absolute for docker
VOLUME=$(cd ${VOLUME} && pwd -P)
if [ ! -z "${SOCKET}" ]; then
SOCKET=$(cd `dirname ${SOCKET}` && pwd -P)/$(basename ${SOCKET})
fi
log "Stopping container..."
docker ps --format "{{.Image}} {{.ID}}" | grep "qoopido/easyepg.minimal" | cut -d " " -f 2 | xargs -I {} docker stop {} > /dev/null
log "Removing old container..."
docker ps -a --format "{{.Image}} {{.ID}}" | grep "qoopido/easyepg.minimal" | cut -d " " -f 2 | xargs -I {} docker rm --force {} > /dev/null
log "Removing old image..."
docker images --format "{{.Repository}}:{{.Tag}}" | grep "qoopido/easyepg.minimal" | xargs -I {} docker rmi --force {} > /dev/null
log "Pulling new image..."
docker pull qoopido/easyepg.minimal:${TAG}
log "Creating new container..."
OPTIONS="--tmpfs /tmp --tmpfs /var/log -e USER_ID=\"${USER_ID}\" -e GROUP_ID=\"${GROUP_ID}\" -e TIMEZONE=\"${TIMEZONE}\" -e FREQUENCY=\"${FREQUENCY}\" -e UPDATE=\"${UPDATE}\" -e REPO=\"${REPO}\" -e BRANCH=\"${BRANCH}\" -e PACKAGES=\"${PACKAGES}\" -v ${VOLUME}:/easyepg"
if [ -n "${SOCKET}" ]; then
if [ -S "${SOCKET}" ]; then
OPTIONS="${OPTIONS} -v ${SOCKET}:/xmltv.sock"
fi
if [ -d "${SOCKET}" ]; then
OPTIONS="${OPTIONS} -v ${SOCKET}:/xmltv"
fi
fi
if [ -n "${CPU_LIMIT}" ]; then
OPTIONS="${OPTIONS} --cpus ${CPU_LIMIT}"
fi
sh -c "docker create -l easyepg.minimal --name=easyepg.admin -e MODE=\"admin\" ${OPTIONS} qoopido/easyepg.minimal:${TAG} 1> /dev/null"
log "> easyepg.admin"
sh -c "docker create -l easyepg.minimal --name=easyepg.run -e MODE=\"run\" ${OPTIONS} qoopido/easyepg.minimal:${TAG} 1> /dev/null"
log "> easyepg.run"
sh -c "docker create -l easyepg.minimal --name=easyepg.cron -e MODE=\"cron\" --restart unless-stopped ${OPTIONS} qoopido/easyepg.minimal:${TAG} 1> /dev/null"
log "> easyepg.cron"
log "Finished!"
exit