#!/bin/bash ### Script for building and running a media processing system using docker ### Adam Dodman # Prereqs: docker, docker-compose, curl (https), git export VOLDIR="/volumes/media-server" SERVICES=("couchpotato" "deluge" "nzbget" "plex" "plexpy" "sickrage" "nginx") SERVICEUID=("745" "647" "236" "787" "426" "439" "0") [[ $EUID -ne 0 ]] && echo "Please run this script as root" && exit 1 #Check if docker is installed and running docker version &> /dev/null [[ $? -ne 0 ]] && echo "Cannot connect to Docker daemon. Please check your configuration." && exit 1 #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. to keep the size down use tianon/true)" && exit 1 # Check if volumes folder exists [[ ! -d $VOLDIR ]] && echo "Creating volumes folder..." && mkdir -p $VOLDIR 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 -R ${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 "\n" > $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml && chown -R 787:787 $VOLDIR/plex [[ ! -a ./docker-compose.yml ]] && echo "Downloading Docker Compose config.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/master/docker-compose.yml > ./docker-compose.yml [[ ! -a $VOLDIR/nginx/nginx.cfg ]] && echo "Downloading nginx.cfg..." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/master/nginx.cfg > $VOLDIR/nginx/nginx.cfg [[ ! -d $VOLDIR/nginx/Organizr ]] && echo "Downloading Organizr..." && git -C $VOLDIR/nginx clone https://github.com/causefx/Organizr && chown -R 82:82 $VOLDIR/nginx/Organizr cd $VOLDIR/nginx/Organizr/ && git pull echo "#####################################" echo "# Config and directory struture OK! #" echo "#####################################" echo echo "Run docker-compose up -d to start the containers..."