#!/bin/sh
set -e

# Hook for building live images
#
# This script is run in the built chroot after all packages are installed,
# before it is packed into a squashfs. This is where you can apply extra tweaks
# to the live system.
echo 'export USERFULLNAME="Baltix Live user"' >> /etc/casper.conf
echo "deb http://download.videolan.org/pub/debian/stable/ /" >> /etc/apt/sources.list.d/videolan-dvdcss.list && wget -O - http://download.videolan.org/pub/debian/videolan-apt.asc|apt-key add -
apt-get --quiet update
apt-get  --yes install libdvdcss2
apt-get purge --auto-remove -y ttf-wqy-microhei fonts-nanum fonts-takao-pgothic fonts-khmeros-core fonts-thai-tlwg fonts-tlwg-typewriter fonts-kacst
# language-pack-zh-hans language-pack-gnome-zh-hans language-pack-es language-pack-gnome-es language-pack-pt language-pack-gnome-pt firefox-locale-zh-hans firefox-locale-es firefox-locale-pt
apt-get purge --auto-remove -y gdb libgdu-gtk0 linux-headers-3.2.0-23 libreoffice-l10n-en-za ibus-pinyin-db-android ibus-pinyin libopencc1
#Removing unneeded recommended packages
apt-get purge --auto-remove -y libqt4-sql-mysql
# Removing unneeded packages since 12.04.1
apt-get purge --auto-remove -y librhythmbox-core5 libmusicbrainz3-6 liborbit2 libavahi-ui-gtk3-0 libidl0 libidl-common libutouch-geis1 libutouch-grail1 libutouch-frame1 libutouch-evemu1
# Hardinfo package recommends lm-sensors, but lm-sensors sets sensors limits at startup
# I'm not sure if sensors -s at computer startup won't cause problems on some systems
# qt-at-spi causes crash in QT file open/save dialogs, see http://launchpad.net/bugs/998012
apt-get purge --auto-remove -y lm-sensors qt-at-spi apport-gtk
# downgrading thunderbird* and linux-firmware-nonfree to save some space in LiveCD
apt-get --force-yes --yes install linux-firmware-nonfree=1.11 thunderbird=11.0.1+build1-0ubuntu2 thunderbird-locale-lt=1:11.0.1+build1-0ubuntu2 thunderbird-gnome-support=11.0.1+build1-0ubuntu2
# Ubuntu-defaults-baltix package contains custom /etc/locale.nopurge config
# to remove unneeded non-european translations
test -x /usr/share/ubuntu-defaults-baltix/hooks/localepurge && /usr/share/ubuntu-defaults-baltix/hooks/localepurge
#Lowers memory usage in Live session by removing unneeded shell prompts on virtual consoles
test -w /usr/share/initramfs-tools/scripts/casper-bottom/25configure_init && sed -i -e "s|^log_end_msg.*|rm -f /root/etc/init/tty3.conf /root/etc/init/tty4.conf /root/etc/init/tty5.conf /root/etc/init/tty6.conf\n\n&|" /usr/share/initramfs-tools/scripts/casper-bottom/25configure_init

# Show more examples for user
ln -s /usr/share/checkbox/data/documents /usr/share/example-content/Documents

# Translate LibreOffice launcher to Lithuanian language - 
# Lithuanian users should find office suite by typing rašyk ir skaičiuok
echo "Name[lt]=Raštinės programos „LibreOffice“">>/usr/share/applications/libreoffice-startcenter.desktop
echo "Comment[lt]=Biuro programų paketas (Rašyklė, Skaičiuoklė, Pateikčių rengyklė, Braižymo bei Duomenų bazių programos ir kt.), palaikantis OpenDocument bei kitus populiarius dokumentų formatus">>/usr/share/applications/libreoffice-startcenter.desktop

# Remove unneeded translations of LibreOffice Letter wizard
# TODO: bugreport: these files should go to libreoffice language packs
for lang in bg eu hu ja km ko pt pt-BR tr vi zh-CN zh-TW; do
 rm -rfv /usr/lib/libreoffice/share/template/wizard/letter/$lang
