Raspberry Pi 4


Boot without the monitor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

echo '''
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN

network={
ssid="xxx"
psk="xxx"
}
''' > wpa_supplicant.conf

# copy wpa_supplicant, ssh or ssh.txt to the root of the sd card

sudo raspi-config

# crontab -e
# @reboot sudo ifdown wlan1
sudo iwconfig wlan1 txpower off
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# EEPROM
sudo apt -y update
sudo apt -y upgrade
sudo apt -y install rpi-eeprom
sudo rpi-eeprom-update
sudo rpi-eeprom-update -a

# oh-my-zsh
sudo apt-get install zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
sudo apt -y install vim

sudo chsh -s /bin/zsh

# pi-hole
curl -sSL https://install.pi-hole.net | bash

# piVPN
curl -L https://install.pivpn.io | bash
pivpn add
pivpn remove
pivpn list
pivpn -qr

Passwordless SSH access

1
2
3
4
5
6
7
8
9
cd ~/.ssh
ssh-keygen
# raspberrypi
cat raspberrypi.pub
cat ~/.ssh/raspberrypi.pub | ssh pi@192.168.2.2 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'

chmod g-w $HOME
chmod 700 $HOME/.ssh
chmod 600 $HOME/.ssh/authorized_keys

Static IP address

1
2
3
4
5
6
# vim /etc/dhcpcd.conf

interface eth0
static ip_address=192.168.0.4/24
static routers=192.168.0.254
static domain_name_servers=192.168.0.254 8.8.8.8

AdGuard

1
2
3
4
5
6
7
8
9
10

cd $HOME
wget https://static.adguard.com/adguardhome/release/AdGuardHome_linux_armv6.tar.gz
tar xvf AdGuardHome_linux_armv6.tar.gz

sudo setcap 'CAP_NET_BIND_SERVICE=+eip CAP_NET_RAW=+eip' ./AdGuardHome

# crontab -e
@reboot /home/pi/AdGuardHome/AdGuardHome &

clash

1
2
3
4
5
6
wget https://github.com/Dreamacro/clash/releases/download/v1.5.0/clash-linux-armv7-v1.5.0.gz
tar xzvf clash-linux-armv7-v1.5.0.gz


@reboot /home/pi/clash-linux-armv7 &

VNC

https://magpi.raspberrypi.org/articles/vnc-raspberry-pi

Rclone & Google Drive

1
2
3
4
5
6
7
8
9
10
sudo apt -y install fuse

curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash
rclone config

mkdir -p /tmp/gdrive
fusermount -u /tmp/gdrive

sudo vim /etc/fuse.conf
# user_allow_other

Auto Mount

1
2
3
4
5
6
7
8
9
10
11
sudo blkid

# sudo vim /etc/fstab

UUID=633a8bc8 /media/3T ext4 defaults,auto,users,rw,nofail 0 0
UUID=d271d018 /media/TM ext4 defaults,auto,users,rw,nofail 0 0
UUID=53f3ce6b /media/8G ext4 defaults,auto,users,rw,nofail 0 0



sudo chown -R pi:pi /media/3T /media/TM

Ramdisk & Logs

1
2
3
4
5
6
7
8
9
# sudo service rsyslog stop
# sudo systemctl disable rsyslog

# sudo vim /etc/fstab

tmpfs /var/lib/plexmediaserver tmpfs defaults,noatime 0 0
tmpfs /home/pi./cache tmpfs defaults,noatime 0 0
tmpfs /tmp tmpfs defaults,noatime 0 0
tmpfs /var/log tmpfs defaults,noatime 0 0

Fix Ext4

sudo fsck.ext4 -vfy /dev/sda2

Swap space on an external hard drive

1
2
3
4
sudo vim /etc/dphys-swapfile

CONF_SWAPFILE=/media/3T/swapfile
CONF_SWAPSIZE=8192

AFP & Time Machine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo apt -y install netatalk gparted

# sudo mkfs.ext4 /dev/sda2
# sudo mkfs.ext4 /dev/sda3
# sudo mkdir /media/TM
# sudo mount /dev/sda3 /media/TM
# sudo chown -R pi:pi /media/3T
# sudo chown -R pi:pi /media/TM

sudo vim /etc/netatalk/afp.conf
# ;[3T]
# ; path = /media/3T/
# ;[tmp]
# ; path = /tmp/
# [TM]
# path = /media/TM/
# time machine = yes


sudo systemctl restart netatalk

Samba

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sudo apt-get install samba samba-common-bin

sudo vim /etc/samba/smb.conf
# [pimylifeupshare]
# path = /media/3T/
# writeable=Yes
# create mask=0777
# directory mask=0777
# public=no
# [tmp]
# path = /tmp/
# writeable=Yes
# create mask=0777
# directory mask=0777
# public=no
sudo smbpasswd -a pi
sudo systemctl restart smbd

Plex Server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
mkdir -p "/tmp/plexmediaserver"
sudo mount -t tmpfs -o size=1000M tmpfs /tmp/plexmediaserver
sudo chown -R pi:pi /var/lib/plexmediaserver

sudo apt -y 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 -y install plexmediaserver

sudo vim /etc/default/plexmediaserver
# export PLEX_MEDIA_SERVER_USER=pi

hostname -I
sudo vim /boot/cmdline.txt
# ip=IPADDRESS

# sudo apt -y install pmount
# sudo apt-get install ntfs-3g exfat-fuse exfat-utils pmount
# sudo apt-get install hfsplus hfsutils hfsprogs gdisk

# lsblk

# /lib/systemd/system/plexmediaserver.service

# user plex to pi
sudo mkdir -p /etc/systemd/system/plexmediaserver.service.d
sudo vim /etc/systemd/system/plexmediaserver.service.d/override.conf
# [Service]
# User=pi
# Group=pi

# [Service]
# ExecStartPre=/bin/sleep 120;/bin/sh -c '/usr/bin/test -d "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" || /bin/mkdir -p "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}"'

# data folder

sudo systemctl stop plexmediaserver

sudo service plexmediaserver stop

sudo systemctl enable plexmediaserver.service
sudo systemctl restart plexmediaserver.service

Crontab -e

1
sudo apt -y install php php-curl

crontab -e

1
2
3
4
5
6
7
8

# rclone

echo '''mkdir -p /tmp/gdrive
fusermount -u /tmp/gdrive
/usr/bin/rclone mount Plex:Plex /tmp/gdrive --umask 0000 --default-permissions --allow-non-empty --allow-other --buffer-size 64M --dir-cache-time 48h --vfs-read-chunk-size 128M --vfs-read-chunk-size-limit 1500M &
''' > rclone.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

# Backup

# tar --exclude="$PlexPath/Logs" --exclude="$PlexPath/Cache" --exclude="$PlexPath/Crash Reports" -czf /tmp/gdrive/backup/plex.tar.gz /var/lib/plexmediaserver

echo '''
mkdir -p /tmp/gdrive/backup/

PlexPath="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
tar cf - --exclude="$PlexPath/Logs" --exclude="$PlexPath/Cache" --exclude="$PlexPath/Crash Reports" /var/lib/plexmediaserver | lz4 -f - /tmp/gdrive/backup/plex.tar.lz4
''' > backup.sh

# Restore

echo '''
lz4 -d /tmp/gdrive/backup/plex.tar.lz4 | tar -xC /

PlexPath="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
mkdir -p "$PlexPath/Logs" "$PlexPath/Cache" "$PlexPath/Crash Reports"
''' > restore.sh


chmod a+x backup.sh restore.sh

# Update

echo '''
sudo apt update && sudo apt upgrade && sudo apt autoremove && sudo apt clean
pihole -up && pihole -g
''' > update.sh

chmod a+x update.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
@reboot vncserver

# @reboot pmount sda2 3T
# @reboot pmount sda3 TM

@reboot /home/pi/rclone.sh
@reboot sleep 30 && /home/pi/restore.sh

*/30 * * * * /home/pi/backup.sh
0 3 * * * /home/pi/update.sh

0 22 * * * cd ~/Bot;python3 autoPill.py
0 9 * * * php ~/Bot/bilibiliRun.ph

sudo crontab -e

1
2
# 0 4 * * * /sbin/shutdown -r
@reboot sleep 90 && sudo service plexmediaserver start

Jellyfin

https://jellyfin.org/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
sudo apt install apt-transport-https
wget -O - https://repo.jellyfin.org/jellyfin_team.gpg.key | sudo apt-key add -
echo "deb [arch=$( dpkg --print-architecture )] https://repo.jellyfin.org/$( awk -F'=' '/^ID=/{ print $NF }' /etc/os-release ) $( awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release ) main" | sudo tee /etc/apt/sources.list.d/jellyfin.list
sudo apt update
sudo apt install jellyfin

# service jellyfin status
# systemctl restart jellyfin
# sudo /etc/init.d/jellyfin stop

# .local/share/jellyfin

echo '''#!/bin/zsh
JELLYFINTMP="/tmp/jellyfin"
USRBIN="/usr/bin"
mkdir -p $JELLYFINTMP/log $JELLYFINTMP/cache $JELLYFINTMP/transcodes \
$JELLYFINTMP/data \
$JELLYFINTMP/metadata \
$JELLYFINTMP/config

$USRBIN/jellyfin \
-C $JELLYFINTMP/cache \
-l $JELLYFINTMP/log \
-d $JELLYFINTMP/data \
-c $JELLYFINTMP/config \
--ffmpeg $USRBIN/ffmpeg &
''' > jellyfin.sh

chmod a+x jellyfin.sh
nohup ./jellyfin.sh </dev/null &

sudo systemctl disable jellyfin

# https://jellyfin.org/docs/general/administration/hardware-acceleration.html
sudo usermod -aG video jellyfin

Translated by gpt-3.5-turbo