1
0
mirror of https://github.com/Adam-Ant/media-server-in-a-box synced 2024-11-08 21:46:23 +00:00
media-server-in-a-box/start.sh

40 lines
2.7 KiB
Bash
Raw Normal View History

2016-09-08 23:04:14 +00:00
#!/bin/bash
### Script for building and running a media processing system using docker
### Adam Dodman <adam.dodman@gmx.com>
# Prereqs: docker, docker-compose, curl (https)
2016-09-08 23:44:43 +00:00
export VOLDIR="/volumes/media-server"
SERVICES=("couchpotato" "deluge" "headphones" "nzbget" "plex" "plexpy" "sickrage" "launcher")
SERVICEUID=("745" "647" "526" "236" "787" "426" "439" "0")
2016-09-08 23:04:14 +00:00
[[ $EUID -ne 0 ]] && echo "Please run this script as root" && exit 1
#Check if docker is installed and running
docker version &> /dev/null
2016-09-08 23:44:43 +00:00
[[ $? -ne 0 ]] && echo "Cannot connect to Docker daemon. Please check your configuration." && exit 1
2016-09-08 23:04:14 +00:00
#Check if docker-compose is installed
docker-compose version &> /dev/null
[[ $? -ne 0 ]] && echo "docker-compose not found. Please check your configuration." && exit 1
# Check if media container is configured
[[ $(docker ps -a --filter="name=media" | wc -l) != "2" ]] && echo "Cannot find a media container - please configure one with your media mounted at /media inside the container before running this script (to keep the size down use tianon/true)" && exit 1
# Check if volumes folder exists
[[ ! -d $VOLDIR ]] && echo "Creating volumes folder..." && mkdir -p $VOLDIR
[[ ! -d $VOLDIR/couchpotato ]]
slen=${#SERVICES[@]}
for ((i=0; i<$slen; i++)); do
[[ ! -d $VOLDIR/${SERVICES[$i]} ]] && echo "Creating folder $VOLDIR/${SERVICES[$i]}" && mkdir -p $VOLDIR/${SERVICES[$i]}
[[ $( ls -dn $VOLDIR/${SERVICES[$i]} | awk '{print $3}') != ${SERVICEUID[$i]} ]] && echo "Chowning $VOLDIR/${SERVICES[$i]} to user ${SERVICEUID[$i]}" && chown ${SERVICEUID[$i]}:${SERVICEUID[$i]} $VOLDIR/${SERVICES[$i]}
done
#Since we are not using net=host, we need to whitelist the subnet in plex. ##TODO## Make this overrideable with commandline argument
[[ ! -a $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml ]] && echo Adding subnet to Plex Whitelist... && mkdir -p $VOLDIR/plex/Plex\ Media\ Server/ && \
echo -e "<?xml version="1.0" encoding="utf-8"?>\n<Preferences allowedNetworks="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | grep -v '172.*')/255.255.0.0" />" > $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml && chown -R 787:787 $VOLDIR/plex
2016-09-13 23:05:41 +00:00
[[ ! -a $VOLDIR/launcher/media-compose.yml ]] && echo "Downloading media-compose.yml.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/docker-compose.yml > $VOLDIR/launcher/media-compose.yml
2016-09-13 22:31:48 +00:00
[[ ! -a $VOLDIR/launcher/nginx.cfg ]] && echo "Downloading nginx.cfg..." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/nginx.cfg > $VOLDIR/launcher/nginx.cfg
2016-09-08 23:04:14 +00:00
echo "Starting services..."
exec docker-compose -p media -f $VOLDIR/launcher/media-compose.yml up -d