HOW-TO:Autostart Kodi for Linux: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
Line 232: Line 232:
You can use any window manager or desktop enviroment with a custom Xsession script as long as it is intalled.
You can use any window manager or desktop enviroment with a custom Xsession script as long as it is intalled.


You do this by creating '''.xinitrc''' script that contains the command to start the WM or DE.
You do this by creating '''~/.xinitrc''' script that contains the command to start the WM or DE.


For instance, if you are using FluxBox?
For instance, if you are using FluxBox?
Line 252: Line 252:
</pre>
</pre>


Use the '''.xinitrc''' file to configure '''.xsession''' to create a custom login for any user, not just Kodi.  
Use the '''~/.xinitrc''' file to configure '''~/.xsession''' to create a custom login for any user, not just Kodi.  


<pre>
<pre>

Revision as of 23:09, 5 March 2018

Any or all or any combination of these methods can be used to configure a Debian-based X Window System to boot directly to Kodi. This should work on any Linux using the X Window System, but these instructions are particular to Debian derivatives, such as Ubuntu. A server edition is best for running only Kodi, but this page assumes booting into a desktop OS, not a server distro. However, the instructions here can be used for a server distro with even less configuration than for a desktop. Experiment inside VirtualBox before you apply any of these to your system and make a backup.

Switch to root

su

or

sudo su

Create a Kodi user

To use Kodi full-screen, you only have to create a standard user.

adduser kodi

To remove the password use:

passwd -d kodi

Customize LightDM to autologin

You can utilize the ability to customize LightDM data manager by changing the builtin custom configuration file 50-myconfig.conf using nano or another text editor. If you have no DE or WM you can install lightdm, but should make sure to do a bit of research before you do. Most versions of Linux use LightDM, but many server versions do not. For Ubuntu Server with no DE, for example, installing lightdm is okay and necessary. Changing the behavior of LightDM is done using a custom 50-myconfig.conf configuration file.

To see if you have lightdm use which.

which lightdm

If not, install it with apt.

apt install lightdm

Create a custom configuration file called 50-myconfig.conf using nano or other CLI text editor.

nano /etc/lightdm/lightdm.conf.d/50-myconfig.conf

Inside this new file add the following text.

[SeatDefaults]
autologin-user=kodi

Configure Kodi to autostart

Configure Kodi to autostart.

mkdir -p ~/.config/autostart
ln -s /usr/bin/kodi ~/.config/autostart

This method of autostart requires a desktop environment or DE.

If Kodi is not installed at the standard path, find it using the which command.

which kodi

Disable / enable the login prompt

You can disable the graphical login prompt.

systemctl set-default multi-user.target

To enable it again use.

systemctl set-default graphical.target

Create custom Xsession script

Create a custom Xsession script with a text editor.

nano ~/.xinitrc

To run Kodi full-screen make sure the text reads:

#!/usr/bin/env bash
exec /usr/bin/x-window-manager &
/usr/bin/kodi -fs &

If you are not sure of the path of X Window Manager, use the which command.

which x-window-manager

Use sudo and the ~/.xinitrc file to configure ~/.xsession.

sudo -H -u kodi bash -c "ln -s ~/.xinitrc ~/.xsession"

You need to use sudo to run this command. If you do not have sudo, install it.

apt install sudo

Remember you can modify use and reuse the ~/.xinitrc file to configure ~/.xsession as often as you want. That is the purpose of the file. It does nothing on its own until you associate it with a user.

Using Kodi standalone service shell for X11

Kodi full-screen is not the same Kodi standalone service, which runs in Xserver in the default window manager. Beware of creating conflicting user sessions. Another user booting to an Xsession with a login prompt will not allow user kodi to autologin. User kodi cannot login to the custom Xsession for the other user. Without a password at the login prompt that appears for this misconfiguration, user kodi is unable to login to the other user's Xsession and the other user cannot login to the Kodi standalone service session for user kodi. In short, if you are using a custom Xsession for another user, do not configure user kodi to autologin when using Kodi standalone service.

In order to use Kodi standalone service with an existing user named kodi, first remove the password.

passwd -d kodi

Also make sure you always have a separate user login other than user kodi, if you remove the password for Kodi. You will be unable to login with Kodi manually from the standalone service shell once running the next commands for Kodi standalone service even if you make a new password. So, this is what you use if you do not want to ever give user kodi a password, which may be what desirable when running kodi as systemd service.

usermod kodi -d /var/lib/kodi -s /usr/bin/nologin
mkdir -p /var/lib/kodi/.kodi
chown -R kodi:kodi /var/lib/kodi/.kodi

To avoid any issues being unable to login as Kodi with a password, do not use the segment -s /usr/bin/nologin in the previous code block. Instead, your commands might run like this.

