Install Kodi 20.1 On Debian 11/12 (Bullseye/Bookworm)

# KODI Installation version 20.1 Nexus on Debian 11/12 (Bullseye/Bookworm)

# Kodi is a multi-platform home-theater PC (HTPC) application.
# official repository: https://github.com/xbmc/xbmc
# website: http://kodi.tv/

# update all pkgs

  1. $ sudo apt update

# if need run upgrade

  1. $ sudo apt upgrade

# all pkgs must be up to date before going further


# edit source list to add testing repo

  1. $ sudo nano /etc/apt/sources.list

# add the line below at end

deb http://deb.debian.org/debian testing main non-free contrib

# CTRL+X and Y to SAVE
# get testing packages list

  1. $ sudo apt update

DO NOT UPGRADE

# install kodi 20.1

  1. cd ~/Downloads

# AMD64

  1. $ sudo apt install kodi

# or
# download/install Kodi 20.1 manually (not recommended)

  1. $ wget -O  kodi_20.1+dfsg-1_amd64.deb http://ftp.us.debian.org/debian/pool/main/k/kodi/kodi_20.1+dfsg-1_amd64.deb

# in case of dependencies error, download and install all pkgs

  1. $ for x in {'kodi-repository-kodi_20.1+dfsg-1_all.deb','kodi-data_20.1+dfsg-1_all.deb','kodi-bin_20.1+dfsg-1_amd64.deb','kodi_20.1+dfsg-1_amd64.deb'}; do wget $x http://ftp.us.debian.org/debian/pool/main/k/kodi/$x; done

# install Kodi 20.1 manually

  1. $ sudo apt install ./kodi-data_20.1+dfsg-1_all.deb ./kodi-bin_20.1+dfsg-1_amd64.deb ./kodi_20.1+dfsg-1_amd64.deb ./kodi-repository-kodi_20.1+dfsg-1_all.deb

# ARM64 Raspberry PI 4

  1. $ sudo apt install kodi

# or
# download/install Kodi 20.1 manually (not recommended)

  1. $ for x in {'kodi-repository-kodi_20.1+dfsg-1_all.deb','kodi-data_20.1+dfsg-1_all.deb','kodi-bin_20.1+dfsg-1_arm64.deb','kodi_20.1+dfsg-1_arm64.deb'}; do wget $x http://ftp.us.debian.org/debian/pool/main/k/kodi/$x; done
  1. $ sudo apt install ./kodi-data_20.1+dfsg-1_all.deb ./kodi-bin_20.1+dfsg-1_arm64.deb ./kodi_20.1+dfsg-1_arm64.deb ./kodi-repository-kodi_20.1+dfsg-1_all.deb

# official repo should be automatically installed but if you want to install it manually

  1. $ $ sudo apt install kodi-repository-kodi

# add current user to all needed groups

  1. $ sudo usermod -aG adm,dialout,cdrom,sudo,audio,www-data,render,video,plugdev,games,users,dip,input $USER

# for Raspberry PI add gpio i2c spi

  1. $  sudo usermod -aG  adm,dialout,cdrom,sudo,audio,www-data,video,plugdev,games,users,input,render,netdev,gpio,i2c,spi pi

# edit source list to comment testing repo

  1. $ sudo nano /etc/apt/sources.list

# comment testing repo

#deb http://deb.debian.org/debian testing main non-free contrib

# CTRL+X and Y to SAVE
# get main packages list

  1. $ sudo apt update

# Kodi Power Menu

# SUSPEND/RESUME (amd64 platform)
# enable suspend services

  1. $ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

# 2 way to enable power policy for pi user
# 1. if /etc/polkit-1/localauthority exists

  1. $ sudo nano /etc/polkit-1/localauthority/50-local.d/50-kodi.pkla
[Allow consolekit]
Identity=unix-group:plugdev
Action=org.freedesktop.upower.suspend;org.freedesktop.consolekit.system.*
#Action=org.freedesktop.consolekit*
ResultAny=yes
ResultInactive=no
ResultActive=yes
[Allow login1]
Identity=unix-group:plugdev
Action=org.freedesktop.login1*
ResultAny=yes
ResultInactive=no
ResultActive=yes
[Allow Upower]
Identity=unix-group:plugdev
Action=org.freedesktop.upower.suspend
ResultAny=yes
ResultInactive=no
ResultActive=yes

