Instantly share code, notes, and snippets.

@ziirish /README.md
Last active Oct 11, 2018

Embed
What would you like to do?
Firefox on Xbian

Firefox on Xbian

These scripts allow you to launch Firefox on XBian.

Usage

When you are in Kodi and you want to switch to Firefox, you just have to quit (no shutdown, just quit). Firefox will then start automatically. Now when you want to get back to Kodi, just quit Firefox and Kodi will start back automatically.

How it works?

The script will run in the background and check for the kodi.bin process.

  1. If the kodi.bin process does not exist, it will start Firefox with a minimal X environment
  2. When you close Firefox, it will start Kodi back
  3. Back to 1.

Installation

As root, install git, clone this gist, and run the firefox_on_xbian.sh script:

apt install git
git clone https://gist.github.com/4b92d9b48ef203b6fcfcfeb2f7e95a6d.git firefox_on_debian
cd firefox_on_debian
chmod +x firefox_on_debian.sh
./firefox_on_debian.sh
#!/bin/bash
LOCK=/tmp/launcher
LOCKFILE=/tmp/firefox-running
STOPFILE=/tmp/firefox-stopped
DEBUG=${DEBUG:-0}
# rc.local seems to be launched twice, to avoid race condition, we use this little
# tweak with a random sleep and a lockfile
if [ "$DEBUG" == 0 ]
then
sleep 30
sleep $(($RANDOM%10))
test -e $LOCK && exit 0
fi
touch $LOCK
log() {
if [ "$DEBUG" == "1" ]; then
echo $@
fi
}
enable_nodm() {
sed -r "s/^NODM_ENABLED=.*$/NODM_ENABLED=true/" /etc/default/nodm
}
disable_nodm() {
sed -r "s/^NODM_ENABLED=.*$/NODM_ENABLED=false/" /etc/default/nodm
}
# make sure nodm is not started (because firefox consumes a lot of resources)
enable_nodm
/etc/init.d/nodm stop &>/dev/null || true
test -e $LOCKFILE && rm $LOCKFILE
test -e $STOPFILE && rm $STOPFILE
disable_nodm
log "Starting service..."
while true
do
# we do something only when kodi is stopped
pgrep kodi.bin &>/dev/null || {
log "Kodi stopped"
# if we just exited firefox, a $STOPFILE will be created
# we can then stop nodm an restart kodi
test -e $STOPFILE && {
log "Restarting Kodi"
enable_nodm
/etc/init.d/nodm stop
disable_nodm
pid=$(cat $STOPFILE)
ps $pid &>/dev/null && kill $pid
sleep 2
stop -q xbmc
start -q xbmc
rm $STOPFILE
} || {
# kodi is stopped and there is no $STOPFILE so it means we can
# start firefox, unless it is already started
test -e $LOCKFILE || {
log "Starting Firefox"
enable_nodm
/etc/init.d/nodm restart
disable_nodm
}
}
}
sleep 5
done
rm $LOCK
#!/bin/bash
GISTID="4b92d9b48ef203b6fcfcfeb2f7e95a6d"
apt install matchbox-window-manager xinit xserver-xorg-input-all firefox-esr nodm git
if [ ! -e "README.md" ]
then
git clone https://gist.github.com/$GISTID.git firefox_on_debian
cd firefox_on_debian
fi
cp xsession.sh /home/xbian/.xsession
cp nodm.default /etc/default/nodm
cp firefox_launcher.sh /opt/firefox_launcher
chown xbian: /home/xbian/.xsession
chmod +x /home/xbian/.xsession
chmod +x /opt/firefox_launcher
grep -vE "^/opt/firefox_launcher" /etc/rc.local || sed -ri 's,exit 0,/opt/firefox_launcher \&\n\n&,' /etc/rc.local
# nodm configuration
# Set NODM_ENABLED to something different than 'false' to enable nodm
NODM_ENABLED=false
# User to autologin for
NODM_USER=xbian
# First vt to try when looking for free VTs
NODM_FIRST_VT=7
# X session
NODM_XSESSION=/etc/X11/Xsession
# Options for nodm itself
NODM_OPTIONS=
# Options for the X server.
#
# Format: [/usr/bin/<Xserver>] [:<disp>] <Xserver-options>
#
# The Xserver executable and the display name can be omitted, but should
# be placed in front, if nodm's defaults shall be overridden.
NODM_X_OPTIONS='-nolisten tcp'
# If an X session will run for less than this time in seconds, nodm will wait an
# increasing bit of time before restarting the session.
NODM_MIN_SESSION_TIME=60
# Timeout (in seconds) to wait for X to be ready to accept connections. If X is
# not ready before this timeout, it is killed and restarted.
NODM_X_TIMEOUT=300
LOCKFILE=/tmp/firefox-running
STOPFILE=/tmp/firefox-stopped
test -e $STOPFILE && rm $STOPFILE || true
#Turn off Power saver and Screen Blanking
xset s off -dpms
#Execute window manager for full screen
matchbox-window-manager -use_titlebar no &
touch $LOCKFILE
#Execute Browser with options
firefox
rm $LOCKFILE
kill %1
sleep 60 &
pid=$!
echo $pid >$STOPFILE
wait $pid
@macaju

This comment has been minimized.

Show comment
Hide comment
@macaju

macaju Dec 2, 2017

I'd like to try your solution but first, could you tell me, if you use them, of course, if amazon video and netflix works with this trick and firefox esr version?

Regarding the version it should*:

xbian@xbian:~$ sudo apt show firefox-esr
Package: firefox-esr
Version: 52.4.0esr-1~deb9u1

* https://www.pcworld.com/article/3108544/linux/firefox-for-linux-will-soon-support-netflix-and-amazon-videos.html

macaju commented Dec 2, 2017

I'd like to try your solution but first, could you tell me, if you use them, of course, if amazon video and netflix works with this trick and firefox esr version?

Regarding the version it should*:

xbian@xbian:~$ sudo apt show firefox-esr
Package: firefox-esr
Version: 52.4.0esr-1~deb9u1

* https://www.pcworld.com/article/3108544/linux/firefox-for-linux-will-soon-support-netflix-and-amazon-videos.html

@ziirish

This comment has been minimized.

Show comment
Hide comment
@ziirish

ziirish Dec 6, 2017

Hi,

You can actually run whatever browser you like. I personally run firefox, but I successfully tried chromium as well.
I did not try amazon video nor netflix since I don't have access to these platforms, but I know youtube is almost unusable so I suppose you may expect the same unusability.

Owner

ziirish commented Dec 6, 2017

Hi,

You can actually run whatever browser you like. I personally run firefox, but I successfully tried chromium as well.
I did not try amazon video nor netflix since I don't have access to these platforms, but I know youtube is almost unusable so I suppose you may expect the same unusability.

@mcgunn84

This comment has been minimized.

Show comment
Hide comment
@mcgunn84

mcgunn84 Jan 14, 2018

Hi,
it will not work, it tried more times on xbian but exit is always to shell. what i make wrong?
thx mcgunn

mcgunn84 commented Jan 14, 2018

Hi,
it will not work, it tried more times on xbian but exit is always to shell. what i make wrong?
thx mcgunn

@nicojx

This comment has been minimized.

Show comment
Hide comment
@nicojx

nicojx Aug 26, 2018

Can't get it to work either. Exiting Kodi leads to a shell login. When I try to run matchbox-window-manager manually, it complains that no display is found (also in the Xorg log file). Any ideas?

nicojx commented Aug 26, 2018

Can't get it to work either. Exiting Kodi leads to a shell login. When I try to run matchbox-window-manager manually, it complains that no display is found (also in the Xorg log file). Any ideas?

@MyMarvel

This comment has been minimized.

Show comment
Hide comment
@MyMarvel

MyMarvel Oct 11, 2018

exit from kodi; enter 'xbian' and 'raspberry' as root login/pass; see a blue screen with list of settings; click 'esc' on your keyboard. You'll see the command line on the bottom of the screen.

MyMarvel commented Oct 11, 2018

exit from kodi; enter 'xbian' and 'raspberry' as root login/pass; see a blue screen with list of settings; click 'esc' on your keyboard. You'll see the command line on the bottom of the screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment