Recipe for MythTV Server

  • base netinst install of jessie - deselect everything from tasksel
    • hostname dvr – domain williams.lcl
    • default partition layout (discard, noatime on root)
    • 2nd SSD – ext4 (noatime, but NOT discard) on /mnt/scratch
  • > /etc/motd
  • apt-get --no-install-recommends install aptitude
  • aptitude install ssh (this will pull in xauth, but that's okay)
  • aptitude install fbset screen rsync psmisc file patch ethtool strace tcpdump vim
  • aptitude --without-recommends install dnsutils
  • adduser tdobes adm
  • aptitude install dbus
  • sed -i -e 's/^deb.* main$/& contrib non-free/g' /etc/apt/sources.list
  • aptitude update && aptitude forget-new
  • aptitude install intel-microcode firmware-linux-nonfree firmware-realtek # firmware for TV tuner card and NIC
  • aptitude install ifplugd
  • sed -i -e 's/^INTERFACES=""/INTERFACES="eth0"/g' /etc/default/ifplugd
  • sed -i -e 's/^allow-hotplug eth0/#allow-hotplug eth0/g' /etc/network/interfaces
  • aptitude --without-recommends install ntp
    echo '[Unit]' > /etc/systemd/system/ntp.service
    echo 'Description=Network Time Protocol daemon' >> /etc/systemd/system/ntp.service
    echo 'After=network.target' >> /etc/systemd/system/ntp.service
    echo >> /etc/systemd/system/ntp.service
    echo '[Service]' >> /etc/systemd/system/ntp.service
    echo 'ExecStart=/usr/sbin/ntpd -n -g -u ntp:ntp' >> /etc/systemd/system/ntp.service
    echo >> /etc/systemd/system/ntp.service
    echo '[Install]' >> /etc/systemd/system/ntp.service
    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ntp.service
    systemctl enable ntp.service
  • mkdir -p /etc/systemd/system/ssh.socket.d
    echo '[Socket]' > /etc/systemd/system/ssh.socket.d/port-2222.conf
    echo 'ListenStream=2222' >> /etc/systemd/system/ssh.socket.d/port-2222.conf
    systemctl disable ssh.service && systemctl enable ssh.socket
  • mkdir -p /etc/systemd/system/getty\@tty1.service.d
    echo '[Service]' > /etc/systemd/system/getty\@tty1.service.d/noclear.conf
    echo 'TTYVTDisallocate=no' >> /etc/systemd/system/getty\@tty1.service.d/noclear.conf
  • systemctl mask networking.service # we use ifplugd instead
    echo 'D /run/network 0755 root root' > /etc/tmpfiles.d/debian-networking.conf
    echo 'F /run/network/ifstate 0644 root root - lo=lo' >> /etc/tmpfiles.d/debian-networking.conf
  • aptitude purge acpid acpi-support-base # systemd-logind takes care of this
  • sed -i -e 's/^GRUB_CMDLINE_LINUX_DEFAULT="quiet"$/GRUB_CMDLINE_LINUX_DEFAULT="quiet panic=5"/g' /etc/default/grub && update-grub
  • systemctl mask keyboard-setup.service
    systemctl mask console-setup.service
    systemctl mask rc-local.service
  • aptitude --without-recommends install irqbalance
  • aptitude --without-recommends install nfs-common
    echo 'memoryalpha:/tank/music        /mnt/music     nfs     _netdev,auto,hard,nfsvers=3     0       0' >> /etc/fstab
    echo 'memoryalpha:/tank/photos        /mnt/photos     nfs     _netdev,auto,hard,nfsvers=3     0       0' >> /etc/fstab
    echo 'memoryalpha:/tank/videos        /mnt/videos     nfs     _netdev,auto,hard,nfsvers=3     0       0' >> /etc/fstab
    mkdir -p /mnt/music /mnt/photos /mnt/videos
    mount /mnt/music
    mount /mnt/photos
    mount /mnt/videos
  • echo 'deb http://www.deb-multimedia.org jessie main non-free' > /etc/apt/sources.list.d/dmo.list
    echo 'deb http://www.deb-multimedia.org jessie-backports main' >> /etc/apt/sources.list.d/dmo.list
    aptitude update
    aptitude -o Aptitude::Cmdline::ignore-trust-violations=true install deb-multimedia-keyring
    aptitude update
  • aptitude install xserver-xorg-video-intel xserver-xorg-input-evdev
  • aptitude install xinit evilwm xdotool x11vnc unclutter x11-xserver-utils
  • sed -i 's/START_UNCLUTTER="true"/START_UNCLUTTER="false"/g' /etc/default/unclutter
    sed -i -e 's/^use-ssh-agent$/#use-ssh-agent/g' /etc/X11/Xsession.options
  • dpkg-reconfigure x11-common – set “Users allowed to start the X server” to “Anybody”
  • aptitude install alsa-utils fonts-freefont-ttf
  • adduser williams
  • adduser williams audio
  • adduser williams video
  • adduser tdobes audio
  • adduser tdobes video
  • adduser tdobes dialout
  • adduser www-data dialout
  • aptitude install picocom python-serial
  • aptitude install unattended-upgrades
  • dpkg-reconfigure -plow unattended-upgrades # select “Yes”
  • sed -i -e 's/^127.0.1.1.*$/# &\n192.168.32.12\tdvr.williams.lcl\tdvr/g' /etc/hosts
  • aptitude install mythtv # enter mysql root password (once for server, then again for mythtv)
  • aptitude install kodi kodi-pvr-mythtv-cmyth
  • echo '#!/bin/sh' > /usr/local/bin/williams-xsession.sh
    echo >> /usr/local/bin/williams-xsession.sh
    echo 'pkill -9 evilwm' >> /usr/local/bin/williams-xsession.sh
    echo 'pkill -9 x11vnc' >> /usr/local/bin/williams-xsession.sh
    echo >> /usr/local/bin/williams-xsession.sh
    echo 'xrandr --output HDMI1 --mode 1920x1080 --rate 60.0' >> /usr/local/bin/williams-xsession.sh
    echo >> /usr/local/bin/williams-xsession.sh
    echo 'x11vnc -q -usepw -N -ncache 0 -shared -forever &' >> /usr/local/bin/williams-xsession.sh
    echo >> /usr/local/bin/williams-xsession.sh
    echo 'xset s off #disable screensaver' >> /usr/local/bin/williams-xsession.sh
    echo 'xset dpms 0 0 0 #disable automatic power saving' >> /usr/local/bin/williams-xsession.sh
    echo 'unclutter -grab -idle 2 & #daemon to auto-hide mouse' >> /usr/local/bin/williams-xsession.sh
    echo >> /usr/local/bin/williams-xsession.sh
    echo '#SHELL=/bin/bash xterm &' >> /usr/local/bin/williams-xsession.sh
    echo >> /usr/local/bin/williams-xsession.sh
    echo "exec evilwm -fn '*-clean-*'" >> /usr/local/bin/williams-xsession.sh
    chmod +x /usr/local/bin/williams-xsession.sh
    ln -s /usr/local/bin/williams-xsession.sh /home/williams/.xsession
    
    echo '[Unit]' > /etc/systemd/system/startx\@.service
    echo 'Description=Start Xorg for %I' >> /etc/systemd/system/startx\@.service
    echo >> /etc/systemd/system/startx\@.service
    echo '[Service]' >> /etc/systemd/system/startx\@.service
    echo 'ExecStart=-/usr/bin/startx' >> /etc/systemd/system/startx\@.service
    echo 'ExecStopPost=-/usr/bin/pkill -9 -U %I evilwm' >> /etc/systemd/system/startx\@.service
    echo 'User=%I' >> /etc/systemd/system/startx\@.service
    echo 'Restart=always' >> /etc/systemd/system/startx\@.service
    echo 'RestartSec=1' >> /etc/systemd/system/startx\@.service
    echo >> /etc/systemd/system/startx\@.service
    echo '[Install]' >> /etc/systemd/system/startx\@.service
    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/startx\@.service
    # systemctl enable startx\@williams.service # doesn't work on old systemd releases
    ln -s /etc/systemd/system/startx\@.service /etc/systemd/system/multi-user.target.wants/startx\@williams.service
    
    echo '#!/bin/sh' > /usr/local/bin/kodi.sh
    echo >> /usr/local/bin/kodi.sh
    echo 'echo -n waiting for mythbackend' >> /usr/local/bin/kodi.sh
    echo 'while ! pidof mythbackend > /dev/null 2> /dev/null ; do' >> /usr/local/bin/kodi.sh
    echo '  echo -n .' >> /usr/local/bin/kodi.sh
    echo '  sleep 1' >> /usr/local/bin/kodi.sh
    echo 'done' >> /usr/local/bin/kodi.sh
    echo 'echo done!' >> /usr/local/bin/kodi.sh
    echo >> /usr/local/bin/kodi.sh
    echo '# start kodi' >> /usr/local/bin/kodi.sh
    echo 'exec /usr/bin/kodi --standalone' >> /usr/local/bin/kodi.sh
    chmod +x /usr/local/bin/kodi.sh
    
    echo '[Unit]' > /etc/systemd/system/kodi.service
    echo 'Description=Kodi' >> /etc/systemd/system/kodi.service
    echo 'After=startx@williams.service' >> /etc/systemd/system/kodi.service
    echo 'Requires=startx@williams.service' >> /etc/systemd/system/kodi.service
    echo >> /etc/systemd/system/kodi.service
    echo '[Service]' >> /etc/systemd/system/kodi.service
    echo 'ExecStart=-/usr/local/bin/kodi.sh' >> /etc/systemd/system/kodi.service
    echo 'User=williams' >> /etc/systemd/system/kodi.service
    echo 'Environment=DISPLAY=:0' >> /etc/systemd/system/kodi.service
    echo 'Restart=always' >> /etc/systemd/system/kodi.service
    echo 'RestartSec=1' >> /etc/systemd/system/kodi.service
    echo 'SendSIGHUP=yes' >> /etc/systemd/system/kodi.service
    echo >> /etc/systemd/system/kodi.service
    echo '[Install]' >> /etc/systemd/system/kodi.service
    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/kodi.service
    
    echo '#!/bin/sh' > /usr/local/bin/mythfrontend.sh
    echo >> /usr/local/bin/mythfrontend.sh
    echo 'echo -n waiting for mythbackend' >> /usr/local/bin/mythfrontend.sh
    echo 'while ! pidof mythbackend > /dev/null 2> /dev/null ; do' >> /usr/local/bin/mythfrontend.sh
    echo '  echo -n .' >> /usr/local/bin/mythfrontend.sh
    echo '  sleep 1' >> /usr/local/bin/mythfrontend.sh
    echo 'done' >> /usr/local/bin/mythfrontend.sh
    echo 'echo done!' >> /usr/local/bin/mythfrontend.sh
    echo >> /usr/local/bin/mythfrontend.sh
    echo '# start mythfrontend' >> /usr/local/bin/mythfrontend.sh
    echo 'exec /usr/bin/mythfrontend' >> /usr/local/bin/mythfrontend.sh
    chmod +x /usr/local/bin/mythfrontend.sh
    
    echo '[Unit]' > /etc/systemd/system/mythfrontend.service
    echo 'Description=MythTV Frontend' >> /etc/systemd/system/mythfrontend.service
    echo 'After=startx@williams.service' >> /etc/systemd/system/mythfrontend.service
    echo 'Requires=startx@williams.service' >> /etc/systemd/system/mythfrontend.service
    echo >> /etc/systemd/system/mythfrontend.service
    echo '[Service]' >> /etc/systemd/system/mythfrontend.service
    echo 'ExecStart=-/usr/local/bin/mythfrontend.sh' >> /etc/systemd/system/mythfrontend.service
    echo 'User=williams' >> /etc/systemd/system/mythfrontend.service
    echo 'Environment=DISPLAY=:0' >> /etc/systemd/system/mythfrontend.service
    echo 'Restart=always' >> /etc/systemd/system/mythfrontend.service
    echo 'RestartSec=1' >> /etc/systemd/system/mythfrontend.service
    echo >> /etc/systemd/system/mythfrontend.service
    echo '[Install]' >> /etc/systemd/system/mythfrontend.service
    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mythfrontend.service
    
    echo '[Unit]' > /etc/systemd/system/xterm.service
    echo 'Description=xterm for troubleshooting' >> /etc/systemd/system/xterm.service
    echo 'After=startx@williams.service' >> /etc/systemd/system/xterm.service
    echo 'Requires=startx@williams.service' >> /etc/systemd/system/xterm.service
    echo >> /etc/systemd/system/xterm.service
    echo '[Service]' >> /etc/systemd/system/xterm.service
    echo 'ExecStart=-/usr/bin/xterm' >> /etc/systemd/system/xterm.service
    echo 'User=williams' >> /etc/systemd/system/xterm.service
    echo 'Environment=DISPLAY=:0' >> /etc/systemd/system/xterm.service
  • run alsamixer and configure audio as needed
  • mkdir ~williams/.vnc
    x11vnc -storepasswd **PASSWORD** ~williams/.vnc/passwd
    chown -R williams:williams ~williams/.vnc
    chmod 0600 ~williams/.vnc/passwd
  • Network shared Kodi database and settings:
    mv ~williams/.kodi ~williams/old-dot-kodi
    ln -s /mnt/videos/dot-kodi ~williams/.kodi
  • Allow power off from Kodi:
    echo '[Actions for williams user]' > /etc/polkit-1/localauthority/50-local.d/kodi-williams.pkla
    echo 'Identity=unix-user:williams' >> /etc/polkit-1/localauthority/50-local.d/kodi-williams.pkla
    echo 'Action=org.freedesktop.login1.reboot' >> /etc/polkit-1/localauthority/50-local.d/kodi-williams.pkla
    echo 'ResultAny=yes' >> /etc/polkit-1/localauthority/50-local.d/kodi-williams.pkla
    echo 'ResultInactive=yes' >> /etc/polkit-1/localauthority/50-local.d/kodi-williams.pkla
    echo 'ResultActive=yes' >> /etc/polkit-1/localauthority/50-local.d/kodi-williams.pkla
  • getting things to start up the right order is a real mess:
    mkdir -p /etc/systemd/system/mythtv-backend.service.d /etc/systemd/system/kodi.service.d /etc/systemd/system/mythfrontend.service.d
    echo '[Unit]' > /etc/systemd/system/mythtv-backend.service.d/depend-on-nfs-mount.conf
    After=mnt-videos.mount' >> /etc/systemd/system/mythtv-backend.service.d/depend-on-nfs-mount.conf
    Requires=mnt-videos.mount' >> /etc/systemd/system/mythtv-backend.service.d/depend-on-nfs-mount.conf
    echo '[Unit]' > /etc/systemd/system/kodi.service.d/depend-on-nfs-mount.conf
    After=mnt-videos.mount' >> /etc/systemd/system/kodi.service.d/depend-on-nfs-mount.conf
    Requires=mnt-videos.mount' >> /etc/systemd/system/kodi.service.d/depend-on-nfs-mount.conf
    echo '[Unit]' > /etc/systemd/system/mythfrontend.service.d/depend-on-nfs-mount.conf
    After=mnt-videos.mount' >> /etc/systemd/system/mythfrontend.service.d/depend-on-nfs-mount.conf
    Requires=mnt-videos.mount' >> /etc/systemd/system/mythfrontend.service.d/depend-on-nfs-mount.conf
    sed -i -e 's/^iface eth0 inet dhcp$/&\n  post-up systemctl start mythtv-backend.service\n  #post-up systemctl start kodi.service\n  post-up systemctl start mythfrontend.service/g' /etc/network/interfaces
  • systemctl start startx@williams
  • aptitude install mythweb # this will pull in apache, php, ffmpeg, and a bunch of other stuff
  • mv /var/www/html/index.html /var/www/html/index.html.orig
    echo '<!DOCTYPE html>' > /var/www/html/index.html
    echo '<html>' >> /var/www/html/index.html
    echo '<head>' >> /var/www/html/index.html
    echo '<meta http-equiv="refresh" content="0; url=mythweb/">' >> /var/www/html/index.html
    echo '</head>' >> /var/www/html/index.html
    echo '<body>' >> /var/www/html/index.html
    echo '<p><a href="mythweb/">MythWeb can be found here</a>.</p>' >> /var/www/html/index.html
    echo '</body>' >> /var/www/html/index.html
    echo '</html>' >> /var/www/html/index.html
  • aptitude install phpmyadmin # select apache2, then choose yes to the dbconfig-common question, enter db admin password, and leave password prompt blank to generate random password
  • sed -i 's/my-unique-identifier-goes-here/dvr/g' /etc/mythtv/config.xml
  • sed -i -e 's/^bind-address/#bind-address/g' /etc/mysql/my.cnf
  • /etc/init.d/mysql restart
  • assign a static IP to system (using router)
  • start an xterm in X11 as williams (su williams then DISPLAY=:0 xterm), then remotely control using VNC
    • in xterm: su -p then mythtv-setup
    • enter database username and password from /etc/mythtv/config.xml
    • in 1-general, select static IP from IPv4 address dropdown, and enter same IP for master backend, enter “0000” for security PIN (then advance through a zillion more pages)
    • in 2-capture cards, add tuner card (use defaults)
    • in 4-video sources, add source “Broadcast” (schedulesdirect), enter username+password, and select local broadcast listings. Deselect “Perform EIT scan”
    • in 5-input connections, connect Broadcast video source to DVB card, then click “Scan for channels”. Leave scan at defaults and click “Next >”, then insert all non-conflicting channels
    • mkdir /mnt/scratch/livetv && chown mythtv:williams /mnt/scratch/livetv
    • chown -R mythtv:williams /mnt/videos/mythtv
    • in 7-storage directories, add livetv group at /mnt/scratch/livetv, add default group at /mnt/videos/mythtv
    • exit GUI setup, then run mythfilldatabase
  • /etc/init.d/mythtv-backend start
  • systemctl start kodi, then configure Kodi as needed
  • # web-based talker:<code> aptitude install espeak echo '#!/bin/sh' > /usr/local/bin/duck_speak.sh echo » /usr/local/bin/duck_speak.sh echo 'CARD=PCH' » /usr/local/bin/duck_speak.sh echo 'NORM=23' » /usr/local/bin/duck_speak.sh echo 'DUCK=10' » /usr/local/bin/duck_speak.sh echo 'CONTROL=Line' » /usr/local/bin/duck_speak.sh echo 'DELAY=.05' » /usr/local/bin/duck_speak.sh echo » /usr/local/bin/duck_speak.sh echo 'for i in $(seq $NORM -1 $DUCK); do' » /usr/local/bin/duck_speak.sh echo ' amixer -c$CARD -q sset $CONTROL $i' » /usr/local/bin/duck_speak.sh echo ' sleep $DELAY' » /usr/local/bin/duck_speak.sh echo 'done' » /usr/local/bin/duck_speak.sh echo » /usr/local/bin/duck_speak.sh echo 'ALSA_CARD=$CARD espeak -s 140 “$@” 2>/dev/null' » /usr/local/bin/duck_speak.sh echo » /usr/local/bin/duck_speak.sh echo 'for i in $(seq $DUCK $NORM); do' » /usr/local/bin/duck_speak.sh echo ' amixer -c$CARD -q sset $CONTROL $i' » /usr/local/bin/duck_speak.sh echo ' sleep $DELAY' » /usr/local/bin/duck_speak.sh echo 'done' » /usr/local/bin/duck_speak.sh chmod +x /usr/local/bin/duck_speak.sh adduser www-data audio </code>
computer/mythtv_server.txt · Last modified: 2016/06/18 15:11 by tdobes
Recent changes RSS feed Driven by DokuWiki Valid XHTML 1.0 Valid CSS