beta: these instructions not perfected yet
Updated: 6/18/2008

See also:
---------
MythTV.org documentation: http://www.mythtv.org/modules.php?name=MythInstall
Some Fedora MythTV documentation: http://wilsonet.com/mythtv/fcmyth.php
MySQL security documentation: http://dev.mysql.com/doc/refman/5.0/en/privilege-system.html

MythTV - quick setup instructions, for use with Fedora 9 Linux:
---------------------------------------------------------------
My experience with MythTV is with using: Hauppauge WinTV-PVR-150 tuner card

MythTV - Backend server configuration:
--------------------------------------
Setup ATrpms repository to get the MythTV packages:
See also: http://atrpms.net/
cd /etc/yum.repos.d
rpm --import http://ATrpms.net/RPM-GPG-KEY.atrpms
vi atrpms.repo
[atrpms]
name=ATrpms for Fedora Core $releasever - $basearch
baseurl=http://dl.atrpms.net/fc$releasever-$basearch/atrpms/stable
# or use something like the following if you are using a locally rsynced copy of the ATrpms repo
# baseurl=http://yum/f9/atrpms
enabled=0
gpgcheck=1
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms

Disable livna repository if enabled:
vi /etc/yum.repos.d/livna.repo
Change "enabled=1" to "enabled=0" in file

Install Hauppauge WinTV-PVR-150 tuner card capture card firmware:
See also: http://ivtvdriver.org
Make sure your kernel is updated to 2.6.22 or newer, and then:
yum --enablerepo=atrpms install ivtv-firmware
Reboot:
init 6
Make sure you can see /dev/video0 as "crw-rw----+" after reboot:
Example:
# ls -la /dev/video*
lrwxrwxrwx 1 root    root      6 Jun 18 21:19 /dev/video -> video0
crw-rw----+ 1 jdoe root 81,  0 Jun 18 21:19 /dev/video0
crw-rw----+ 1 jdoe root 81, 24 Jun 18 21:19 /dev/video24
crw-rw----+ 1 jdoe root 81, 32 Jun 18 21:19 /dev/video32

Install MythTV (136 packages when I installed):
yum --enablerepo=atrpms install mythtv
 Note, if you get transaction errors similar to this:
  Transaction Check Error:
   file /usr/lib/python2.5/site-packages/PIL/GifImagePlugin.py from install of PIL-1.1.6-8.fc9.i386 conflicts with file from package python-imaging-1.1.6-9.fc9.i386
 Then you need to remove these packages:
  rpm -e python-imaging hplip
 Then rerun the above yum command.

Install mplayer-skins so that mplayer works for testing:
yum --enablerepo=atrpms install mplayer-skins

Set location of saved video files (make sure your userID can write to this directory)
Example:
chown -R mythtv:mythtv /video
chmod -R 775 /video
chown -R root:root /video/lost+found/
chmod -R 700 /video/lost+found/

Set useable shell for userID "mythtv":
usermod -s /bin/bash mythtv
 Before change:
  # grep myth /etc/passwd
  mythtv:x:495:487:mythtvbackend User:/var/lib/mythtv:/sbin/nologin
 After change:
  [root@s2 /]# grep myth /etc/passwd
  mythtv:x:495:487:mythtvbackend User:/var/lib/mythtv:/bin/bash

