Skip to content

Instantly share code, notes, and snippets.

@eggplants
Last active November 6, 2024 14:23
Show Gist options
  • Save eggplants/bf335687539efd399cd5477f894c9fd2 to your computer and use it in GitHub Desktop.
Save eggplants/bf335687539efd399cd5477f894c9fd2 to your computer and use it in GitHub Desktop.
My setup for Mirakc / EPGStation on RaspberryPi 4
#!/usr/bin/env bash
# Updated at: 2024-09-01
# Environment:
# - Machine: RaspberryPi 4
# - Tuner: PX-M1UR
# - Card reader: SCR3310 v2.0
# - OS: RaspberryPi OS Lite (Debian GNU/Linux 12 bookworm)
# Architecture:
# ```
# $ uname -vorm
# 6.6.31+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux
# ```
MDNS_HOST="$(grep -P '^(?!.*localhost$)127\.0\.[0-9]+.1' /etc/hosts | tail -1 | cut -f2).local"
#
# Connect from host PC
#
# ssh [email protected]
#
# Disable swap
#
sudo systemctl stop dphys-swapfile
sudo systemctl disable dphys-swapfile
sudo rm -f /var/swap
#
# Enable ntp
#
echo 'NTP=ntp.nict.jp' | sudo tee -a /etc/systemd/timesyncd.conf
sudo systemctl restart systemd-timesyncd
#
# Setup
#
mkdir _tv
pushd _tv
#
# Mount external storage
#
sudo fdisk -l > before
echo ...insert storage...
read
sudo fdisk -l > after
hdd="$(diff before after | grep -E '^> Disk /dev/' | cut -d' ' -f3)"
# > Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
# format storage with ext4 and mount to /mnt/hdd1
sudo mkfs -t ext4 "$hdd"
sudo mkdir -m 777 /mnt/hdd1
sudo mount -t ext4 "$hdd" /mnt/hdd1
echo "$hdd" '/mnt/hdd1 ext4 defaults 0 0' | sudo tee -a /etc/fstab
#
# Install Tailscale
#
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
#
# Install Docker Engine
#
sudo apt update
sudo apt upgrade -y
curl -fsSL https://get.docker.com -o get-docker.sh
DRY_RUN=1 sh ./get-docker.sh # check executing commands
DEBIAN_FRONTEND=noninteractive sudo sh get-docker.sh
sudo usermod -aG docker $USER
newgrp docker
# check
docker info
#
# Install nodejs
#
sudo apt install nodejs npm -y
sudo npm install n -g
sudo n lts
sudo apt purge nodejs npm -y
# check
node --version
#
# Install Python3
#
curl https://mise.run | sh
echo 'eval "$($HOME/.local/bin/mise activate bash)"' >>~/.bashrc
eval "$($HOME/.local/bin/mise activate bash)"
mise use --global python@latest
# check
python --version
#
# Install px4_drv v0.5.1
# https://github.com/tsukumijima/px4_drv/releases
#
wget https://github.com/tsukumijima/px4_drv/releases/download/v0.5.1/px4-drv-dkms_0.5.1_all.deb
sudo apt install ./px4-drv-dkms_0.5.1_all.deb -y
sudo modprobe px4_drv
# check
ls /dev | grep -E 'px|isdb'
#
# Install recisdb-rs v1.2.2
# https://github.com/kazuki0824/recisdb-rs/releases
#
wget https://github.com/kazuki0824/recisdb-rs/releases/download/1.2.2/recisdb_1.2.2_arm64.deb
sudo apt install ./recisdb_1.2.2_arm64.deb -y
# check
recisdb --version
#
# Install ISDBScanner v1.2.0
# https://github.com/tsukumijima/ISDBScanner/releases
#
sudo wget https://github.com/tsukumijima/ISDBScanner/releases/download/v1.2.0/isdb-scanner-arm -O /usr/local/bin/isdb-scanner
sudo chmod +x /usr/local/bin/isdb-scanner
# check
isdb-scanner --version
#
# Generate list of viewable channels
#
isdb-scanner # Finished in 354.71 seconds.
# check
ls ./scanned
#
# Configure EPGStation v2.10.0
# https://github.com/l3tnun/EPGStation/releases
#
git clone --depth 1 https://github.com/l3tnun/EPGStation.git epgstation
pushd epgstation
cp config/config.yml.template config/config.yml
cp config/operatorLogConfig.sample.yml config/operatorLogConfig.yml
cp config/epgUpdaterLogConfig.sample.yml config/epgUpdaterLogConfig.yml
cp config/serviceLogConfig.sample.yml config/serviceLogConfig.yml
cp config/enc.js.template config/enc.js
patch -u config/config.yml --ignore-whitespace <<EOS
--- config/config.yml.template 2024-08-18 23:37:53.804736199 +0900
+++ config/config.yml 2024-08-19 00:51:05.380043633 +0900
@@ -1,23 +1,13 @@
port: 8888
-mirakurunPath: http+unix://%2Fvar%2Frun%2Fmirakurun.sock/
+mirakurunPath: 'http://mirakc:40772/'
-dbtype: sqlite
-# sqlite:
-# extensions:
-# - '/hoge/regexp.dylib'
-# regexp: true
-
-# dbtype: mysql
-# mysql:
-# host: 192.168.xx.xx
-# port: 3306
-# user: epgstation
-# password: epgstation
-# database: epgstation
-# charset: utf8mb4
-
-# 囲み文字を置換するか
-needToReplaceEnclosingCharacters: true
+dbtype: mysql
+mysql:
+ host: mysql
+ port: 3306
+ user: epgstation
+ password: epgstation
+ database: epgstation
epgUpdateIntervalTime: 10
@@ -34,8 +24,8 @@
thumbnailSize: 480x270
thumbnailPosition: 5
-ffmpeg: /usr/local/bin/ffmpeg
-ffprobe: /usr/local/bin/ffprobe
+ffmpeg: /usr/bin/ffmpeg
+ffprobe: /usr/bin/ffprobe
encodeProcessNum: 4
concurrentEncodeNum: 1
EOS
popd
#
# Launch mirakc / EPGStation
#
cat <<'EOS' >>./compose.yaml
services:
mirakc:
build:
dockerfile_inline: |
FROM mirakc/mirakc:debian
WORKDIR /tmp
RUN <<EOF
set -eux
curl -OL https://github.com/tsukumijima/libaribb25/releases/download/v0.2.9/libaribb25_0.2.9_arm64.deb
# curl -OL https://github.com/CobaltCas/CobaltCas/raw/master/dist/libcobaltcas_1.0.0_arm64.deb # softcas
curl -OL https://github.com/kazuki0824/recisdb-rs/releases/download/1.2.2-rc.2/recisdb_1.2.1-1_arm64.deb
apt update
apt install pcscd libpcsclite-dev libccid pcsc-tools -y # hardcas
apt install ./libaribb25_*.deb -y
# apt install ./libcobaltcas_*.deb -y # softcas
apt install ./recisdb_*.deb -y
apt autoremove -y
apt autoclean
rm -rf /var/lib/apt/lists/*
rm -rf /tmp/*
EOF
WORKDIR /
entrypoint: "sh -c 'pcscd && mirakc'" # hardcas
# entrypoint: mirakc # softcas
container_name: mirakc
init: true
restart: unless-stopped
devices:
- /dev/pxm1urvideo0
- /dev/bus/usb # hardcas
ports:
- 40772:40772
volumes:
- mirakc-epg:/var/lib/mirakc/epg
- $HOME/_tv/scanned/mirakc/config.yml:/etc/mirakc/config.yml:ro
environment:
TZ: Asia/Tokyo
RUST_LOG: info
mysql:
image: mariadb:11.5
container_name: mysql
ports:
- 3306:3306
volumes:
- /mnt/hdd1/mysql:/var/lib/mysql
environment:
MYSQL_USER: epgstation
MYSQL_PASSWORD: epgstation
MYSQL_ROOT_PASSWORD: epgstation
MYSQL_DATABASE: epgstation
TZ: "Asia/Tokyo"
LANG: ja_JP.UTF-8
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --performance-schema=false --expire_logs_days=1
restart: always
logging:
options:
max-size: "10m"
max-file: "3"
epgstation:
build:
dockerfile_inline: |
FROM l3tnun/epgstation:master-debian
WORKDIR /tmp
RUN <<EOF
set -eux
apt update
apt install ffmpeg -y
apt autoremove -y
apt autoclean
rm -rf /var/lib/apt/lists/*
rm -rf /tmp/*
EOF
WORKDIR /app
entrypoint: npm start
container_name: epgstation
volumes:
- ./epgstation/config:/app/config
- ./epgstation/data:/app/data
- ./epgstation/thumbnail:/app/thumbnail
- ./epgstation/logs:/app/logs
- /mnt/hdd1/recorded:/app/recorded
ports:
- 8888:8888
environment:
TZ: "Asia/Tokyo"
depends_on:
- mirakc
- mysql
restart: always
volumes:
mirakc-epg:
name: mirakc_epg
driver: local
EOS
docker compose up -d
#
# Install KonomiTV 0.11.0
# https://github.com/tsukumijima/KonomiTV/releases
#
sudo npm install pm2 -g
sudo apt install lshw -y
sudo mkdir /mnt/hdd1/TV-Capture
curl -LO https://github.com/tsukumijima/KonomiTV/releases/download/v0.11.0/KonomiTV-Installer-ARM.elf
chmod +x KonomiTV-Installer-ARM.elf
./KonomiTV-Installer-ARM.elf <<EOS
1
/opt/KonomiTV
Mirakurun
http://127.0.0.1:40772/
FFmpeg
/mnt/hdd1/TV-Capture
EOS
echo '/opt/KonomiTV/server/thirdparty/FFmpeg' | sudo tee -a /etc/ld.so.conf
sudo ldconfig
#
# Export channels to m3u8 playlist
#
curl -o channels.json http://127.0.0.1:40772/api/channels
wget https://gist.githubusercontent.com/eggplants/ca989cea260d03747f0e2a7fcec29fec/raw/ch2pl.py
python ch2pl.py channels.json -e "http://${MDNS_HOST}:40772" >channels.m3u8
#
# After these steps are executed,
# you can see WebUI at:
# - http://<raspberrypi address>:8888/
# you can fetch playlist file with:
# $ scp xxx@yyy:~/_tv/channels.m3u8 ~
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment