Skip to content

Instantly share code, notes, and snippets.

@cmlburnett
Last active June 14, 2021 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmlburnett/dd9a42dd6d0efbe3ba0d62248fec91ee to your computer and use it in GitHub Desktop.
Save cmlburnett/dd9a42dd6d0efbe3ba0d62248fec91ee to your computer and use it in GitHub Desktop.
# Installing plex on a Raspberry Pi as a stand-alone server in which users connect to its wifi as an access point
# DO NOT BLINDLY EXECUTE THIS BY COPY/PASTE
# USE EACH COMMAND AS A TEMPLATE FOR WHAT YOU DO
# YOU'VE BEEN WARNED
# There are things in comments you need to do
# 1) Enable SSH
# https://www.raspberrypi.org/documentation/remote-access/ssh/
# Boot > RP menu > Preferences > Raspberry Pi Configuration
# Interfaces > SSH > Enable
# Reboot
# 2) Update
sudo apt update
sudo apt install
# 3) Basic packages of a sane install
sudo apt install vim git nmap ntpdate rsync wget
# 4) Setup network
# Wifi is access point
# bridge wifi to local ethernet and masquerade
# https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md
sudo apt install hostapd dnsmasq
sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
# Put in your desired wifi access point IP (192.168.10.1 here)
# Be sure to use >> not > to append to dhcpcd.conf
sudo echo -en "\ninterface wlan0\n\tstatic ip_address=192.168.10.1/24\n\tnohook wpa_supplicant\n" >> /etc/dhcpcd.conf
# Put this in /etc/sysctl.d/routed-ap.conf (doesn't exist) and strip off the leading hash (bash was giving me grief so I did it manually)
## https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md
## Enable IPv4 routing
#net.ipv4.ip_forward=1
sudo netfilter-persistent save
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
# In the following, adjust the IP accordingly
# Assuming 192.168.10.1 is the wlan0 IP, then serve 192.168.10.2 - 192.168.10.250 as DHCP addresses
# Put this in /etc/dnsmasq.conf (again, bash giving me trouble so strip leading hash and
#interface=wlan0
#dhcp-range=192.168.10.2,192.168.10.250,255.255.255.0,24h
#domain=wlan
#address=/gw.wlan/192.168.10.1
sudo rfkill unblock wlan
# Adjust wifi access point settings (again, strip leading hash)
sudo vim /etc/hostapd/hostapd.conf
#country_code=UK
#interface=wlan0
#ssid=foo
#hw_mode=g
#channel=7
#macaddr_acl=0
#auth_algs=1
#ignore_broadcast_ssid=0
#wpa=2
#wpa_passphrase=bar
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP
sudo reboot
# Check that wifi is working and can connect via wifi
# If ethernet is plugged in, it should permit internet access via wifi
# If ethernet is not plugged in, it should not. Sanity check to ensure you're actually connected.
# 5) Setup storage
# This is however many drives you want, etc
# 5a) This example is a single 512 GB USB thumb drive to be mounted as /mnt/plex1
parted /dev/sda --align optimal
# Inside parted are the following commands (had 4 partitions to begin with)
# rm 1
# rm 2
# rm 3
# rm 4
# mklabel gpt
# mkpart ext4 0% 100%
# quit
mke2fs -m 0 /dev/sda1
# Get UUID of the partition for /dev/sda1
lsblk -o NAME,PARTUUID
# Edit /etc/fstab
PARTUUID=b641d95b-b013-401b-b359-4ace09273f5e /mnt/plex1 ext4 defaults,nofail 0 2
mkdir /mnt/plex1
mount /mnt/plex1
# 5c) Repeat for other drives
# 5d) Set up directories on a local drive that is on the root filesystem
mkdir /mnt/local
mkdir /mnt/local/Movies
mkdir /mnt/local/TV
mkdir /mnt/local/MVids
# 5d) Setup Plex directories (do this as you see fit)
mkdir /mnt/plex1/Movies
mkdir /mnt/plex1/TV
mkdir /mnt/plex1/MVids
# Will need to change ownership after installing plex as the user doesn't exist yet
# 6a) Add plex repository
# https://pimylifeup.com/raspberry-pi-plex-server/
sudo apt-get install apt-transport-https
curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
echo deb https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
sudo apt-get update
# 6b) Install Plex
sudo apt install plexmediaserver
# This will probably ask you to fix /etc/apt/sources.list.d/plexmediaserver.list
# I said yes
# 6c) Setup file permissions
chown plex.plex -R /mnt/local/
chown plex.plex -R /mnt/plex1/
# 6d) Setup Plex
# Add "ip=192.168.0.XXX" or whatever to the end of the line
sudo vim /boot/cmdline.txt
sudo systemctl reboot
# 7) Setup Samba
# https://pimylifeup.com/raspberry-pi-samba/
sudo apt-get install samba samba-common-bin
# I don't want WINS support, so say no when asked
# Edit /etc/samba/smb.conf
vim /etc/samba/smb.conf
# Comment out all shares in there
# Add a new share
[plexlocal]
path = /mnt/local
read only = no
browseable = yes
[plex1]
path = /mnt/plex1
read only = no
browseable = yes
# Done with the config? Reboot
sudo systemctl reboot
# 8) Done
# Install anything else you care about
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment