aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md72
-rw-r--r--compose.yaml22
-rwxr-xr-xsetup-plex.sh58
3 files changed, 152 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..148947e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,72 @@
+# Plex Server Setup
+
+This repository contains scripts and configuration for setting up a Plex Media
+Server. I run this on a Raspberry Pi 4B running Debian.
+
+## Assumptions
+
+- Server running Debian (e.g. apt-based)
+- External storage device with UUID `2c882f17-50e7-4099-a305-693f4aa0113b`
+ - Comment out `ensure_fstab_entry` if you're not using a separate external
+ hard drive for your media or change the UUID as needed. If you comment it
+ out, we'll want to adjust the Plex data directory from `/mnt/media/Plex` to
+ wherever your data will be.
+- Plex account and claim token
+
+## Installation
+
+1. Copy the files over to your server:
+```sh
+scp compose.yaml <username>@<server>:/home/<username>/compose.yaml
+scp setup-plex.sh <username>@<server>:/home/<username>/setup-plex.sh
+```
+
+2. SSH into your server:
+```sh
+ssh <username>@<server>
+```
+
+3. Set the plex claim token (get a claim token at https://www.plex.tv/claim/):
+```sh
+sed 's|PLEX_CLAIM=<your-plex-claim-token>|PLEX_CLAIM=your-actual-token-here|' compose.yaml > compose.yaml.tmp \
+ && mv compose.yaml.tmp compose.yaml
+```
+
+4. Additionally, the timezone is hard-coded to 'America/New_York'. If that's not
+your timezone, adjust it in the `compose.yaml` file:
+```sh
+sed 's|TZ=America/New_York|TZ=your-timezone-here|' compose.yaml > compose.yaml.tmp \
+ && mv compose.yaml.tmp compose.yaml
+```
+
+5. Run the installation script to set up an fstab entry for a external hard drive
+and install docker:
+
+```sh
+chmod +x setup-plex.sh
+sudo ./setup-plex.sh
+```
+
+6. After the fstab entry is added, ensure the drive is mounted for the external
+hard drive:
+```sh
+sudo mount -a
+```
+
+7. Now, finally, we can start plex:
+```bash
+docker compose up --detach
+```
+
+## Configuration
+
+### Volume Mappings
+
+- `/mnt/media/Plex` - Media files on an external drive
+- `/opt/plex-config` - Plex configuration and metadata on the server drive
+- `/opt/plex-transcode` - Temporary transcoding files on the server drive
+
+### Ports
+
+Plex uses multiple ports for different features. All necessary ports are exposed
+in the compose file.
diff --git a/compose.yaml b/compose.yaml
new file mode 100644
index 0000000..1b71442
--- /dev/null
+++ b/compose.yaml
@@ -0,0 +1,22 @@
+services:
+ plex:
+ image: plexinc/pms-docker
+ container_name: plex
+ restart: unless-stopped
+ ports:
+ - "32400:32400/tcp"
+ - "3005:3005/tcp"
+ - "8324:8324/tcp"
+ - "32469:32469/tcp"
+ - "1900:1900/udp"
+ - "32410:32410/udp"
+ - "32412:32412/udp"
+ - "32413:32413/udp"
+ - "32414:32414/udp"
+ environment:
+ - TZ=America/New_York
+ - PLEX_CLAIM=<your-plex-claim-token>
+ volumes:
+ - /mnt/media/Plex:/data
+ - /opt/plex-config:/config
+ - /opt/plex-transcode:/transcode
diff --git a/setup-plex.sh b/setup-plex.sh
new file mode 100755
index 0000000..ee282b1
--- /dev/null
+++ b/setup-plex.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+set -e
+
+main() {
+ ensure_fstab_entry
+ install_docker_gpg_key
+ add_docker_repository
+ install_docker
+}
+
+ensure_fstab_entry() {
+ _fstab_uuid="2c882f17-50e7-4099-a305-693f4aa0113b"
+ _fstab_mount_point="/mnt/media"
+ _fstab_fs_type="xfs"
+ _fstab_options="defaults"
+ _fstab_dump="0"
+ _fstab_pass="2"
+ _fstab_entry="UUID=${_fstab_uuid} ${_fstab_mount_point} ${_fstab_fs_type} ${_fstab_options} ${_fstab_dump} ${_fstab_pass}"
+
+ if ! grep -q "UUID=${_fstab_uuid}" /etc/fstab; then
+ echo "Adding mount entry to /etc/fstab..."
+ echo "${_fstab_entry}" | sudo tee -a /etc/fstab >/dev/null
+ echo "Creating mount point if it doesn't exist..."
+ sudo mkdir -p "${_fstab_mount_point}"
+ else
+ echo "Mount entry already exists in /etc/fstab"
+ fi
+}
+
+install_docker_gpg_key() {
+ sudo apt-get update
+ sudo apt-get install --yes ca-certificates curl
+ sudo install --mode=0755 --directory /etc/apt/keyrings
+ sudo curl --fail --silent --show-error --location \
+ https://download.docker.com/linux/ubuntu/gpg \
+ --output /etc/apt/keyrings/docker.asc
+ sudo chmod a+r /etc/apt/keyrings/docker.asc
+}
+
+add_docker_repository() {
+ # shellcheck disable=SC1091
+ echo \
+ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
+ $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" |
+ sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
+}
+
+install_docker() {
+ sudo apt-get update
+ sudo apt-get install --yes \
+ docker-ce \
+ docker-ce-cli \
+ containerd.io \
+ docker-buildx-plugin \
+ docker-compose-plugin
+}
+
+main "$@"