usermod kodi -d /var/lib/kodi
mkdir -p /var/lib/kodi/.kodi
chown -R kodi:kodi /var/lib/kodi/.kodi

If you have already use the -s /usr/bin/nologin segment and want to remove it, no worries. To remove it simply re-enter the command leaving the path to the shell blank to reset it to the default system shell.

usermod kodi -s

You may want to add kodi to these groups.

adduser kodi audio
adduser kodi video
adduser kodi sambashare
adduser kodi network
adduser kodi optical

If there is no user named kodi, you must create one.

To create user kodi for Kodi standalone service, create a Kodi user with no login and no password.

groupadd kodi
useradd kodi -u 420 -g kodi -G audio,video,network,optical,sambashare \
-d /var/lib/kodi \
-s /usr/bin/nologin # if Kodi doesn't have a password
mkdir -p /var/lib/kodi/.kodi
chown -R kodi:kodi /var/lib/kodi/.kodi

You can download the zip file for Kodi standalone service from GitHub.

Kodi standalone service on GitHub

Most systems utilize the client version of the X11 software Kodi standalone service requires.

Upgrade to the server versions of the X Window System.

apt install xauth xorg xinit xserver-xorg-core xserver-xorg xserver-common

You can install Kodi standalone service with one easy command.

unzip -p kodi-standalone-service-master/kodi-standalone-service-master/init/kodi.service>/usr/lib/systemd/kodi.service

You can now run Kodi standalone service by running one simple command.

systemctl start kodi

Or, configure user kodi to autologin with LightDM (step 3) and autostart (step 4). Remember autostart requires a DE!

You can also remove the login prompt to boot directly to Kodi (step 5), and exit Kodi to the CLI.

The ~/.xinitrc file you can create and link to your ~/.xsession file is:

#!/usr/bin/env bash
exec /usr/bin/x-window-manager &
systemctl start /usr/bin/kodi -fs &

Though the -fs switch is not necessary, it is something I leave there for to assure it exists beyond my own edits, but only in the case of using the defautl X Window Manager. You can remove it.

On the CLI you can restore your DE or window manager.

startx

If the login prompt is enabled, you return to the login screen.

The default behavior for most Linux is to boot into the same environment and user session as before.

The only way to get rid of the DE or WM entirely is by booting in text mode (step 9) by creating a custom Grub entry.

Xsession to boot to app / WM / DE

You can use any window manager or desktop enviroment with a custom Xsession script as long as it is intalled.

You do this by creating ~/.xinitrc script that contains the command to start the WM or DE.

For instance, if you are using FluxBox?

#!/usr/bin/env bash
exec fluxbox &
/usr/bin/kodi -fs &

The -fs option is full-screen.

To start Gnome with Kodi full-screen:

#!/usr/bin/env bash
exec gnome-session &
/usr/bin/kodi -fs &

Use the ~/.xinitrc file to configure ~/.xsession to create a custom login for any user, not just Kodi.

sudo -H -u [username] bash -c "ln -s ~/.xinitrc ~/.xsession"

Add a custom Grub entry

If you want to boot to the CLI and manually launch an app, WM or DE, add a custom grub entry.

The right way to add a custom grub entry is to copy the menu entry you want to change or duplicate.

Copy the default Grub configuration file and open it with a text editor on your desktop. If you use a text editor on the CLI, the text will be cut off by the window when copying and pasting.

cp /boot/grub/grub.cfg grub.cfg
gedit grub.cfg

Copy the menu entry and paste it into 40_custom with a text editor in the CLI.

nano /etc/grub.d/40_custom

Where the menu entry contains quiet splash change it to text instead.

You should also change the name of the entry!

I just appended mine with “CLI” for command line interface.

To update Grub:

update-grub

You can the boot to the CLI of your operating system.

You can launch Kodi standalone service.

systemctl start kodi

To launch a WM:

fluxbox

You must have FluxBox installed. There are countless other window managers.

To launch a DE you enter the appropriate command. For Gnome desktop:

gnome-session

For KDE:

startkde

or

plasma-desktop

For XFCE:

startxfce4

For Mate:

mate-session

For LXDE:

startlxde

You can either manually launch your apps, boot right into them, or create an Xsession for each user. This is great when you want to create a Kodi user for running Kodi only, and for making sure you can still login to your DE with your regular user account. You can boot to any app full-screen this way, not just Kodi. You can create a custom Xsession script for any user, configured with any startup applications running in full-screen mode or normally.

If you do not want to create a custom Xsession, Kodi standalone service provides an easy solution.

By optionally creating a Grub menu entry, you can create a different Grub menu selection to boot only to the CLI and start an Xsession with a script or run commands manually.