Skip to content

Instantly share code, notes, and snippets.

@eggplants
Last active November 14, 2024 14:42
Show Gist options
  • Save eggplants/afaa31d65a1603f4868c0c400d7d5430 to your computer and use it in GitHub Desktop.
Save eggplants/afaa31d65a1603f4868c0c400d7d5430 to your computer and use it in GitHub Desktop.
My setup for Mirakc / EPGStation / KonomiTV on NanoPi R6S
#!/usr/bin/env bash
# Updated at: 2024-11
# Environment:
# - Machine: NanoPi R6S
# - Tuner:
# - PX-M1UR (/dev/pxm1urvideo0)
# - PX-W3U4 (/dev/px4video{0..3})
# - Card reader: SCR3310 v2.0
# - OS: rk3588-sd-debian-bullseye-core-5.10-arm64-20230909.img
# - Debian 11 / Linux 5.10
# - https://drive.google.com/file/d/1wfr-ZcSpmTKwAF5XmYM1y64-YrIRrn-m
# Architecture:
# ```
# $ uname -vorm
# 5.10.160 #194 SMP Tsu Sep 7 15:19:51 CST 2023 aarch64 GNU/Linux
# ```
#
# ...connect display and keyboard
#
sudo useradd -m -G 1000,4,20,24,27,29,30,44,46,50,101,108,111,1001 eggplants # GROUPS = `id pi -G | tr ' ' ,`
sudo passwd eggplants
sudo hostnamectl set-hostname npi01
sudo reboot
#
# ...login as `eggplants`
#
sudo apt update
sudo apt upgrade -y
#
# Install Tailscale
#
sudo apt install ca-certificates curl dialog nano -y
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up --qr
sudo reboot
#
# ...run `ssh eggplants@npi01.*.ts.net`
#
chsh -s /bin/bash
bash
sudo userdel -r pi
sudo timedatectl set-timezone Asia/Tokyo
mkdir -m 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
#
# ~ copy `gpg --export-ssh-key ...` to authorized_keys
#
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
sudo sed -i '/#PasswordAuthentication yes/aPasswordAuthentication no' /etc/ssh/sshd_config
sudo service ssh restart
#
# ...check ssh connectivity without password authentication
#
sudo reboot
#
# Setup
#
mkdir _tv
pushd _tv
#
# Install px4_drv v0.5.1
# https://github.com/tsukumijima/px4_drv/releases
#
sudo apt install -y -f /opt/linux-headers-"$(uname -r)"*.deb
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'
#
# 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 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
sudo apt autoremove -y
# check
node --version
#
# Install mise - python, lazydocker
#
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
mise plugin install https://github.com/comdotlinux/asdf-lazydocker.git
mise use --global lazydocker
#
# 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-1_arm64.deb
sudo apt install ./recisdb_1.2.2-1_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/tags
#
sudo apt install git -y
git clone --depth 1 https://github.com/l3tnun/EPGStation.git epgstation
pushd epgstation
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.template --ignore-whitespace -o config/config.yml <<EOS
--- config/config.yml.template 2024-11-10 22:49:17.386195704 +0900
+++ config/config.yml 2024-11-10 22:51:22.176546790 +0900
@@ -1,24 +1,13 @@
port: 8888
-mirakurunPath: http+unix://%2Fvar%2Frun%2Fmirakurun.sock/
-
-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
+mirakurunPath: 'http://mirakc:40772/'
+dbtype: mysql
+mysql:
+ host: mysql
+ port: 3306
+ user: epgstation
+ password: epgstation
+ database: epgstation
epgUpdateIntervalTime: 10
conflictPriority: 1
@@ -34,8 +23,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/recisdb_1.2.2-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/px4video0
# - /dev/px4video1
# - /dev/px4video2
# - /dev/px4video3
- /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 requirements for rkmppenc
#
# libmali-rockchip
wget https://github.com/tsukumijima/libmali-rockchip/releases/download/v1.9-1-55611b0/libmali-valhall-g610-g13p0-wayland-gbm_1.9-1_arm64.deb
sudo apt install -y ./libmali-valhall-g610-g13p0-wayland-gbm_1.9-1_arm64.deb
# rockchip-multimedia-config
wget https://github.com/tsukumijima/rockchip-multimedia-config/releases/download/v1.0.2-1/rockchip-multimedia-config_1.0.2-1_all.deb
sudo apt install -y ./rockchip-multimedia-config_1.0.2-1_all.deb
sudo reboot
#
# Install KonomiTV 0.11.0
# https://github.com/tsukumijima/KonomiTV/releases
#
sudo npm install pm2 -g
sudo apt install gcc python3-dev lshw libvorbis-dev -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/
rkmppenc
/mnt/hdd1/TV-Capture
EOS
#
# Export channels to m3u8 playlist
#
TS_HOST="${HOSTNAME}.$(tailscale status --json | grep -m1 MagicDNSSuffix | cut -f4 -d'"')"
curl -o channels.json http://localhost:40772/api/channels
wget https://gist.githubusercontent.com/eggplants/ca989cea260d03747f0e2a7fcec29fec/raw/ch2pl.py
python ch2pl.py channels.json -e "http://${TS_HOST}:40772" >channels.m3u8
#
# Install Prometheus
#
sudo apt install prometheus prometheus-node-exporter -y
#
# Install Grafana
#
sudo apt install apt-transport-https software-properties-common -y
sudo mkdir -p /etc/apt/keyrings/
curl -sSL https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install grafana-enterprise -y
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server
sudo systemctl enable grafana-server.service
# check:
#
# Mirakc: http://${TS_HOST}:40772/api/version
# EPGStation: http://${TS_HOST}:8888/#/
# KonomiTV: https://$(tailscale ip --4 npi01 | tr . -).local.konomi.tv:7000/tv/
# Grafana: http://${TS_HOST}:3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment