[85d082]: tools / Linux / packaging / debian / xbmc-live.postinst  Maximize  Restore  History

Repo status: analyzing...

Download this file

268 lines (233 with data), 8.7 kB

#!/bin/sh
# postinst script for xbmc-live
#
# see: dh_installdeb(1)

set -e
release="$(lsb_release -r | cut -f2 | sed 's/\.//')"

case "$1" in
    configure)
	# TODO: What's the purpose of this line? As I see it, if 'xbmc' can't
	# get a console session going, we're in trouble anyway. ceros
	sed -i.bak-xbmc-live s/allowed_users=console/allowed_users=anybody/ /etc/X11/Xwrapper.config

	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/\:.*//')
		if [ -z "$xbmcUser" ]; then
			# Add the 'xbmc' user if the primary one is missing
			clearTextPWD=xbmc
			encryptedPWD=$(echo $clearTextPWD | mkpasswd -s)

			adduser --disabled-password --gecos "XBMC Live User" xbmc
			usermod -p $encryptedPWD xbmc

			xbmcUser=xbmc
		fi
	fi

	# Add 'xbmcUser' user to the appropriate groups
	# Below is a listing of groups and their purpose
	# adm - For reading system logs (minimal systems may have this user only)
	# sudo - allow optional passwordless sudo (with trivial intervention on /etc/sudoers)
	# cdrom - optical disc drive access
	# floppy - floppy drive access
	# audio - audio device access
	# video - video device access
	# plugdev - enable automatic notifications of new devices
	# netdev - managing network connections via NetworkManager
	# powerdev - to be able to hibernate/suspend
	# fuse - to be able to mount filesystems as normal user
	GROUPS="adm
		sudo
		cdrom
		floppy
		audio
		video
		plugdev
		netdev
		powerdev
		fuse
		polkituser"

	# TODO: this probably isn't necessary anymore as PolicyKit is now being
	# used
	for GROUP in $GROUPS; do
		if getent group $GROUP >/dev/null && \
			! getent group $GROUP | grep -q $xbmcUser; then
			adduser $xbmcUser $GROUP
		fi
	done


	SUDOERSBLOCK_TEMPFILE=$(mktemp -q)

	cat > $SUDOERSBLOCK_TEMPFILE <<ENDOFBLOCK
### XBMC-specific configuration ###
# XBMC
Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/reboot, /sbin/halt # XBMC
Cmnd_Alias MOUNT_CMDS = /bin/mount, /bin/umount # XBMC
$xbmcUser ALL=(ALL) ALL # XBMC
$xbmcUser ALL=NOPASSWD: SHUTDOWN_CMDS, MOUNT_CMDS # XBMC
ENDOFBLOCK

	SUDOERS_TEMPFILE=$(mktemp -q)

	# Simply create a sudoers file if none exists
	if [ ! -e /etc/sudoers ]; then
	    cat > /etc/sudoers <<ENDOFBLOCK
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults        env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL

# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=NOPASSWD: ALL
ENDOFBLOCK
	    chmod 0440 /etc/sudoers
	fi

	# Add xbmc to the sudoers file (if not already done)
	if ! grep -i -q XBMC-specific /etc/sudoers ; then
		cat /etc/sudoers $SUDOERSBLOCK_TEMPFILE > $SUDOERS_TEMPFILE

		# Check if sudoers file is ok with visudo and write to /etc/sudoers if
		# it is ok, else display a message to the user.
		if visudo -c -f $SUDOERS_TEMPFILE >/dev/null 2>&1; then
			cp -f $SUDOERS_TEMPFILE /etc/sudoers
		else
			# TODO: Use debconf for this message.
			echo "Couldn't edit /etc/sudoers, must be manually edited."
			echo "Please edit /etc/sudoers using 'visudo' and add the following"
			echo "entries:"
			cat $SUDOERSBLOCK_TEMPFILE
		fi
	fi

	rm $SUDOERS_TEMPFILE
	rm $SUDOERSBLOCK_TEMPFILE

 #Maverick no longer has polkit-auth, we have to use a .pkla file instead
 if [ $release -ge 1010 ]; then
   cat > /var/lib/polkit-1/localauthority/50-local.d/20-xbmclive.pkla <<ENDOFBLOCK
