How To Install kmttg and pyTivo in a FreeNAS 9.3 Jail

Status
Not open for further replies.

philiplu

Explorer
Joined
Aug 10, 2014
Messages
58
[Edit: Oct 17, 2015. The original instructions from April 2015 apply to v1.1 of kmttg. Kmttg is now up to v2.0, and is using JavaFX instead of Java Swing (for the graphics presentation, apparently). That doesn't work for OpenJDK on FreeBSD. To use these instructions, grab the most recent version of kmttg v1.1, which right now is v1.1r.]

This is a guide to installing both kmttg and pyTivo together in a jail. There's a previous guide here describing pyTivo in a jail if you don't need kmttg. I use kmttg more than pyTivo, and the two work together nicely, so both in a single jail is useful.

I've got a Tivo Roamio Pro with a 3 TB drive, the latest in over a decade of using Tivos. I've had Tivo drives die over the years, and use kmttg as a way to back up the drive. I use it to copy shows from the Tivo to my NAS, with pyTivo letting the Tivo see those downloaded shows if I ever need to pull them back to the Tivo from the NAS. It doesn't let me copy non-transferable movies (think HBO), but it does mean no longer losing all the episodes of various kids programs we have stored.

pyTivo is accessed using a browser, so it's pretty simple to install. But kmttg's main interface is via a local graphical window, so it's more interesting to install. I'm using a VNC (Virtual Network Computing) server to expose a virtual screen that can be accessed remotely. The virtual screen will use Openbox as the window manager over X Windows. There are lots of window managers you can play around with; I ended up with Openbox pretty randomly, looking for a simple manager (I think I tried Fluxbox and twm as well while I was first setting this up several months ago).

Before Creating the Jail
  1. Install a VNC viewer (client) wherever you plan on remoting into your jail. I installed TightVNC for Win 7 64-bit, version 2.7.10, from http://tightvnc.com/download.php.
  2. Use the FreeNAS GUI to create a tivo group, via Account → Group → Add Group (default items not shown):
    Group ID: Whatever you choose. I picked 2001 to keep it away from regular user IDs.
    Group Name: tivo
  3. Create a tivo user at Account → Users → Add User (default items not shown):
    User ID: Same as the tivo group ID (2001 in my case)
    Username: tivo
    Create a new primary group for the user: Unchecked
    Primary group: tivo
    Shell: nologin
    Full name: "Owner of files created in tivo jail"
    Disable password login: Checked
  4. You'll want to store downloaded shows outside the jail, via storage attached to the jail. Create a dataset using the Storage → Volumes page. I created the dataset pool/nbu/tivo (nbu stands for Not Backed Up, for datasets I don't back up to my secondary FreeNAS box).
Create the Jail
  1. Use Jails → Jails → Add Jails to create a standard jail. I gave mine the name tivo.
  2. Use Jails → Storage → Add Storage to attach your media dataset (point 4 above) to your jail. In my case:
    Jail: tivo
    Source: /mnt/pool/nbu/tivo
    Destination: /mnt/tivo
    Read-only: Unchecked
    Create directory: Checked
Install and Configure the Jail Software

The following steps are performed with a command shell in your jail. You can go to Jails → Jails and select the tivo jail, then click the Shell button at the bottom of the webpage. If you prefer working through ssh, ssh into your NAS, then run jexec tivo tcsh (with sudo if needed) to enter your jail.
  1. Create a tivo group and user inside the jail to match those outside the jail. Change the number if you chose something other than 2001 above.
    Code:
    pw groupadd tivo -g 2001
    echo "tivo:2001:2001::::Account for running kmttg & pyTivo:/home/tivo:/usr/sbin/nologin:" | adduser -f -
  2. Install the necessary packages. I'm using TightVNC as the VNC server, Openbox as the window manager, PyPanel for the taskbar at the bottom of the screen, and several utilities used by kmttg and pyTivo to manipulate Tivo files.
    Code:
    pkg update -f
    pkg upgrade -y
    pkg install -y tightvnc curl openjdk8-jre
    pkg install -y openbox obconf obmenu pypanel
    pkg install -y tivodecode ffmpeg handbrake mediainfo mencoder
  3. Create new file /etc/rc.d/pytivo, an rc script to run pytivo as user tivo when the jail is started. Use an editor like ee or vi to create the file with the following text:
    Code:
    #!/bin/sh
    
    # $FreeBSD$
    #
    # PROVIDE: pytivo
    # REQUIRE: LOGIN NETWORKING
    # KEYWORD: shutdown
    
    # Add the following line to /etc/rc.conf to enable pytivo at boot:
    # pytivo_enable="YES"
    
    . /etc/rc.subr
    
    name=pytivo
    rcvar=$(set_rcvar)
    
    pytivo_user=tivo
    
    eval homedir=~${pytivo_user}
    
    command=${homedir}/pytivo/pytivo-master/pyTivo.py
    command_args=">${homedir}/pytivo.log 2>&1 &"
    command_interpreter=python
    
    pidfile=/var/run/${name}.pid
    
    load_rc_config $name
    run_rc_command "$@"
  4. Create new file /etc/rc.d/kmttg, an rc script to run vncserver as user tivo (which will start kmttg thanks to the xstartup created later on). Edit the file to have the following text:
    Code:
    #!/bin/sh
    
    # $FreeBSD$
    #
    # PROVIDE: kmttg
    # REQUIRE: LOGIN NETWORKING
    # KEYWORD: shutdown
    
    # Add the following line to /etc/rc.conf to enable kmttg at boot:
    # kmttg_enable="YES"
    
    . /etc/rc.subr
    
    name=kmttg
    rcvar=$(set_rcvar)
    
    kmttg_user=tivo
    
    eval homedir=~${kmttg_user}
    
    vnc_display=:1
    
    # The command is vncserver, not kmttg, because the script is really just starting Xvnc.
    # kmttg is started using ${homedir}/.vnc/xstartup
    
    command=/usr/local/bin/vncserver
    command_args="${vnc_display} -geometry 1280x1024 -depth 24"
    procname=Xvnc
    
    pidfile=${homedir}/.vnc/$(hostname)${vnc_display}.pid
    
    start_cmd="su -m ${kmttg_user} -c \"sh -c \\\"HOME=${homedir} ${command} ${command_args}\\\"\""
    stop_cmd="su -m ${kmttg_user} -c \"sh -c \\\"HOME=${homedir} ${command} -kill ${vnc_display}\\\"\""
    
    load_rc_config $name
    run_rc_command "$@"
  5. Make both rc scripts executable:
    Code:
    chmod +x /etc/rc.d/pytivo /etc/rc.d/kmttg
  6. Use an editor to add the following two lines to the end of /etc/rc.conf, to enable running the two scripts on jail startup/shutdown:
    Code:
    pytivo_enable="YES"
    kmttg_enable="YES"
  7. Change from user root to user tivo for the remaining steps in this section, which create files in the tivo user's home directory. Then create a couple directories we need for starting up the VNC session:
    Code:
    su -m tivo
    cd ~tivo
    mkdir .vnc
    mkdir -p .config/openbox
  8. Use an editor to create new file /home/tivo/.vnc/xstartup with the following text, which instructs the VNC server to load the Openbox window manager and kmttg when starting up:
    Code:
    #!/bin/sh
    openbox-session &
    (sleep 5 && /home/tivo/kmttg/kmttg) &
  9. Make xstartup executable with the following command:
    Code:
    chmod +x ~tivo/.vnc/xstartup
  10. Create new file /home/tivo/.config/openbox/autostart so openbox loads the PyPanel taskbar. Since it's only a single line, I'm using an echo command to create the file, instead of an editor:
    Code:
    echo '(sleep 5 && pypanel) &' > ~tivo/.config/openbox/autostart
  11. Tweak the PyPanel configuration. First, make it opaque instead of mostly transparent, since I'm not installing a desktop wallpaper app, and the default desktop pattern makes it impossible to see what's in a transparent taskbar. Also, bump up the font-size PyPanel uses:
    Code:
    sed -e '/^SHADE *=/s/50/255/' -e '/^FONT *=/s/-8/-12/' /usr/local/share/pypanel/pypanelrc > ~tivo/.pypanelrc
  12. Install the kmttg software by downloading the .zip from sourceforge and unpacking it. Version 1.1n was current when I wrote this. Check at https://downloads.sourceforge.net/project/kmttg for the latest version. Once installed, it's trivial to update kmttg using the Help → Update kmttg... menu selection from within the app.
    Code:
    mkdir ~tivo/kmttg
    cd ~tivo/kmttg
    fetch https://downloads.sourceforge.net/project/kmttg/kmttg_v1.1n.zip
    unzip kmttg_v1.1n.zip
  13. Install the pyTivo software by downloading the .zip from GitHub and unpacking it. You could alternately clone the repo as shown in the earlier guide.
    Code:
    mkdir ~tivo/pytivo
    cd ~tivo/pytivo
    fetch https://github.com/wmcbrine/pytivo/archive/master.zip
    unzip master.zip
  14. Change from the tivo user back to the root user, then start up the pytivo and kmttg services. The first time you start up the kmttg service, it will ask you to supply a password to be used when connecting to the VNC server. Do so.
    Code:
    exit
    service pytivo start
    service kmttg start
  15. Exit the jail, either by closing the console window within the FreeNAS GUI, or executing exit to leave the jail, then again to leave the ssh session.
