Setting up XBMCbuntu 12 based HTPC - Part 3 - OS tweaks

Since XBMCbuntu is just Ubuntu with some tweaks next we apply my usual Ubuntu fixes over it. Only major difference is that this time we're not removing Network-Damager. And of course bunch of XBMC specific changes.



Check IP your XBMC got from DHCP and connect to it using SSH with username xbmc and password you entered during install. You can find IP under System > System Info > Summary. Switch to root with “sudo su -”. BTW, that is stuff everyone reading my fancy blog is supposed to already know.

# Fix SSH keys. All XBMCbuntu installs are shipped with same key.
# Which is bad m'kay?
/bin/rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
# Set root password.
passwd root
# Allow sudo without password.
echo "%adm ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/nopassword
chmod 0440 /etc/sudoers.d/nopassword
# Clean files older than two # weeks from /tmp and
# autofix filesystem on boot after crash.
sed -i /etc/default/rcS -e's/^TMPTIME=.*/TMPTIME=14/g' \
    -e's/^FSCKFIX=.*/FSCKFIX=yes/g'
# Enable TRIM for rootfs and swap
sed -i.bak /etc/fstab \
    -e's/remount-ro/remount-ro,discard,commit=15/g' \
    -e's/sw /sw,discard/g'
# Next we make sure existing packages are up-to-date and
# add few packages that aren't included in stock install.
# Some of these are for making command line use easier
# while some are essential for later steps.
apt-get update
apt-get -y dist-upgrade
apt-get -y install joe screen lftp smartmontools samba \
           locate telnet mtr python-dbus python-gobject traceroute
# Disable IPv6 support
echo "net.ipv6.conf.all.disable_ipv6=1" >>/etc/sysctl.conf
# Disable bunch of unwanted services started by default
rm -f /etc/rc2.d/S19lirc
rm -f /etc/rc2.d/S50rsync
rm -f /etc/rc2.d/S70pppd-dns
echo manual >/etc/init/console-font.override
echo manual >/etc/init/cryptdisks-enable.override
echo manual >/etc/init/cryptdisks-udev.override
echo manual >/etc/init/tvheadend.override
echo manual >/etc/init/setvtrgb.override
echo manual >/etc/init/hybrid-gfx.override
echo manual >/etc/init/gssd.override
echo manual >/etc/init/gssd-mounting.override
echo manual >/etc/init/idmapd.override
echo manual >/etc/init/idmapd-mounting.override
echo manual >/etc/init/mountall-net.override
echo manual >/etc/init/portmap.override
echo manual >/etc/init/portmap-wait.override
echo manual >/etc/init/statd.override
echo manual >/etc/init/statd-mounting.override
# Allow wakeup from suspend using USB devices
cat <<'__EOF__' >/etc/rc.local
#!/bin/bash
# /etc/rc.local
#
# Enable USB wakeup, part 1
grep -e "USB.*disabled" /proc/acpi/wakeup |\
while read line; do
echo $line >/proc/acpi/wakeup
done
#
# Enable USB wakeup, part 2
for i in /sys/bus/usb/devices/*/power/wakeup; do echo "enabled" > $i; done
#
# Exit with success
exit 0
__EOF__
# More USB wakeup changes
cat <<'__EOF__' >/etc/usbwakeup-fixup.sh
#!/bin/bash
# /etc/usbwakeup-fixup.sh
(sleep 3; for i in /sys/bus/usb/devices/*/power/wakeup; do echo "enabled" > $i; done) &
__EOF__
# One more USB wakeup related change left
cat <<'__EOF__' >/etc/udev/rules.d/10-usb-wakeup.rules
# /etc/udev/rules.d/10-usb-wakeup.rules
ACTION=="add", SUBSYSTEM=="usb", IMPORT{program}="/bin/bash -c /etc/usbwake-fixup.sh"
__EOF__
# Ha! Fooled you! Still more USB wakeup. Promise this is last.
chmod a+x /etc/rc.local /etc/usbwakeup-fixup.sh
# Reload ath9k wlan drivers after suspend. This is needed as
# otherwise WLAN gets stuck at around 10Mbit/s instead of
# proper 300Mbit/s.
echo 'SUSPEND_MODULES="ath9k ath9k_hw ath9k_common"' >>/etc/pm/config.d/modules
# For PS3 BD remote we need to force older, patched Bluetooth stack.
# First make really sure no existing bluetooth package exist
apt-get -y purge bluez

# Add new repository and force use of Ubuntu 12.04 packages
# on XBMCbuntu 12 (Ubuntu 12.10)
add-apt-repository -y ppa:kitlaan/ppa
sed -i /etc/apt/sources.list.d/kitlaan-ppa-quantal.list -e's/quantal/precise/g'
cat <<'__EOF__' >/etc/apt/preferences.d/bluez
Package: bluez*
Pin: release o=LP-PPA-kitlaan
Pin-Priority: 1000 
__EOF__
# Install bluetooth stack
apt-get update
apt-get -y install bluez
# Pairing PS3 remote on Linux
# Grab required software
mkdir -p /opt/ps3pair
cd /opt/ps3pair
wget http://dump.asiantuntijakaveri.fi/le_bueno_dumpo/ps3pair.tar.gz
# or
# wget http://kitlaan.twinaxis.com/projects/bluez-ps3remote/ps3pair.tar.gz
tar xvzf ps3pair.tar.gz
mv ps3pair/* .
rmdir ps3pair

# Start pairing. Press and hold Start+Enter on 
# PS3 BD remote for at least 5 seconds to enter pairing mode.
python ps3_pair.py

# You should see something like this:
# Please HOLD the START and ENTER buttons on the PS3 remote.
# Searching for devices, please wait...
# Found:
# 1: 00:06:F5:93:BD:76 [Unknown]
# Select the device you wish to add [1]: 
#  Registering device...  Done

# Linux bluetooth pairing with PS3 remote is broken...
# Pairing does results in proper Linux side configuration, but PS3
# remote side never completes pairing.
#
# To workaround this problem you need to pair same USB bluetooth
# dongle with same PS3 remote on Windows 7. Only then remote is
# properly paired with dongle and also Linux side configuration
# is ok.

# For AR3011 in Windows use driver version 8.0.0.214 from
# http://www.station-drivers.com/page/atheros.htm or from mirror
# http://dump.asiantuntijakaveri.fi/le_bueno_dumpo/atheros_bluetooth_8.0.0.214-w7-8(www.station-drivers.com).exe
#
# Do pairing as with any other bluetooth device on Windows 7 using
# built-in add new device feature. Press and hold Start+Enter on
# PS3 BD remote for at least 5 seconds to enter pairing mode.

# Remove and re-insert batteries on PS3 BD remote to reset it
# after partial pairing attempt with Linux bluetooth stack.

# After pairing is complete both on Linux and Windows side we need
# to create custom input configuration file. This is just one example,
# you probably want different keymap.

# Fix configuration file
cat <<'__EOF__' >/etc/bluetooth/input.conf
[General]
IdleTimeout=180 # 3 minute timeout, shorten to improve battery life
[PS3 Remote Map]
OverlayBuiltin = FALSE
0x16 = KEY_ESC            # EJECT
0x64 = KEY_A              # AUDIO
0x65 = KEY_Z              # ANGLE
0x63 = KEY_T              # SUBTITLE
0x0f = KEY_O              # CLEAR
0x28 = KEY_I              # TIME
0x00 = KEY_1              # NUM-1
0x01 = KEY_2              # NUM-2
0x02 = KEY_3              # NUM-3
0x03 = KEY_4              # NUM-4
0x04 = KEY_5              # NUM-5
0x05 = KEY_6              # NUM-6
0x06 = KEY_7              # NUM-7
0x07 = KEY_8              # NUM-8
0x08 = KEY_9              # NUM-9
0x09 = KEY_0              # NUM-0
0x81 = KEY_S              # RED
0x82 = KEY_MUTE           # GREEN
0x80 = KEY_VOLUMEUP       # BLUE
0x83 = KEY_VOLUMEDOWN     # YELLOW
0x70 = KEY_I              # DISPLAY
0x1a = KEY_M              # TOP MENU
0x40 = KEY_M              # POP UP/MENU
0x0e = KEY_ESC            # RETURN
0x5c = KEY_C              # TRIANGLE/OPTIONS
0x5d = KEY_BACKSPACE      # CIRCLE/BACK
0x5f = KEY_TAB            # SQUARE/VIEW
0x5e = KEY_SPACE          # CROSS
0x54 = KEY_UP             # UP
0x56 = KEY_DOWN           # DOWN
0x57 = KEY_LEFT           # LEFT
0x55 = KEY_RIGHT          # RIGHT
0x0b = KEY_ENTER          # ENTER
0x5a = KEY_VOLUMEUP       # L1
0x58 = KEY_VOLUMEDOWN     # L2
0x51 = KEY_MUTE           # L3
0x5b = KEY_VOLUMEUP       # R1
0x59 = KEY_VOLUMEDOWN     # R2
0x52 = KEY_MUTE           # R3
0x43 = KEY_HOMEPAGE       # PS button
0x50 = KEY_ENTER          # SELECT
0x53 = KEY_PLAY           # START
0x33 = KEY_R              # SCAN BACK
0x32 = KEY_PLAY           # PLAY
0x34 = KEY_F              # SCAN FORWARD
0x30 = KEY_DOWN           # PREVIOUS
0x38 = KEY_X              # STOP
0x31 = KEY_UP             # NEXT
0x60 = KEY_LEFT           # SLOW/STEP BACK
0x39 = KEY_PLAY           # PAUSE
0x61 = KEY_RIGHT          # SLOW/STEP FORWARD
__EOF__

# Restart bluetooth service
service bluetooth restart

# Now press some button on PS3 BD remote. Blue led on USB bluetooth
# dongle has been solid blue so far and should start flashing.

# To save battery life we need to disconnect PS3 BD remote on
# shutdown and suspend
mkdir -p /opt/bt-disconnect
cd /opt/bt-disconnect
wget http://dump.asiantuntijakaveri.fi/le_bueno_dumpo/bt-disconnect-all.py
# or
# wget http://kitlaan.twinaxis.com/projects/bluez-ps3remote/bt-disconnect-all.py
chmod a+x bt-disconnect-all.py

# Disconnect on shutdown
cat <<'__EOF__' >/etc/rc6.d/K99btdisconnect
#!/bin/sh
date >>/opt/bt-disconnect/log
exec /opt/bt-disconnect/bt-disconnect-all.py >>/opt/bt-disconnect/log 2>&1
__EOF__

# exec bit needed as usual
chmod a+x /etc/rc6.d/K99btdisconnect

# Disconnect on suspend
cat <<'__EOF__' >/etc/pm/sleep.d/bt-disconnect.sh
#!/bin/bash
case $1 in
suspend)
  date >>/opt/bt-disconnect/log
  /opt/bt-disconnect/bt-disconnect-all.py >>/opt/bt-disconnect/log
  ;;
resume)
  # do nothing
  ;;
esac
__EOF__

# And finally make it executable
chmod a+x /etc/pm/sleep.d/bt-disconnect.sh

# If you managed to follow instructions your PS3 BD remote can now
# control XBMC.

Comments