# CTRL + X the Y to SAVE

# 2. alternative
# or create rules in /usr/share/polkit-1/rules.d/

  1. $sudo nano /usr/share/polkit-1/rules.d/10-kodi.rules
polkit.addRule(function(action, subject) {
    polkit.log("action=" + action);
    polkit.log("subject=" + subject);
    if (action.id.indexOf("org.freedesktop.login1.") == 0) {
        return polkit.Result.YES;
    }
    if (action.id.indexOf("org.freedesktop.udisks.") == 0) {
        return polkit.Result.YES;
    }
    if (action.id.indexOf("org.freedesktop.upower.") == 0) {
        return polkit.Result.YES;
    }
});

# CTRL + X the Y to SAVE

# run kodi to check the power menu

  1. $ kodi-standalone

# create kodi service

  1. $ sudo nano /lib/systemd/system/kodi.service
[Unit]
Description = Kodi Media Center
After = remote-fs.target network-online.target
Wants = network-online.target
[Service]
User = pi
Group = pi
Type = simple
ExecStart = /usr/bin/kodi-standalone
Restart = on-abort
RestartSec = 5
[Install]
WantedBy = multi-user.target

# CTRL + X the Y to SAVE

  1. $ sudo systemctl daemon-reload
  1. $ sudo systemctl enable kodi
  1. $ sudo systemctl start kodi
  1. $ sudo systemctl status kodi

# add kodi smb share points

# insert lines at the end of conf

  1. $ sudo nano /etc/samba/smb.conf
[kodi]
path = /home/pi/.kodi
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = pi

[userdata]
path = /home/pi/.kodi/userdata
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = pi

# CTRL + X the Y to SAVE

  1. $ sudo systemctl restart smbd
  1. $ sudo reboot

# Adding media source to Kodi


# IMPORTANT NOTICE for Windows network SMB share in Kodi 20
# make sure to configure your NAS with shared folders using SMB v2 or v3 and with
# access to everyone (no user/pass)
# setup KODI SMB service with minimum version SMBv2 and maximum SMBv3
# browse the network from a PC and check if you have a full access to shared
# folders without needing to enter your credential
# then in Kodi create your movies, TV shows, etc. source points (i.e. //MYSERVER/Video ) with
# a dummy username and password (like username: srcmedia and paswd: srckodi)


# OPTIONAL: create Video and TV Shows folders if you store the media on the server (not recommended)

  1. $ cd ~/
  1. $ mkdir Video
  1. $ mkdir "TV Shows"

# setup HDMI CEC

# on raspberry PI 4 HDMI CEC is already managed,
# however some keys of remote control must be adjusted like the back and contextual menu key.
# use the Keymap Editor addon (already installed) to make your changes in >global>navigation.

# on amd64 platform

# do not forget to add the Pulse Heigh CEC adapter ( https://www.pulse-eight.com ) to be able to use the TV remote control even with the Intel NUC which have a poor CEC implementation.
you may need to deactivate internal IR Receiver and HDMI CEC in Intel NUC Bios.


# install rc6 mce IR remote control with Kodi 20

# by default Kodi manages the RC6 MCE remote control if your usb dongle is installed or the built in extended IR receiver is set in your bios
# you may need to activate internal IR Receiver in Intel NUC Bios.
# unfortunately some essential buttons of the remote control do not work like BACK (KEY_BACK) and OK (KEY_OK) for example. Read the instructions below to fix it.
# open SSH session
# install ir-keytable

  1. $ sudo apt install ir-keytable

# check if remote control is recognized

  1. $ sudo ir-keytable

# result for usb dongle (mceusb)

Found /sys/class/rc/rc0/ with:
        Name: Media Center Ed. eHome Infrared Remote Transceiver (147a:e03e)
        Driver: mceusb
        Default keymap: rc-rc6-mce
        Input device: /dev/input/event6
        LIRC device: /dev/lirc0
        Attached BPF protocols: Operation not supported
        Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon rc-mm
        Enabled kernel protocols: lirc rc-6
        bus: 3, vendor/product: 147a:e03e, version: 0x1201
        Repeat delay = 500 ms, repeat period = 125 ms

# example with build IR (cir)