Configure pyTivo

This is a quick look at configuring pyTivo. Check out the wiki at http://pytivo.sourceforge.net/wiki/index.php/PyTivo for more details.
  1. Connect to pyTivo with a browser. It's available at port 9032 at the IP address shown in the Jails listing in the FreeNAS GUI. In my case, I browsed to 192.168.1.201:9032.
  2. Click on Settings, select Global Server Settings from the Sections box, then enter the following settings:
    ffmpeg: /usr/local/bin/ffmpeg
    tivodecode: /usr/local/bin/tivodecode
    tdcat: /usr/local/bin/tdcat
    tivo_username: Your login name at tivo.com
    tivo_password: Your password at tivo.com (needed to push shows from the NAS to the Tivo box)
    tivo_mak: The Media Access Key (MAK) for your Tivo.
    togo_path: Somewhere in your jail's attached storage. In my case, that's somewhere under /mnt/tivo.
  3. Click the Save Changes button
  4. If you want your Tivo to see pyTivo as a source of shows, click Add Section, then name the section (something like NAS Videos or My Downloaded Shows), and click Save Changes. Then select the new section and set the type and path as appropriate. I set type=video, path=/mnt/tivo/downloaded. Click Save Changes again.
  5. You should be able to see the new section as a Device in the Tivo My Shows menu. If not, check for errors in the log file at /home/tivo/pytivo.log in the tivo jail. You might also try setting the Global Server Setting beacon to something like 192.168.1.255, click Save Changes, then click Restart pyTivo.
Configure VNC and Openbox
  1. Start up whatever VNC viewer you installed in the first step. These instructions show TightVNC being used on Win 7.
  2. In the New TightVNC Connection dialog, type the IP address of your jail followed by ::5901. I typed 192.168.1.201::5901, then clicked Connect.
  3. You next need to supply the password you chose when you started up the kmttg service.
  4. If all goes well, you should see a remote desktop being presented by the VNC server in your tivo jail, with kmttg running and ready to be configured. It should look something like this:
    kmttg-1.png
  5. Click the floppy disk icon on TightVNC's toolbar to save your session to a .vnc file. That will allow you to reconnect to kmttg later without requiring your password every time.
  6. You might want to configure the Openbox appearance next. Notice the window title bars are using a very small font. To tweak that, right-click the desktop to bring up the Openbox menu, hover over System, and click Openbox Configuration Manager:
    kmttg-2.png
  7. In the configuration dialog, choose the Appearance tab, then click each of the Fonts buttons and change the font size (I bumped all of them to 12 point):
    kmttg-3.png
  8. After you close the configuration dialog, activate the changes by again right-clicking the desktop, hovering over System, and clicking "Reconfigure Openbox".
    kmttg-4.png
Configure kmttg

The kmttg docs are at https://sourceforge.net/p/kmttg/wiki/Home. Here's a quick run through my setup:
  1. Maximize the kmttg window in the VNC client, since you don't need to get at the underlying desktop any longer.
  2. Enter your Tivo's Media Access Key in the startup dialog.
  3. Select File → Configure... and proceed with configuration on the File Settings tab. In my case:
    FILES Default Path: /mnt/tivo
    .TiVo Output Dir: /mnt/tivo/downloaded
    All other directories: /mnt/tivo/converted (I don't use these yet)
  4. The Programs tab in the configuration dialog should automatically be filled in with the paths to whatever tools are installed.
  5. On the Web tab, set the Web server cache dir to somewhere in the attached storage. I'm using /mnt/tivo/webcache.
  6. On the pyTivo tab, set the path to the pytivo.conf file to /home/tivo/pytivo/pytivo-master/pytivo.conf.
  7. Press OK to dismiss the configuration dialog, and you should be ready to play. If kmttg isn't detecting your Tivo, play around with the Tivos tab of the configuration dialog. If necessary, manually add a name and IP address for the Tivo.
 

Attachments

  • kmttg-2.png
    kmttg-2.png
    11.5 KB · Views: 375
  • kmttg-3.png
    kmttg-3.png
    45.6 KB · Views: 429
  • kmttg-4.png
    kmttg-4.png
    20.6 KB · Views: 305
Last edited:
Joined
Apr 6, 2014
Messages
4
Hello,
I'm following your guide, and when I try to start kmttg, I get:

/etc/rc.d/kmttg: starting: not found
Unmatched ".
Unmatched ".

Any ideas?
Thanks!
 

philiplu

Explorer
Joined
Aug 10, 2014
Messages
58
I'll have to look later - on the way out the door now. But first question, what version of kmttg are you trying to install? These instructions work for v1.1[whatever]. I think it was v1.1n or so when I first installed it, and I'm now on v1.1r. But the latest version is v2.0t. The switch to v2.0 started using some Java libs that apparently aren't available for FreeBSD (at least, they weren't when I noticed the problem a month or two ago). So I'd suggest making sure to grab an older v1.1 version of kmttg.

If that's not the problem (and I suspect you'd hit a different error message if it were), then can you attach the /etc/rc.d/kmttg file? I can take a look to see if you got everything copied correctly.
 
Joined
Apr 6, 2014
Messages
4
No dice with 1.1n either, same error. Do I need to start over?
kmttg file attached(renamed to .zip)...
 

Attachments

  • kmttg.zip
    843 bytes · Views: 280

philiplu

Explorer
Joined
Aug 10, 2014
Messages
58
Your editor is word-wrapping (splitting) longer lines, looks like anything over 78 characters or so. In the kmttg file I show in step 4 above of the section Install and Configure the Jail Software, that would be lines 23, 32, and 33. Fix that, make sure none of the other files you set up are being split, and try again. You should be able to use the latest v1.1r instead of v1.1n once that's fixed.
 

JosephHJRR

Cadet
Joined
Dec 29, 2015
Messages
2
Thanks , got it installed and working - now how to share these TIVO files (decrypted) to my PLEX on same server so I can watch on my iPad (I have series 2 Tivo).

What to Share:
/mnt/FNvol/plugins/tivo (Seems to be growing as I copy files from TIVO to FreeNas server)
/mnt/FNvol/tivo (Is not growing in size)

Neither seem to work when I share them to PLEX.
 

CyberdineX

Cadet
Joined
Mar 26, 2016
Messages
6
This is awesome, thanks for the great detailed How To.
I was thinking that if I installed a very light Linux in the jail and then ran KMTTG in that shell we should be able to run the latest version of KMTTG with JavaFX???
Any thoughts. I am new to command line work so this will probably be challenging for me.
Is this even worth trying or just a recipe for disaster???
Cheers,
 

philiplu

Explorer
Joined
Aug 10, 2014
Messages
58
I'm still running kmttg and pyTivo in a jail under FreeBSD, but I'm thinking of doing what you're considering, running Linux in a jail and then having kmttg and pyTivo under Linux, so I can get access to the latest version of kmttg. Shouldn't be too difficult - I'm already doing that with Plex, which I run under Linux in a VirtualBox jail. I'll probably wait until I move from FreeNAS 9.3 to 9.10 before that, so I can get rid of VirtualBox and use the FreeBSD-native bhyve VMs instead.
 

boybert

Cadet
Joined
Aug 11, 2016
Messages
3
Thanks for the excellent guide, philiplu! With it I was able to get kmttg up and running on my new FreeNAS system.

Has anyone had any luck installing Comskip on their system to use with kmttg? I've tried a few times but haven't been able to successfully compile it for one reason or another. If anyone's got it up and running I'd love to hear some tips. Or, is anyone aware of any alternatives to Comskip I could use to automatically detect ads?

Thanks again!
 
Status
Not open for further replies.
Top