done

# Remove not needed big files from brltty tool
rm -fv /etc/brltty/zh-tw* /etc/brltty/ko.ctb /usr/share/doc/brltty/French/* /usr/share/doc/brltty/English/BRLTTY.txt.gz

# Copy updated (not identical) firmware files from /lib/firmware/3.8.0-*/ to 
# /lib/firmware in hooks/chroot (duplicated files doesn't use space in compressed filesystem)
for firmware in phanfw.bin ql2500_fw.bin ql2400_fw.bin ql2322_fw.bin ql2300_fw.bin "mrvl/sd8787_uapsta.bin"; do
 cmp /lib/firmware/3.8.0-*/$firmware /lib/firmware/$firmware || cp /lib/firmware/3.8.0-*/$firmware /lib/firmware/$firmware
done

# checkbox/data/video/* wastes 800Kb and aren't needed for user
rm -fv /usr/share/checkbox/data/video/*
ln -s "/usr/share/example-content/Ubuntu_Free_Culture_Showcase/How fast.ogg" "/usr/share/checkbox/data/video/Ogg_Theora_Video.ogv"

# Remove big changelog.gz and other unneeded files from doc folder
rm -fv /usr/share/doc/rhythmbox-mozilla/changelog.gz /usr/share/doc/rhythmbox-plugin-cdrecorder/changelog.gz /usr/share/doc/librhythmbox-core6/changelog.gz /usr/share/doc/gir1.2-rb-3.0/changelog.gz /usr/share/doc/rhythmbox-data/changelog.gz /usr/share/doc/rhythmbox-plugin-zeitgeist/changelog.gz /usr/share/doc/rhythmbox-plugin-magnatune/changelog.gz /usr/share/doc/rhythmbox/changelog.gz /usr/share/doc/rhythmbox-plugins/changelog.gz
rm -fv /usr/share/doc-base/xterm-faq /usr/share/doc/xterm/xterm.faq.html /usr/share/doc/xterm/xterm.log.html /usr/share/doc/xterm/xterm.faq.gz
rm -fv /usr/share/doc/libgtk2.0-0/changelog.gz /usr/share/doc/gcc-4.6-base/changelog.gz /usr/share/doc/libgd2-xpm/README.html
rm -fv /usr/share/doc-base/configobj-api /usr/share/doc/python-configobj/api/* /usr/share/doc/python-configobj/api/configobj-pysrc.html /usr/share/doc/python-configobj/configobj.html /usr/share/doc/python-configobj/validate.html
rm -fv /usr/share/doc/libsane/html/sane-backends.html /usr/share/doc/libsane/umax/sane-umax-*a*.jpg /usr/share/doc/libsane/umax/sane-umax.jpg
rm -fv /usr/share/doc/printer-driver-foo2zjs/manual.pdf /usr/share/doc-base/foo2zjs
rm -fv /usr/share/doc/syslinux/logo/syslinux-100.png /usr/share/doc/syslinux/CodingStyle.txt.gz
rm -fv /usr/share/doc/shared-mime-info/shared-mime-info-spec.pdf /usr/share/doc-base/shared-mime-info
for lang in bg ca cs eu el es it hu ja km ko pt pt-BR tr vi zh-CN zh-TW sv; do
 rm -rfv /usr/share/gnome/help/rhythmbox/$lang
 rm -rfv /usr/share/gnome/help/gweather/$lang
 rm -rfv /usr/share/gnome/help/stickynotes_applet/$lang
 rm -rfv /usr/share/gnome/help/multiload/$lang
 rm -rfv /usr/share/gnome/help/char-palette/$lang
 rm -rfv /usr/share/gnome/help/gnome-search-tool/$lang
 rm -rfv /usr/share/gnome/help/cpufreq-applet/$lang
done

dpkg --clear-avail
dpkg --clear-avail