Found /sys/class/rc/rc0/ with:
        Name: ITE8708 CIR transceiver
        Driver: ite-cir
        Default keymap: rc-rc6-mce
        Input device: /dev/input/event4
        LIRC device: /dev/lirc0
        Attached BPF protocols: Operation not supported
        Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon rc-mm
        Enabled kernel protocols: lirc rc-6
        bus: 25, vendor/product: 1283:0000, version: 0x0000
        Repeat delay = 500 ms, repeat period = 125 ms

# Important Info are:

 system device: rc0 (Found /sys/class/rc/rc0/)
driver: mceusb or ite-cir
protocol: rc-6

# copy the rc6 mce keymap rc6_mce.toml from /lib/udev/rc_keymaps/ to /etc/rc_keymaps/

  1. $ sudo cp /lib/udev/rc_keymaps/rc6_mce.toml /etc/rc_keymaps/

# edit the keymap to fix it

  1. $ sudo nano /etc/rc_keymaps/rc6_mce.toml

# replace entries 0x800f0412, 0x800f0413, 0x800f0418, 0x800f0422 and 0x800f0423 with:

.
.
0x800f0412 = "KEY_PAGEUP"
0x800f0413 = "KEY_PAGEDOWN"
.
0x800f0418 = "KEY_PLAY"
.
.
0x800f0422 = "KEY_ENTER"
0x800f0423 = "KEY_BACK"

# CTRL+X then Y to save
# edit /etc/rc_maps.cfg to add our custom keymap for mceusb and ite-cir driver

  1. $ sudo nano /etc/rc_maps.cfg

# add these lines at end

mceusb	*			/etc/rc_keymaps/rc6_mce.toml
ite-cir	*			/etc/rc_keymaps/rc6_mce.toml

# CTRL+X then Y to save
# now we are going to create a service to load our keymap at startup

  1. $ sudo nano /etc/systemd/system/rc6mce-ir-keytable.service

# rc-6 protocol and sys/class/rc rc0 is reported and obviously the path to our keymap

[Unit]
Description=RC6 MCE Keymap Fix
After=network.service kodi.service
[Service]
Type=oneshot
ExecStart=/usr/bin/ir-keytable -c -p rc-6 --write=/etc/rc_keymaps/rc6_mce.toml --sysdev=rc0
[Install]
WantedBy=default.target

# CTRL+X then Y to save
# activate the service

  1. $ sudo systemctl enable rc6mce-ir-keytable.service

# start service

  1. $ sudo systemctl start rc6mce-ir-keytable.service

# now the pause, back and OK buttons work and to get info select the item on Kodi and do a long press on OK
# reboot

  1. $ sudo reboot

# to test your remote control or get the correct scancode

  1. $ sudo ir-keytable -t

# Backup / Restore Kodi Data

# backup

  1. $ cd ~/
  2. $ tar cvzf ~/Downloads/"kodi_backup-$(date +'%m-%d-%y').tar.gz" --exclude=.kodi/temp .kodi

# restore

  1. $ cd ~/
  2. $ sudo systemctl stop kodi
  3. $ tar xzvf kodi_backup-xx-xx-xx.tar.gz
  4. $ sudo systemctl start kodi

# UNINSTALL KODI SERVICES

# if for some reason you no longer need the Home Theater service and want to keep the server for the audio system only (in short using it as the MusicLounge server) do the following

  1. $ sudo systemctl stop kodi
  1. $ sudo systemctl disable kodi

# edit /etc/samba/smb.conf to remove or comment SMB Share kodi

  1. $ sudo nano /etc/samba/smb.conf
#[kodi]
#path = /home/pi/.kodi
#read only = no
#public = yes
#writable = yes
#browseable = yes
#guest ok = yes
#create mask = 0777
#directory mask = 0755
#force user = pi

#[userdata]
#path = /home/pi/.kodi/userdata
#read only = no
#public = yes
#writable = yes
#browseable = yes
#guest ok = yes
#create mask = 0777
#directory mask = 0755
#force user = pi

# CTRL + X and Y to save

  1. $ sudo reboot

# you can remove kodi user data and configuration files if needed

  1. $ cd ~/
  2. $ sudo rm -r .kodi

# Congrats! The audiophile server and the Kodi Home Theater are ready

# setup the Kodi SYSTEM > AUDIO > and choose the correct number of speakers
# activate the passthrough to take benefit of Dolby, DTS, trueHD, etc.