# Policy to allow the livecd user to bypass policykit. Should be installed at /var/lib/polkit-1/localauthority/50-local.d/20-xbmclive.pkla
[XBMC-Live user permissions]
Identity=unix-user:${xbmcUser}
Action=*
ResultAny=no
ResultInactive=no
ResultActive=yes
ENDOFBLOCK
 else
	# This is a list of actions that the 'xbmc' user should be allowed to
	# do. If we missed one, or we have one that's not necessary, please
	# submit a bug report.
	POLKIT_ACTIONS="org.freedesktop.hal.dockstation.undock
		org.freedesktop.hal.wol.enabled
		org.freedesktop.hal.wol.enable
		org.freedesktop.hal.wol.supported
		org.freedesktop.hal.leds.brightness
		org.freedesktop.hal.device-access.audio-player
		org.freedesktop.hal.device-access.camera
		org.freedesktop.hal.device-access.cdrom
		org.freedesktop.hal.device-access.dvb
		org.freedesktop.hal.device-access.fingerprint-reader
		org.freedesktop.hal.device-access.floppy
		org.freedesktop.hal.device-access.ieee1394-avc
		org.freedesktop.hal.device-access.ieee1394-iidc
		org.freedesktop.hal.device-access.joystick
		org.freedesktop.hal.device-access.mouse
		org.freedesktop.hal.device-access.obex
		org.freedesktop.hal.device-access.pda
		org.freedesktop.hal.device-access.printer
		org.freedesktop.hal.device-access.scanner
		org.freedesktop.hal.device-access.sound
		org.freedesktop.hal.device-access.video
		org.freedesktop.hal.device-access.video4linux
		org.freedesktop.hal.lock
		org.freedesktop.hal.killswitch.bluetooth
		org.freedesktop.hal.killswitch.wlan
		org.freedesktop.hal.killswitch.wwan
		org.freedesktop.hal.storage.mount-removable
		org.freedesktop.hal.storage.eject
		org.freedesktop.hal.storage.crypto-setup-removable
		org.freedesktop.hal.power-management.shutdown
		org.freedesktop.hal.power-management.reboot
		org.freedesktop.hal.power-management.set-powersave
		org.freedesktop.hal.power-management.suspend
		org.freedesktop.hal.power-management.hibernate
		org.freedesktop.hal.power-management.cpufreq
		org.freedesktop.hal.power-management.lcd-panel
		org.freedesktop.hal.power-management.light-sensor
		org.freedesktop.hal.power-management.keyboard-backlight
		org.freedesktop.devicekit.power.suspend
		org.freedesktop.devicekit.power.Hibernate
		org.freedesktop.consolekit.system.stop
		org.freedesktop.devicekit.disks.filesystem-mount
		org.freedesktop.devicekit.disks.filesystem-mount-system-internal
		org.freedesktop.devicekit.disks.filesystem-unmount-others
		org.freedesktop.devicekit.disks.drive-eject
		org.freedesktop.devicekit.disks.drive-detach
		org.freedesktop.upower.suspend
		org.freedesktop.upower.hibernate
		org.freedesktop.udisks.filesystem-mount
		org.freedesktop.udisks.filesystem-mount-system-internal
		org.freedesktop.udisks.filesystem-unmount-others
		org.freedesktop.udisks.drive-eject
		org.freedesktop.udisks.drive-detach"

	# Grant the 'xbmc' user each action from the list if not done already
	for ACTION in $POLKIT_ACTIONS; do
		if polkit-auth --user $xbmcUser --show-obtainable | \
			grep -q $ACTION; then
			polkit-auth --user $xbmcUser --grant $ACTION
		fi
	done
fi
	if ! grep -i -q XBMCLive /etc/lsb-release ; then
		sed -i -e "/^DISTRIB_DESCRIPTION/s/\"\(.*\)\"/\"\1 - XBMCLive\"/" /etc/lsb-release
	fi

	# Add <xbmc=autostart,nodiskmount,setvolume loglevel=0> to grub's kernel entries
	if [ -f /boot/grub/menu.lst ]; then
		if ! grep -q -i "xbmc=autostart" /boot/grub/menu.lst ; then
			# TODO Do not modify single-mode entry
			sed -i -e "/^kernel/s/\(.*\)/\1 xbmc=autostart,nodiskmount,setvolume loglevel=0/" /boot/grub/menu.lst
			sed -i -e "/^# kopt=root=/s/\(.*\)/\1 xbmc=autostart,nodiskmount,setvolume loglevel=0/" /boot/grub/menu.lst
		fi
	fi

	if [ -f /boot/grub/grub.cfg ]; then
		if ! grep -q -i "xbmc=autostart" /etc/default/grub ; then
			sed -i -e "/^GRUB_CMDLINE_LINUX_DEFAULT=/s/\"\(.*\)\"/\"\1 xbmc=autostart,nodiskmount loglevel=0\"/" /etc/default/grub
			update-grub
		fi
	fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# Upstart scripts tested on karmic+ only (>=9.10)  and not backward compatible ATM
if [ $release -ge 910 ]; then
	if [ -f "/etc/init.d/xbmc-live" ]; then
		update-rc.d -f xbmc-live remove >/dev/null
		rm /etc/init.d/xbmc-live >/dev/null
	fi

	ln -s /lib/init/upstart-job /etc/init.d/xbmc-live
else
	if [ -f "/etc/init/xbmc-live.conf" ]; then
		rm /etc/init/xbmc-live.conf >/dev/null
	fi
	if [ -f "/etc/init/xbmc-live-install" ]; then
		rm /etc/init/xbmc-live-install.conf >/dev/null
	fi

	if [ -x "/etc/init.d/xbmc-live" ]; then
		update-rc.d xbmc-live defaults >/dev/null
		if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
			invoke-rc.d xbmc-live start || exit $?
		else
			/etc/init.d/xbmc-live start || exit $?
		fi
	fi
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks