diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-03-28 13:26:20 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-03-28 13:33:00 -0400 |
| commit | 3bb961484cc6a8403d70794ab53beee7613e5ec7 (patch) | |
| tree | d28a541f0dcedff3691fc83e8c6ff771f8314de5 | |
| parent | Fix rendered formatting of numbered list on git.sr.ht (diff) | |
| download | plex-setup-3bb961484cc6a8403d70794ab53beee7613e5ec7.zip | |
Use env file and break out setup-plex into two scripts
| -rw-r--r-- | .env.example | 12 | ||||
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 86 | ||||
| -rw-r--r-- | compose.yaml | 6 | ||||
| -rwxr-xr-x | setup-docker.sh (renamed from setup-plex.sh) | 28 | ||||
| -rwxr-xr-x | setup-drive.sh | 46 |
6 files changed, 113 insertions, 66 deletions
diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e49e983 --- /dev/null +++ b/.env.example @@ -0,0 +1,12 @@ +# Timezone for the Plex container. +# See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones +TZ=America/New_York + +# Plex claim token. Go to https://www.plex.tv/claim/ to get one. +PLEX_CLAIM= + +# Root of your media library +# +# Must match FSTAB_MOUNT_POINT in setup-drive.sh if you're using a separate +# drive. +MEDIA_DIR=/mnt/media diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env @@ -1,85 +1,79 @@ # 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 Ubuntu. - -## Assumptions - -- Server running Ubuntu -- 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 +Server on Ubuntu. I run this on a Raspberry Pi 4B. + +* [Installation](#installation) + * [1. Copy the Files over to Your Server](#1.-copy-the-files-over-to-your-server) + * [2. SSH into Your Server](#2.-ssh-into-your-server) + * [3. Configure Your Environment](#3.-configure-your-environment) + * [Copy the Example Env File](#copy-the-example-env-file) + * [Fill in PLEX_CLAIM with Your Plex Claim Token](#fill-in-plex_claim-with-your-plex-claim-token) + * [4. Run the Installation Scripts](#4.-run-the-installation-scripts) + * [Install Docker](#install-docker) + * [Set up External Drive](#set-up-external-drive) + * [5. Start Plex](#5.-start-plex) ## Installation -### 1. Copy the files over to your server +### 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 +scp compose.yaml .env.example setup-docker.sh setup-drive.sh <username>@<server>:/home/<username>/ ``` -### 2. SSH into your server +### 2. SSH into Your Server ```sh ssh <username>@<server> ``` -### 3. Set the plex claim token +### 3. Configure Your Environment -Get a claim token at https://www.plex.tv/claim/ +#### Copy the Example Env File ```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 +cp .env.example .env ``` -### 4. Adjust hard-coded timezone if necessary +#### Fill in PLEX_CLAIM with Your Plex Claim Token + +[Get a claim token from Plex](https://www.plex.tv/claim/) + +### 4. Run the Installation Scripts -The timezone is hard-coded to 'America/New_York'. If that's not your timezone, -adjust it in the `compose.yaml` file. +#### Install Docker ```sh -sed 's|TZ=America/New_York|TZ=your-timezone-here|' compose.yaml > compose.yaml.tmp \ - && mv compose.yaml.tmp compose.yaml +chmod +x setup-docker.sh +sudo ./setup-docker.sh ``` -### 5. Run the installation script +#### Set up External Drive -This will set up a fstab entry for a external hard drive and install docker. +If you're using an external hard drive for your media, set up the fstab entry +for it: ```sh -chmod +x setup-plex.sh -sudo ./setup-plex.sh +chmod +x setup-drive.sh +sudo ./setup-drive.sh ``` -### 6. Ensure external drive is mounted +The defaults use my hard drive assumptions. To use different configuration, pass +the overrides before the command: + +```sh +FSTAB_UUID=your-uuid FSTAB_MOUNT_POINT=/mnt/data FSTAB_FS_TYPE=ext4 sudo -E ./setup-drive.sh +``` -After the fstab entry is added, ensure the drive is mounted for the external -hard drive. +After you've added the fstab entry, mount the drive: ```sh sudo mount -a ``` -### 7. Start Plex +### 5. Start Plex -```bash +```sh 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 index 1b71442..8dfc48d 100644 --- a/compose.yaml +++ b/compose.yaml @@ -14,9 +14,9 @@ services: - "32413:32413/udp" - "32414:32414/udp" environment: - - TZ=America/New_York - - PLEX_CLAIM=<your-plex-claim-token> + - TZ=${TZ} + - PLEX_CLAIM=${PLEX_CLAIM} volumes: - - /mnt/media/Plex:/data + - ${MEDIA_DIR}/Plex:/data - /opt/plex-config:/config - /opt/plex-transcode:/transcode diff --git a/setup-plex.sh b/setup-docker.sh index ee282b1..b421872 100755 --- a/setup-plex.sh +++ b/setup-docker.sh @@ -2,29 +2,23 @@ set -e main() { - ensure_fstab_entry + parse_args "$@" 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}" +parse_args() { + case "${1:-}" in + -h | --help) usage ;; + esac +} - 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 +usage() { + echo "Usage: sudo ./setup-docker.sh [-h]" + echo "" + echo "Installs Docker on Ubuntu." + exit 0 } install_docker_gpg_key() { diff --git a/setup-drive.sh b/setup-drive.sh new file mode 100755 index 0000000..f678178 --- /dev/null +++ b/setup-drive.sh @@ -0,0 +1,46 @@ +#!/bin/sh +set -e + +main() { + parse_args "$@" + ensure_fstab_entry +} + +parse_args() { + case "${1:-}" in + -h | --help) usage ;; + esac +} + +usage() { + echo "Usage: sudo [-E] ./setup-drive.sh [-h]" + echo "" + echo "Adds an fstab entry for an external media drive." + echo "" + echo "Environment variables (all optional):" + echo " FSTAB_UUID UUID of the external media drive (default: 2c882f17-...)" + echo " FSTAB_MOUNT_POINT Mount point for the media drive (default: /mnt/media)" + echo " FSTAB_FS_TYPE Filesystem type of the drive (default: xfs)" + exit 0 +} + +ensure_fstab_entry() { + _fstab_uuid="${FSTAB_UUID:-2c882f17-50e7-4099-a305-693f4aa0113b}" + _fstab_mount_point="${FSTAB_MOUNT_POINT:-/mnt/media}" + _fstab_fs_type="${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 +} + +main "$@" |