aboutsummaryrefslogtreecommitdiff
path: root/tools/Linux/packaging/debian/xbmc-live.upstart
blob: 5ddffc17287e4224185535d2bc3ae8b7f08cd853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# xbmc-live
#
# init XBMC environment and starts XBMC in fullscreen (if asked to do so)

#      Copyright (C) 2005-2008 Team XBMC
#      http://www.xbmc.org
#
#  This Program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with XBMC; see the file COPYING.  If not, write to
#  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html

description     "XBMCLive"
author          "Luigi Capriotti"

start on (filesystem and stopped udevtrigger)

stop on runlevel [06]

emits starting-x

pre-start script
	get_opt() {
		echo "$@" | cut -d "=" -f 2
	}

	clear >/dev/tty7 || true

	CMDLINE=$(cat /proc/cmdline)

	#Process command line options
	XBMC_PARAMS=""
	for i in ${CMDLINE}; do
		case "${i}" in
		xbmc\=*)
		      XBMC_PARAMS=$(get_opt $i)
		      ;;
		esac
	done
	echo $XBMC_PARAMS > /tmp/xbmcliveParams

	if grep "boot=live" /proc/cmdline ; then
		# Relies on init scripts to mount boot device on a specified directory
		BOOTMEDIAMOUNTPOINT="/live/image"
	fi

	BOOTHOOKSDIRECTORY="/etc/xbmc"

	xbmcUser=xbmc
	# Read configuration variable file if it is present
	[ -r /etc/default/xbmc-live ] && . /etc/default/xbmc-live
	if ! getent passwd $xbmcUser >/dev/null; then
		xbmcUser=$(getent passwd 1000 | sed -e 's/\:.*//')
	fi

	# Executes pre-hooks (if any) in the System "Hooks" directory
	if [ -d $BOOTHOOKSDIRECTORY/live.d ]; then
	  for hook in $(find $BOOTHOOKSDIRECTORY/live.d -type f -perm /u=x,g=x,o=x | sort)
	  do
	        $hook $BOOTMEDIAMOUNTPOINT $XBMC_PARAMS  || true
	  done
	fi

	# Executes pre-hooks (if any) in the user "Hooks" directory
	if [ -d /home/$xbmcUser/.xbmc/live.d ]; then
	  for hook in $(find /home/$xbmcUser/.xbmc/live.d -type f -perm /u=x,g=x,o=x | sort)
	  do
	        $hook $BOOTMEDIAMOUNTPOINT $XBMC_PARAMS  || true
	  done
	fi

	if [ -f /home/xbmc/.xsession ] ; then
		rm /home/xbmc/.xsession
	fi
	if [ -f /tmp/noRestartXBMC ] ; then 
		rm /tmp/noRestartXBMC
	fi
end script

script
	if ! grep -i -q autostart /tmp/xbmcliveParams ; then
		exit
	fi

	exec /usr/bin/runXBMC
end script

pre-stop script
	touch /tmp/noRestartXBMC
	rm /tmp/xbmcliveParams

	# Clean up the console before we switch to it, to avoid text flicker
	if [ -x /usr/bin/tput ] ; then
		tput -Tlinux reset > /dev/tty1 || true
		tput -Tlinux reset > /dev/tty8 || true
	fi

	# Clear VT 1 & 8 of any console messages
	clear >/dev/tty1 || true
	clear >/dev/tty8 || true
end script