Allow /dev/video to be writeable by mythtv group (you must reboot after this):
Create file /etc/security/console.perms.d/51-default.perms with the following 4 lines in it:
# device class
<mythtv>=/dev/video* /dev/radio* /dev/winradio* /dev/vtx* /dev/vbi* /dev/video/*
# permission definition
<console>  0660 <mythtv>        0660 root.mythtv

After reboot, /dev/video* should look like this (Group read/writeable and group owned by mythtv):
# ll /dev/video*
lrwxrwxrwx 1 root    root        6 Jun 18 23:53 /dev/video -> video0
crw-rw---- 1 jdoe mythtv 81,  0 Jun 18 23:53 /dev/video0
crw-rw---- 1 jdoe mythtv 81, 24 Jun 18 23:53 /dev/video24
crw-rw---- 1 jdoe mythtv 81, 32 Jun 18 23:53 /dev/video32
Before reboot, looked like this:
# ll /dev/video*
lrwxrwxrwx 1 root root      6 2008-06-18 22:50 /dev/video -> video0
crw-rw---- 1 root root 81,  0 2008-06-18 22:50 /dev/video0
crw-rw---- 1 root root 81, 24 2008-06-18 22:50 /dev/video24
crw-rw---- 1 root root 81, 32 2008-06-18 22:50 /dev/video32

Test the IVTV driver:
cat /dev/video0 > test.mpg
Press CTRL-C to stop recording to test.mpg after awhile.
Test playback of the test.mpg file with mplayer

Add the next 7 lines to the "[mysqld]" section of the /etc/my.cnf file:
set-variable=thread_stack=256k
skip-innodb
key_buffer = 16M
table_cache = 128
sort_buffer_size = 2M
myisam_sort_buffer_size = 8M
query_cache_size = 16M

Setup mysql (as "root" userID)
chkconfig mysqld on
service mysqld start

Remove anonymous mysql accounts, if available:
mysql -u root
mysql> select host, user from mysql.user;
mysql> DELETE FROM mysql.user WHERE User = '';
mysql> FLUSH PRIVILEGES;
mysql> select host, user from mysql.user;
mysql> quit

Set mysql "root" userID password, where "newpwd" is the password you want for root mysql userID and "hostname" is your hostname:
mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE user='root';
 or you can do the "set password" option for each instance of the root userID in the user table, for example:
  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
  mysql> SET PASSWORD FOR 'root'@'hostname' = PASSWORD('newpwd');
mysql> FLUSH PRIVILEGES;
mysql> quit

Populate the mythconverg database
mysql -u root -p < /usr/share/doc/mythtv-docs-0.21/database/mc.sql
 enter your root mysql userID password at the prompt

Grant access from your local IP subnet for mythfrontends to connect to your mythtv backend database:
 mysql -u root -p mythconverg
  enter your root mysql userID password at the prompt
 mysql> grant all on mythconverg.* to mythtv@'192.168.1.0/255.255.255.0' identified by "mythtv";
 mysql> grant all on mythconverg.* to mythtv@'localhost' identified by "mythtv";
 mysql> flush privileges;
 mysql> quit
Set mysql "mythtv" userID password, where "newpwd" is the password you want for root mysql userID and "hostname" is your hostname::
 mysql -u root -p
  enter your root mysql userID password at the prompt
 mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE user='mythtv';
  or you can do the "set password" option for each instance of the mythtv userID in the user table, for example:
   mysql> SET PASSWORD FOR 'mythtv'@'localhost' = PASSWORD('newpwd');
   mysql> SET PASSWORD FOR 'mythtv'@'hostname' = PASSWORD('newpwd');
 mysql> FLUSH PRIVILEGES;
 mysql> quit

Setup a Schedules Direct account:
http://www.schedulesdirect.org/

Run the mythTV setup program (run this as "mythtv" userID):
From another terminal window, run "xhost +" to enable x window use by "mythtv" userID!
mythtv-setup
 If you get this error: "libGL error: failed to open DRM: Operation not permitted"
 Then you need to add this 3 line section to your /etc/X11/xorg.conf:
 Section "DRI"
     Mode 0666
 EndSection
NOTE: Make sure you setup each main menu tab item from top to bottom!  MythTV won't work without it.
General section:
 IP address for (servername): (enter the backend servers IP address)
 Security Pin (Required): 0000 (to allow all frontends to connect)
 Master Server IP address: (enter the backend servers IP address)
 Locale Settings
  TV format: NTSC
  VBI format: None
  Channel frequency table: us-cable
  Time offset for XMLTV listings: Auto
 Miscellaneous Settings (use defaults)
 EIT Scanner Optionis (use defaults)
 Shutdown/Wakeup Optioins (use defaults)
 Backend Wakeup settings (use defaults)
 Job Queue (Backend-Specific) (use defaults)
 Job Queue (Global) (use defaults)
 Job Queue (Job Commands) (use defaults)
Capture cards:
 New capture card
 Card type: MPEG-2 encoder card (PVR-x50, PVR-500)
 Video device: /dev/video0
 Probed info: Hauppauge WinTV PVR-150 [ivtv]
 Default input: Tuner 1
Video sources:
 New video source
 Video source name: ScheduleesDirect.org
 XMLTV listings grabber: North America (SchedulesDirect.org) (Internal)
  User ID:(your userID on SchedulesDirect.org)
  Password: (your password on SchedulesDirect.org)
  Retrieve Lineups
  Data Direct Lineup: (should show your lineup selected when on SchedulesDirect.org web site)
 Channel frequency table: default
Input connections:
 MPEG: /dev/video0 Tuner1 -> SchedulesDirect.org
  Video source: SchedulesDirect.org
  Scan for channels (this fails when I tried it, so I recommend just running Fetch channels below)
  Fetch channels from listings source (this does take awhile to run)
  Starting channel: (select your first channel)
Channel Editor:
 Channel Scanner (this fails when I tried it)
Storage Directories
 Storage Groups (directories for new recordings)
  Default
   'Default' Storage Group Directories
    (Add New Directory)
     Enter directory name or press SELECT to enter
      /video (or your directory location to store recorded video)

Run the "mythfilldatabase" (as directed after running "mythtv-setup"):
Run next line first time you run this:
 mythfilldatabase --do-channel-updates
All future updates, run:
 mythfilldatabase

Setup "mythbackend" to startup automatically and start it:
Verify these lines in /etc/init.d/mythbackend startup script, so that mythtv runs as mythtv user and not root:
 daemon --user mythtv $binary $OPTIONS
#  daemon $binary $OPTIONS
Then run:
chkconfig mythbackend on
service mythbackend start

Either turn off iptables firewall on backend server or configure to allow mythtv to access from frontend
To turn off iptables:
chkconfig iptables off
service iptables stop

# MythWeb configuration - for scheduling recordings of shows using your web browser:
chkconfig httpd on
service httpd start
Setup a loginID and password to browse your mythweb page:
Example:
htdigest -c /etc/httpd/conf/htdigest MythTV your_user_id
chown apache:apache /etc/httpd/conf/htdigest
chmod 640 /etc/httpd/conf/htdigest
vi /var/www/html/mythweb/.htaccess
Add and change this section to suit your needs (make sure you remove any "#" commenting these lines):
    AuthType           Digest
    AuthName           "MythTV"
    AuthUserFile       /etc/httpd/conf/htdigest
    Require            valid-user
    BrowserMatch       "MSIE"      AuthDigestEnableQueryStringHack=On
You can also add your local IP subnet so you do not need a loginID/password at home, but you do from the Internet:
Example:
vi /var/www/html/mythweb/.htaccess
Add and change this section to suit your needs:
    Order deny,allow
    Deny from all
    Allow from 192.168.1.0/255.255.255.0
    Satisfy any
Configure this section in /var/www/html/mythweb/.htaccess based on your mythtv configuration:
        setenv db_server        "localhost"
        setenv db_name          "mythconverg"
        setenv db_login         "mythtv"
        setenv db_password      "mythtv"
Browse to your mythweb backend server:
http://your_server_name/mythweb or http://your_server_IP_address/mythweb
You can also setup an index.php file to redirect your main page to your /mythweb page:
Example:
vi /var/www/html/index.php
Add the next line to the index.php file:
<?php header("Location: /mythweb"); ?>
Then, just browse to http://your_server_name/ and it should redirect to your /mythweb page.

MythTV - Frontend server configuration.  Setup the mythfrontend on your frontend server:
----------------------------------------------------------------------------------------
cd /etc/yum.repos.d
vi atrpms.repo
# atrpms.repo begin
[atrpms]
name=Fedora $releasever - $basearch - ATrpms
baseurl=http://dl.atrpms.net/f$releasever-$basearch/atrpms/stable
enabled=0
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
# atrpms.repo end

rpm --import http://ATrpms.net/RPM-GPG-KEY.atrpms
yum --enablerepo=atrpms install mythtv-frontend

Setup mysql remote user for remote server:
mysql -u root -p mythconverg
mysql> grant all on mythconverg.* to mythtv@FRONTEND_SERVERNAME_HERE identified by "mythtv";
mysql> set password for mythtv@FRONTEND_SERVERNAME_HERE=password('MYTHTV_USERID_PASSWORD_HERE');
mysql> flush privileges;
mysql> quit

Run mythfrontend:
mythfrontend

Updating MythTV and IVTV firmware and drivers:
----------------------------------------------
Update your Fedora Core base and extra packages:
yum update

If there are new Myth packages, update myth packages:
yum -y --enablerepo=atrpms update \*myth\* ivtv-firmware
Verify these lines in /etc/init.d/mythbackend startup script, so that mythtv runs as mythtv user and not root:
 daemon --user mythtv $binary $OPTIONS
#  daemon $binary $OPTIONS


Troubleshooting:
----------------
For mythbackend issues, check the log file here:
/var/log/mythtv/mythbackend.log

Test mythtv frontend connection to backend server, while on frontend server:
telnet BACKEND_HOSTNAME 3306
mysql -h BACKEND_HOSTNAME -u mythtv -p mythconverg

To show host table:
mysql -u root -p mysql
mysql> select host, user from mysql.user;

To show full mysql user database table:
mysql -u root -p mysql
mysql> select * from user;

For access denied mysql errors, see:
http://dev.mysql.com/doc/refman/5.0/en/access-denied.html

Using mythweb, if you get "Database Access Denied...Please see .htaccess for instructions.", then:
On your backend server, modify the .htaccess file to set your "mythtv" userID mysql password:
Example:
vi /var/www/html/mythweb/.htaccess
Change "setenv db_password" section to include your "mythtv" userID mysql password, then save the file.

If your channels on mythweb show as (channel 7 example) "Adding Channel 7", run this to fix:
mythfilldatabase --do-channel-updates


Backing up the database:
------------------------
Backup the database (See the mysqldump manpage for more information):
 mysqldump -u mythtv -p(type your mythtv password here) mythconverg -c > mythtv_backup.sql
 Example:
 mysqldump -u mythtv -pmythtv mythconverg -c > mythtv_backup.sql


After upgrading Fedora or moving your database's recorded program data to new backend hardware:
-----------------------------------------------------------------------------------------------
Prior to upgrading Fedora, create a backup of the database and copy it off of your server.

NOTE: Newer versions of mysqldump place backticks around the table names.
Backticks are not the same as apostrophes!
Backticks are located to the left of the "1" key, on the same key as the "~" (tilde).
The bash shell interprets the backticks, so we use a \ before each one.

Run these commands:
 grep "INSERT INTO \`record\` "          mythtv_backup.sql > restore.sql
 grep "INSERT INTO \`recorded\` "        mythtv_backup.sql >> restore.sql
 grep "INSERT INTO \`oldrecorded\` "     mythtv_backup.sql >> restore.sql
 grep "INSERT INTO \`recordedprogram\` " mythtv_backup.sql >> restore.sql
 grep "INSERT INTO \`recordedrating\` "  mythtv_backup.sql >> restore.sql
 grep "INSERT INTO \`recordedmarkup\` "  mythtv_backup.sql >> restore.sql
 grep "INSERT INTO \`recordedseek\` "    mythtv_backup.sql >> restore.sql

Note the space after the table name and the ">>" to append to the file for all but the first grep.
"recordedmarkup" and "recordedseek" are huge and there may be hundreds of thousands of lines if you had lots of hours of recordings.

After you have moved the data files to the new hardware, configure MythTV using the mythtv-setup program as you normally would with a standard MythTV installation.

Then, restore the information about your programs back into the database:
Populate the mythconverg database
mysql -u root -p < /usr/share/doc/mythtv-docs-0.21/database/mc.sql
 enter your root mysql userID password at the prompt
Grant access from your local IP subnet for mythfrontends to connect to your mythtv backend database:
mysql -u root -p mythconverg
 enter your root mysql userID password at the prompt
mysql> grant all on mythconverg.* to mythtv@'192.168.1.0/255.255.255.0' identified by "mythtv";
mysql> flush privileges;
mysql> quit
Set mysql "mythtv" userID password, where "newpwd" is the password you want for root mysql userID and "hostname" is your hostname::
mysql -u root -p
 enter your root mysql userID password at the prompt
mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE user='mythtv';
 or you can do the "set password" option for each instance of the mythtv userID in the user table, for example:
  mysql> SET PASSWORD FOR 'mythtv'@'localhost' = PASSWORD('newpwd');
  mysql> SET PASSWORD FOR 'mythtv'@'hostname' = PASSWORD('newpwd');
mysql> FLUSH PRIVILEGES;
mysql> quit
Setup a Schedules Direct account:
http://www.schedulesdirect.org/Run the mythTV setup program (run this as "mythtv" userID):
(run "xhost +" as your login userID from another window first)
 mythtv-setup
Run the "mythfilldatabase" (as directed after running "mythtv-setup"):
 mythfilldatabase --do-channel-updates
Restore the database:
 mysql -u mythtv -pmythtv mythconverg < restore.sql
Setup "mythbackend" to startup automatically and start it:
Verify these lines in /etc/init.d/mythbackend startup script, so that mythtv runs as mythtv user and not root:
 daemon --user mythtv $binary $OPTIONS
#  daemon $binary $OPTIONS
Then run:
chkconfig mythbackend on
service mythbackend start
After successful adding the data you may delete the restore.sql file.


Restore the database (assuming that you've dropped the database):
-----------------------------------------------------------------
 mysql -u root -p
 mysql>create database mythconverg;
 mysql>exit
Grant access from your local IP subnet for mythfrontends to connect to your mythtv backend database:
 mysql -u root -p mythconverg
  enter your root mysql userID password at the prompt
 mysql> grant all on mythconverg.* to mythtv@'192.168.1.0/255.255.255.0' identified by "mythtv";
 mysql> grant all on mythconverg.* to mythtv@'localhost' identified by "mythtv";
 mysql> flush privileges;
 mysql> quit
Set mysql "mythtv" userID password, where "newpwd" is the password you want for root mysql userID and "hostname" is your hostname::
 mysql -u root -p
  enter your root mysql userID password at the prompt
 mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE user='mythtv';
  or you can do the "set password" option for each instance of the mythtv userID in the user table, for example:
   mysql> SET PASSWORD FOR 'mythtv'@'localhost' = PASSWORD('newpwd');
   mysql> SET PASSWORD FOR 'mythtv'@'hostname' = PASSWORD('newpwd');
 mysql> FLUSH PRIVILEGES;
 mysql> quit
Restore database:
mysql -u mythtv -p mythconverg < mythtv_backup.sql

You may need to alter the MySQL permissions if this database is being shared with multiple systems.
(See Modifying access to the MySQL database for multiple systems.)


Mysql - removing access to a previously granted account:
--------------------------------------------------------
See also: http://dev.mysql.com/doc/refman/5.0/en/drop-user.html
mysql -u root -p mythconverg
mysql> select host, user from mysql.user;
mysql> show grants for 'mythtv'@'192.168.1.0/255.255.255.0';
mysql> revoke all privileges, grant option from 'mythtv'@'192.168.1.0/255.255.255.0';
mysql> revoke usage on *.* from 'mythtv'@'192.168.1.0/255.255.255.0';
mysql> drop user 'mythtv'@'192.168.1.0/255.255.255.0';
mysql> show grants for 'mythtv'@'192.168.1.0/255.255.255.0';
mysql> select host, user from mysql.user;
mysql> flush privileges;
mysql> quit


Deleting the MySQL database (ONLY IF YOU WANT TO DELETE ALL YOUR RECORDINGS DATA):
----------------------------------------------------------------------------------
NOTE: Performing this step will remove the entire database.
You will lose all of your settings and will need to re-run the mc.sql script to setup the database structure before running the mythtv-setup program:

    $ mysql -u root
    mysql> drop database mythconverg;
    mysql> quit

Things to look into yet:
------------------------
MythstreamTV

Mythstream plugin:
------------------
yum -y --enablerepo=atrpms install mythstream

Streaming MythTV from MythWeb using FLASH:
------------------------------------------
http://chiefhacker.com/2007/01/22/streaming-mythtv-from-mythweb-using-flash/


Automaticly remove commercials from recorded files:
---------------------------------------------------
NOTE: This tends to remove some bits of the program you recorded, so I don't use it.
Normally, commercials are just flagged to be skipped while watching.
To free up some space, you can automaticly remove commercials by retranscoding the file.
 See also: http://www.mythtv.org/wiki/index.php/Removing_Commercials
NOTES:
 This example will re-transcode the file and remove the commercial sections that were flagged by mythtv as commercials.
 You will want to periodically remove the .old files.  This isn't automatic in case a commercial is cut incorrectly.
Switch to "mythtv" userID:
 su - mythtv
Note: In this example, "mythtv" userID's home directory is in /var/lib/mythtv
Setup bin directory:
 mkdir /var/lib/mythtv/bin
Copy this example file to /var/lib/mythtv/bin as removecommercials
Change "ADD_YOUR_MYTHTV_DATABASE_PASSWORD_HERE" to your mythtv userID database password at the top of the file:
 vi removecommercials
 Example:  MYTHTVDATABASEPASSWORD=ADD_YOUR_MYTHTV_DATABASE_PASSWORD_HERE
Set permissions on the file:
 chmod 700 /var/lib/mythtv/bin/removecommercials
Run mythtv-setup as the "mythtv" userID on the backend server.
mythtv-setup
click on "1.General"
Click "Next" until you get to the "Job Queue (Host-Specific)" section.
At "Job Queue (Host-Specific)", make sure these are all checked:
 "Allow 'User Job #1' jobs"
 "Allow Commercial Detection jobs"
 "Allow Transcoding jobs"
Click "Next" until you get to "Job Queue (Job Commands)" section.
Note: In this example, "mythtv" userID's home directory is in /var/lib/mythtv
Setup User Job #1 as shown here:
User Job #1 Description: Remove Commercials
User Job #1 Command:     /var/lib/mythtv/bin/removecommercials %FILE%
Click "Next" until you see "Finish", then click "Finish" and exit "mythtv-setup".

Option 1: Manually remove commercials from a recording using mythfrontend:
Run mythfrontend
Select "Media Library" - "Watch Recordings"
Select the recording you want to remove commercials from, and hit the right arrow on the keyboard
Select "Job Options" and press "Enter"
Select "Begin Remove Commercials" and press "Enter"
You can watch the job get queued on mythweb "Backend Status"

Option 2: Automaticly remove commercials after they are recorded using mythweb:
From mythweb, click on the "Recording Schedules (Manual, Custom)"
Click the title you want to automaticly remove commercials from future recordings
Check the "Remove Commercials" tab
Click Update Recording Settings

Option 3: Manually remove commercials from a recording using Unix command line:
Switch to mythtv userID and cd to your videos directory:
 su - mythtv
 cd /path/to/videos
Run the script manually to remove commercials:
 /var/lib/mythtv/bin/removecommercials (filename)
 Example: /var/lib/mythtv/bin/removecommercials 1048_20070616222813.mpg