-
-
Save dlueth/62a3d7133e96e23fc67285e251daf3fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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_TAG="2.0.4-RC.1" | |
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 local xmltv.sock [Y/n]: " yn | |
case ${yn} in | |
[Nn]*) | |
break | |
;; | |
*) | |
read -p "Socket location [${DEFAULT_SOCKET}]: " SOCKET | |
break | |
;; | |
esac | |
else | |
read -p "Use local 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 "Version [${DEFAULT_TAG}]: " TAG | |
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 "${TAG}" ]; then | |
TAG=${DEFAULT_TAG} | |
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}" ] && [ ! -S "${SOCKET}" ]; then | |
log "Socket location incorrect" | |
exit 1 | |
fi | |
# make paths absolute for docker | |
VOLUME=$(cd ${VOLUME} && pwd -P) | |
if [ ! -z "${SOCKET}" ]; then | |
SOCKET=$(cd `dirname ${SOCKET}` && pwd -P)/$(basename ${SOCKET}) | |
fi | |
docker rm --force easyepg.admin > /dev/null 2>&1 | |
docker rm --force easyepg.run > /dev/null 2>&1 | |
docker rm --force easyepg.cron > /dev/null 2>&1 | |
log "Pulling image..." | |
docker pull qoopido/easyepg.minimal:${TAG} | |
log "Creating container..." | |
OPTIONS="--tmpfs /tmp --tmpfs /var/log -e USER_ID=\"${USER_ID}\" -e GROUP_ID=\"${GROUP_ID}\" -e TIMEZONE=\"${TIMEZONE}\" -e FREQUENCY=\"${FREQUENCY}\" -v ${VOLUME}:/easyepg" | |
if [ -n "${SOCKET}" ]; then | |
OPTIONS="${OPTIONS} -v ${SOCKET}:/xmltv.sock" | |
fi | |
if [ -n "${CPU_LIMIT}" ]; then | |
OPTIONS="${OPTIONS} --cpus ${CPU_LIMIT}" | |
fi | |
sh -c "docker create --name=easyepg.admin -e MODE=\"admin\" ${OPTIONS} qoopido/easyepg.minimal:${TAG} 1> /dev/null" | |
log "> easyepg.admin" | |
sh -c "docker create --name=easyepg.run -e MODE=\"run\" ${OPTIONS} qoopido/easyepg.minimal:${TAG} 1> /dev/null" | |
log "> easyepg.run" | |
sh -c "docker create --name=easyepg.cron -e MODE=\"cron\" --restart unless-stopped ${OPTIONS} qoopido/easyepg.minimal:${TAG} 1> /dev/null" | |
log "> easyepg.cron" | |
log "Finished!" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment