#!/bin/bash
#
# jernst's Ubuntu post-install script
#
# Copyright (C) 2009 Jonathan Ernst
#
# 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 3 of the License, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#
# English : http://ernstfamily.ch/jonathan/2009/05/script-de-post-installation-pour-ubuntu
# Français : http://ernstfamily.ch/jonathan/2009/05/script-de-post-installation-pour-ubuntu
#
# Version: 20090923
#
# Inverted changelog :
#
# 20090923
# - disable CONCURRENCY=shell as it makes karmic behave badly (cups not starting, etc.)
#
# 20090613
# - accept sun license when installing ubuntu-restricted-extras too
# - allow user to not delete the script and its logs
# - misc small fixes
#
# 20090604
# - try to fetch medibuntu key from more locations
#
# 20090519
# - suppress harmless errors from standard output
# - fix a bug that caused some software installation failure
#
# 20090512
# - first localisable version
# - english l10n
# - ability to install the latest version of OpenOffice.org (disabled for now)
# - disable the waiting delay before logout in Jaunty (optimizations and tweaks)
# - several improvements and fixes (thanks for your feedback)
# - add ssh keys even if .ssh existed already
#
# 20090507
# - reactivate Ctrl+alt+backspace in Jaunty (optimizations and tweaks)
# - activate Medibuntu even if apt-get ends in error
# - temorary files in RAM if RAM ~> 2GB 
# - more comments to understand the code
# - fix an issue with the update system
#
# 20090506
# - define CONCURRENCY=shell in /etc/init.d/rc (optimizations and tweaks)
#
# 20090505
# - checks for new versions on the Web
# - don't add repositories twice (the script can now be run several times)
# - misc. fixes (thanks for the feedback)
#
# 20090504
# - disable system bips (optimizations and tweaks)
# - progress bar not pulsing anymore
# - log file (deleted when quitting)
#
# 20090503
# - licensing
# - delete my own public SSH key in the configuration
# - checklist instead of multiple dialog boxes
#
# 20090502
# - first version
#
#
# Historique inversé :
#
# 20090923
# - désactive CONCURRENCY=shell à cause de problèmes avec karmic (cups ne démarre pas, etc.)
#
# 20090613
# - accepte la licence de sun lors de l'installation d'ubuntu-restricted-extras
# - permet à l'utilisateur de ne pas supprimer le script et ses logs
# - correction diverses
#
# 20090604
# - essaie de récupérer la clé de medubuntu depuis plus d'endroits
#
# 20090519
# - suppression d'erreurs sans conséquences sur la sortie standard
# - correction d'un bug qui empêchait l'installation de certains logiciels
#
# 20090512
# - première version localisable
# - version anglaise
# - possibilité d'installer la dernière version d'OpenOffice.org (désactivé pour l'instant)
# - désactive le délai d'attente avant la déconnexion dans Jaunty (optimisations et ajustements)
# - diverses corrections et améliorations (merci pour les commentaires)
# - ajoute les clés ssh même si .ssh existait déjà
#
# 20090507
# - réactive Ctrl+alt+backspace dans Jaunty (optimisations et ajustements)
# - active la clé de Medibuntu même si apt-get renvoie une erreur
# - fichiers temporaires en RAM si RAM ~> 2GB 
# - plus de commentaires pour comprendre le code
# - correction d'un problème avec le système de mise à jour
#
# 20090506
# - définit CONCURRENCY=shell dans /etc/init.d/rc (optimisations et ajustement)
#
# 20090505
# - vérifie l'existence d'une nouvelle version du script sur Internet
# - n'ajoute pas les dépôts à double (permet d'exécuter le script plusieurs fois)
# - diverses corrections (merci pour les commentaires)
#
# 20090504
# - désactive les bips système (optimisations et ajustement)
# - barre de progression « non-pulsante »
# - fichier log (supprimé lorsqu'on quitte le script)
#
# 20090503
# - précision de la licence
# - suppression de la clé ssh publique par défaut dans la configuration
# - mise en place d'une liste de choix à la place des boîtes de dialogue
#
# 20090502
# - version initiale

#################
# Configuration #
#################
# Clés SSH autorisées pour le login sur le compte utilisateur et root
# KEYS="ssh-rsa XXXXX user@user-desktop"
KEYS=""

# Logiciels libres à installer
FREESOFTWARE="adblock-plus nmap iotop python-coherence wine pidgin-plugin-pack pidgin-facebookchat language-support-fr language-pack-fr language-pack-gnome-fr cheese simple-ccsm compizconfig-settings-manager p7zip-full vim"

# Polices de caractère à installer
FONTS="msttcorefonts ttf-liberation ttf-dejavu"

# Codecs et logiciels multimédia
CODECS="vlc non-free-codecs flashplugin-nonfree gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly-multiverse unrar ubuntu-restricted-extras"

# Logiciels d'optimisation
TWEAKS="prelink preload dontzap"

# Chaînes de caractères
case "$LANG" in
    *"fr_"* )
        S_SCRIPTNAME="Ubuntu post-install"
        S_ENTERPASSWORD="Merci de saisir votre mot de passe pour poursuivre..."
        S_CHANGELOG="Historique"
        S_NEWVERSIONAVAILABLE="Une nouvelle version est disponible sur Internet !\nVoulez-vous exécuter cette nouvelle version (ONLINEVERSION) à la place de votre version actuelle (CURRENTVERSION) ?"
        S_WARNING="ATTENTION : Ce script va modifier votre installation d'Ubuntu de façon automatique !"
        S_DESCRIPTION="Description"
        S_OPTIONS="Options"
        S_ADDITIONALREPOSITORIES="Dépôts supplémentaires"
        S_FREESOFTWARES="Logiciels libres"
        S_SSHSERVER="Serveur SSH"
        S_OVPNCLIENT="Client OpenVPN"
        S_ADDITIONALCODECS="Codecs supplémentaires (dont certain non libres)"
        S_ADDITIONALFONTS="Polices de caractères supplémentaires"
        S_LATESTOOORG="Dernière version d'OpenOffice.org"
        S_UNINSTALLTRACKER="Désinstallation du moteur d'indexation tracker"
        S_DESKTOPSHORTCUTS="Raccourci vers le dossier personnel et la corbeille sur le bureau"
        S_SKYPE="Logiciel propriétaire de téléphonie IP Skype"
        S_GOOGLEEARTH="Logiciel propriétaire Google Earth"
        S_PICASA="Logiciel propriétaire de gestion de photos Google Picasa"
        S_JAVA="Logiciel propriétaire Java de Sun"
        S_TWEAKSANDOPTIMISATIONS="Optimisations et ajustements"
        S_DELETESCRIPTANDLOG="Supprime ce script et ses logs à la fermeture"
        S_ADDEDBY="Dépôts ajoutés par"
        S_OOOADDEDBY="Dépôts OpenOffice.org Scribblers ajouté par"
        S_DELETINGEXTRAREPOSITORIES="Suppression des dépôts à double..."
        S_ADDINGREPOSITORIESFOR="Ajout de dépôts pour RELEASE..."
        S_ADDINGKEYSANDUPDATINGSOFTWARE="Ajout des clés et mise à jour de la liste des logiciels..."
        S_INSTALLINGFREESOFTWARE="Installation de logiciels libres..."
        S_INSTALLINGCODECS="Installation de codecs et lecteurs multimedia..."
        S_UNINSTALLINGTRACKER="Désinstallation de tracker..."
        S_INSTALLINGFONTS="Installation de polices de caractère..."
        S_ADDINGOOOREPOSITORY="Ajout des dépôts OpenOffice.org Scribblers..."
        S_ADDINGSHORTCUTS="Ajout de raccourcis sur le bureau..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONS="Optimisations et ajustements..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONSPRELINK="Optimisations et ajustements (prelink en cours)..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONSTMPINRAM="Optimisations et ajustements (chargement des fichiers temporaires en RAM)..."
        S_TMPINRAM="Fichiers temporaires dans la ram, ajouté par"
        S_INSTALLINGTWEAKSANDOPTIMISATIONSCONCURRENTSTARTUP="Optimisations et ajustements (parallélisation des scripts de démarrage)..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONSNOBIP="Optimisations et ajustements (désactivation du bip système)..."
        S_NOBIPS="Désactive les bips système, ajouté par"
        S_INSTALLINGTWEAKSANDOPTIMISATIONSCTRLALTBCKSPCE="Optimisations et ajustements (réactivation de CTRL+ALT+RETOUR pour tuer X)..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONSNOWAITBEFORELOGOUT="Optimisations et ajustements (suppression de l'attente de 60 secondes avant de fermer la session)..."
        S_FINISHED="Terminé !\nMerci de poster vos commentaires sur http://ernstfamily.ch/jonathan/2009/05/script-de-post-installation-pour-ubuntu"
        S_INSTALLINGPROPRIETARYSOFTWARE="Installation de logiciels propriétaires supplémentaires..."
        S_UPDATINGSYSTEM="Mise à jour du système..."
        S_CLEANING="Nettoyage..."
        S_RESTARTINGCRON="Redémarrage de cron..."
    ;;
    *)
        S_SCRIPTNAME="Ubuntu post-install"
        S_ENTERPASSWORD="Please enter your password to continue..."
        S_CHANGELOG="changelog"
        S_NEWVERSIONAVAILABLE="A new version is available on the Web!\nWould you like to run this new version (ONLINEVERSION) instead of the current version (CURRENTVERSION)?"
        S_WARNING="WARNING: This script will update your Ubuntu installation automatically!"
        S_DESCRIPTION="Description"
        S_OPTIONS="Options"
        S_ADDITIONALREPOSITORIES="Additional repositories"
        S_FREESOFTWARES="Free software"
        S_SSHSERVER="SSH server"
        S_OVPNCLIENT="OpenVPN client"
        S_ADDITIONALCODECS="Additional codecs (including some non-free ones)"
        S_ADDITIONALFONTS="Additional fonts"
        S_LATESTOOORG="Latest OpenOffice.org version"
        S_UNINSTALLTRACKER="Uninstall tracker indexing engine"
        S_DESKTOPSHORTCUTS="Shortcut to personnal folder and trash on the desktop"
        S_SKYPE="Skype VoIP proprietary software"
        S_GOOGLEEARTH="Google Earth proprietary software"
        S_PICASA="Proprietary photo management software Google Picasa"
        S_JAVA="Sun proprietary Java software"
        S_TWEAKSANDOPTIMISATIONS="Optimizations and tweaks"
        S_DELETESCRIPTANDLOG="Deletes this script and its logs after execution"
        S_ADDEDBY="Repositories added by"
        S_OOOADDEDBY="OpenOffice.org Scribblers repositories added by"
        S_DELETINGEXTRAREPOSITORIES="Extraneous repositories deletion..."
        S_ADDINGREPOSITORIESFOR="Adding repositories for RELEASE..."
        S_ADDINGKEYSANDUPDATINGSOFTWARE="Adding keys and updating software lists..."
        S_INSTALLINGFREESOFTWARE="Installing free software..."
        S_INSTALLINGCODECS="Installing codecs and media players..."
        S_UNINSTALLINGTRACKER="Uninstalling tracker..."
        S_INSTALLINGFONTS="Installing fonts..."
        S_ADDINGOOOREPOSITORY="Adding OpenOffice.org Scribblers repositories..."
        S_ADDINGSHORTCUTS="Adding shortcuts on the desktop..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONS="Optimizations and tweaks..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONSPRELINK="Optimizations and tweaks (prelinking)..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONSTMPINRAM="Optimizations and tweaks (chargement des fichiers temporaires en RAM)..."
        S_TMPINRAM="Temporary files in RAM, added by"
        S_INSTALLINGTWEAKSANDOPTIMISATIONSCONCURRENTSTARTUP="Optimizations and tweaks (startup scripts concurrency)..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONSNOBIP="Optimizations and tweaks (disabling system bips)..."
        S_NOBIPS="Disable system bips, added by"
        S_INSTALLINGTWEAKSANDOPTIMISATIONSCTRLALTBCKSPCE="Optimizations and tweaks (reactivating CTRL+ALT+BACKSPACE to kill X)..."
        S_INSTALLINGTWEAKSANDOPTIMISATIONSNOWAITBEFORELOGOUT="Optimizations and tweaks (suppressing 60 seconds wait before logout)..."
        S_FINISHED="Finished!\nPlease send your comments on http://ernstfamily.ch/jonathan/2009/05/script-de-post-installation-pour-ubuntu"
        S_INSTALLINGPROPRIETARYSOFTWARE="Installing proprietary software..."
        S_UPDATINGSYSTEM="Updating system..."
        S_CLEANING="Cleanup..."
        S_RESTARTINGCRON="Restarting cron..."
    ;;
esac


# Vérifie les mises à jour
CHECKUPDATE="TRUE"

#################
#   Functions   #
#################
check_update () 
{
    CURRENTVERSION=`grep -m1 "# Version: " $0 | awk '{print$3}'`
    if [ "$CHECKUPDATE" = "TRUE" ] ; then
        wget http://ernstfamily.ch/jonathan/uploads/postinstall.sh --timeout=10 -a $0.log -O $0.new
        ONLINEVERSION=`grep -m1 "# Version: " $0.new | awk '{print$3}'`
        CHANGELOG=`grep -m1 -A10 "# $S_CHANGELOG" $0.new`
        if [ "$ONLINEVERSION" -gt "$CURRENTVERSION" ] ; then
            S_NEWVERSIONAVAILABLE=`echo "$S_NEWVERSIONAVAILABLE" | sed s/ONLINEVERSION/$ONLINEVERSION/g`
            S_NEWVERSIONAVAILABLE=`echo "$S_NEWVERSIONAVAILABLE" | sed s/CURRENTVERSION/$CURRENTVERSION/g`
            if $(zenity --question --no-wrap --title "$S_SCRIPTNAME $CURRENTVERSION" --text "$S_NEWVERSIONAVAILABLE\n\n$CHANGELOG\n[...]") ; then
                mv $0.new $0
                chmod +x $0
                $0
                exit 0
            fi
        fi
        rm $0.new
    fi
}

disable_automatic_updates ()
{
    gksudo -m "$S_ENTERPASSWORD" "killall -q update-manager" >> $0.log 2>&1
    gksudo -m "$S_ENTERPASSWORD" "killall -q update-notifier" >> $0.log 2>&1
    gksudo -m "$S_ENTERPASSWORD" "killall -q synaptic" >> $0.log 2>&1
    gksudo -m "$S_ENTERPASSWORD" "/etc/init.d/cron stop" >> $0.log 2>&1
}

enable_automatic_updates ()
{
    message "# $S_RESTARTINGCRON"
    gksudo -m "$S_ENTERPASSWORD" "/etc/init.d/cron start" >> $0.log 2>&1
}

message ()
{
    echo $1
    echo $1 >> $0.log 2>&1
}

#################
#    Script     #
#################
check_update
disable_automatic_updates

# Disabled for now, too many problems    FALSE G "$S_LATESTOOORG"\

choice="$(zenity --width=500 --height=450 --list --column "" --checklist --title="$S_SCRIPTNAME $CURRENTVERSION - $S_OPTIONS" --text "$S_WARNING" \
    --column="" --column="$S_DESCRIPTION"\
    TRUE A "$S_ADDITIONALREPOSITORIES"\
    TRUE B "$S_FREESOFTWARES"\
    TRUE C "$S_SSHSERVER"\
    TRUE D "$S_OVPNCLIENT"\
    TRUE E "$S_ADDITIONALCODECS"\
    TRUE F "$S_ADDITIONALFONTS"\
    FALSE H "$S_UNINSTALLTRACKER"\
    FALSE I "$S_DESKTOPSHORTCUTS"\
    FALSE J "$S_SKYPE"\
    FALSE K "$S_GOOGLEEARTH"\
    FALSE L "$S_PICASA"\
    FALSE M "$S_JAVA"\
    FALSE N "$S_TWEAKSANDOPTIMISATIONS"\
    TRUE Z "$S_DELETESCRIPTANDLOG"\
  )"

export DEBIAN_FRONTEND=noninteractive

(
case "${choice}" in
    *"A"* )
    RELEASE=`lsb_release -c | awk '{print$2}'`
    message "# $S_DELETINGEXTRAREPOSITORIES"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "grep -v dl.google.com /etc/apt/sources.list | grep -v medibuntu.org | grep -v wine.budgetdedicated | grep -v 'partner # partner' | grep -v postinstall.sh | uniq > /tmp/sources.list && cp /tmp/sources.list /etc/apt/sources.list"
    S_ADDINGREPOSITORIESFOR=`echo "$S_ADDINGREPOSITORIESFOR" | sed s/RELEASE/$RELEASE/g`
    message "# $S_ADDINGREPOSITORIESFOR"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "
    cat >> /etc/apt/sources.list <<EOF 

# $S_ADDEDBY postinstall.sh $CURRENTVERSION
deb http://dl.google.com/linux/deb/ stable non-free # Google stable
deb http://dl.google.com/linux/deb/ testing non-free # Google testing
deb http://packages.medibuntu.org/ $RELEASE free non-free # Medibuntu
deb http://wine.budgetdedicated.com/apt $RELEASE main # Wine
deb http://archive.canonical.com/ubuntu $RELEASE partner # partner
EOF"

    message "# $S_ADDINGKEYSANDUPDATINGSOFTWARE"
    gksudo -- bash -c "wget -q http://wine.budgetdedicated.com/apt/387EE263.gpg -O- | apt-key add -" >> $0.log 2>&1
    gksudo -- bash -c "wget -q https://dl-ssl.google.com/linux/linux_signing_key.pub -O- | apt-key add -" >> $0.log 2>&1
    gksudo -- bash -c "wget -q http://fr.packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add -" >> $0.log 2>&1
    # just in case the previous import was not successfull
    gksudo -- bash -c "wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add -" >> $0.log 2>&1
    gksudo "aptitude update" >> $0.log 2>&1
    # sometimes medibuntu key is not retrieved, let's try one more time
    gksudo "apt-get install -y --force-yes medibuntu-keyring" >> $0.log 2>&1
    echo "10"
    ;;
esac

case "${choice}" in
    *"B"* )
    message "# $S_INSTALLINGFREESOFTWARE"
    gksudo "aptitude install -y $FREESOFTWARE" >> $0.log 2>&1
    echo "30"
    ;;
esac

case "${choice}" in
    *"C"* )
    mkdir ~/.ssh > /dev/null 2>&1
    cat >> ~/.ssh/authorized_keys <<EOF 
$KEYS
EOF
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "mkdir ~root/.ssh > /dev/null 2>&1"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "
cat >> ~root/.ssh/authorized_keys <<EOF 
$KEYS
EOF"  
    MORESOFTWARE="$MORESOFTWARE openssh-server"
    echo "35"
    ;;
esac

case "${choice}" in
    *"D"* )
    MORESOFTWARE="$MORESOFTWARE openvpn network-manager-openvpn"
    echo "40"
    ;;
esac

case "${choice}" in
    *"E"* )
    message "# $S_INSTALLINGCODECS"
    # sun-java6-jre is included in ubuntu-extras...
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "echo sun-java6-jre shared/accepted-sun-dlj-v1-1 select true | /usr/bin/debconf-set-selections"
    gksudo "aptitude install -y $CODECS" >> $0.log 2>&1
    echo "50"
    ;;
esac

case "${choice}" in
    *"F"* )
    message "# $S_INSTALLINGFONTS"
    gksudo "aptitude install -y $FONTS" >> $0.log 2>&1
    echo "60"
    ;;
esac

case "${choice}" in
    *"G"* )
    message "# $S_DELETEINGEXTRAREPOSITORIES"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "grep -v 'ppa.launchpad.net/openoffice-pkgs' /etc/apt/sources.list | grep -v 'OpenOffice.org Scribblers' | uniq > /tmp/sources.list && cp /tmp/sources.list /etc/apt/sources.list"
    message "# $S_ADDINGOOOREPOSITORY"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "
    cat >> /etc/apt/sources.list <<EOF 

# $S_OOOADDEDBY postinstall.sh $CURRENTVERSION
deb http://ppa.launchpad.net/openoffice-pkgs/ppa/ubuntu $RELEASE main
deb-src http://ppa.launchpad.net/openoffice-pkgs/ppa/ubuntu $RELEASE main
EOF"
    gksudo "apt-key adv --recv-keys --keyserver keyserver.ubuntu.com D2BB86E0EBD0F0A43D4DB3A760D11217247D1CFF" >> $0.log 2>&1
    echo "63"
    ;;
esac

case "${choice}" in
    *"H"* )
    message "# $S_UNINSTALLINGTRACKER"
    gksudo "aptitude remove --purge -y tracker" >> $0.log 2>&1
    echo "65"
    ;;
esac

case "${choice}" in
    *"I"* )
    message "# $S_ADDINGSHORTCUTS"
    gconftool-2 --set "/apps/nautilus/desktop/home_icon_visible" --type bool TRUE
    gconftool-2 --set "/apps/nautilus/desktop/home_icon_name" --type string "Dossier personnel"
    gconftool-2 --set "/apps/nautilus/desktop/trash_icon_visible" --type bool TRUE
    echo "65"
    ;;
esac

case "${choice}" in
    *"J"* )
    MORESOFTWARE="$MORESOFTWARE skype"
    ;;
esac

case "${choice}" in
    *"K"* )
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "echo googleearth shared/accepted-googleearth-eula select true | /usr/bin/debconf-set-selections"
    MORESOFTWARE="$MORESOFTWARE googleearth"
    ;;
esac

case "${choice}" in
    *"L"* )
    MORESOFTWARE="$MORESOFTWARE picasa"
    ;;
esac

case "${choice}" in
    *"M"* )
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "echo sun-java6-jre shared/accepted-sun-dlj-v1-1 select true | /usr/bin/debconf-set-selections"
    MORESOFTWARE="$MORESOFTWARE sun-java6-plugin"
    ;;
esac

case "${choice}" in
    *"N"* )
    message "# $S_INSTALLINGTWEAKSANDOPTIMISATIONS"
    gksudo "aptitude install -y $TWEAKS" >> $0.log 2>&1
    echo "70"

    message "# $S_INSTALLINGTWEAKSANDOPTIMISATIONSPRELINK"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "sed s/PRELINKING=unknown/PRELINKING=yes/g /etc/default/prelink > /tmp/prelink && cp /tmp/prelink /etc/default/prelink && /etc/cron.daily/prelink"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "sed s/relatime/noatime/g /etc/fstab > /tmp/fstab && cp /tmp/fstab /etc/fstab"

    MEMORY=`free | grep Mem | awk '{print$2}'`
    grep "/tmp" /etc/fstab
    if [ $? != 0 ] && [ "$MEMORY" -gt "1900000" ]; then
        message "# $S_INSTALLINGTWEAKSANDOPTIMISATIONSTMPINRAM"
        gksudo -m "$S_ENTERPASSWORD" -- bash -c "
        cat >> /etc/fstab <<EOF

# $S_TMPINRAM postinstall.sh $CURRENTVERSION
tmpfs      /tmp            tmpfs        defaults           0    0
tmpfs      /var/tmp        tmpfs        defaults           0    0
EOF"
    fi

    message "# $S_INSTALLINGTWEAKSANDOPTIMISATIONSCONCURRENTSTARTUP"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "sed s/^CONCURRENCY=shell/CONCURRENCY=none/g /etc/init.d/rc > /tmp/rc && cp /tmp/rc /etc/init.d/rc"

    message "# $S_INSTALLINGTWEAKSANDOPTIMISATIONSNOBIP"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "grep -v 'blacklist pcspkr' /etc/modprobe.d/blacklist.conf | grep -v postinstall.sh | uniq > /tmp/blacklist.conf && cp /tmp/blacklist.conf /etc/modprobe.d/blacklist.conf"
    gksudo -m "$S_ENTERPASSWORD" -- bash -c "
    cat >> /etc/modprobe.d/blacklist.conf <<EOF 

# $S_NOBIPS postinstall.sh $CURRENTVERSION
blacklist pcspkr
EOF"
    gksudo "modprobe -r pcspkr"

    message "# $S_INSTALLINGTWEAKSANDOPTIMISATIONSCTRLALTBCKSPCE"
    gksudo "dontzap -d"
    echo "73"

    message "# $S_INSTALLINGTWEAKSANDOPTIMISATIONSNOWAITBEFORELOGOUT"
    APPLET0=`gconftool-2 --get /apps/panel/applets/applet_0/prefs/suppress_logout_restart_shutdown 2>/dev/null`
    if [ "$APPLET0" = "false" ] ; then
        gconftool-2 --set /apps/panel/applets/applet_0/prefs/suppress_logout_restart_shutdown --type=bool TRUE >> $0.log 2>&1
    fi
    FUSA0=`gconftool-2 --get /apps/panel/applets/fast_user_switch_screen0/prefs/suppress_logout_restart_shutdown 2>/dev/null`
    if [ "$FUSA0" = "false" ] ; then
        gconftool-2 --set /apps/panel/applets/fast_user_switch_screen0/prefs/suppress_logout_restart_shutdown --type=bool TRUE >> $0.log 2>&1
    fi
    echo "75"
    ;;
esac

case "${choice}" in
    "" )
    message "# $S_FINISHED"
    exit 0
    ;;
esac

message "# $S_INSTALLINGPROPRIETARYSOFTWARE"
gksudo "aptitude install -y $MORESOFTWARE" >> $0.log 2>&1
echo "90"

message "# $S_UPDATINGSYSTEM"
gksudo "aptitude update" >> $0.log 2>&1
gksudo "aptitude dist-upgrade -y" >> $0.log 2>&1
echo "96"

message "# $S_CLEANING"
gksudo "aptitude autoclean" >> $0.log 2>&1
gksudo "apt-get autoremove -y" >> $0.log 2>&1
echo "100"

message "# $S_FINISHED"
) | zenity --progress --width 500 --height 150 --title "$S_SCRIPTNAME $CURRENTVERSION" --percentage=0 

enable_automatic_updates


case "${choice}" in
    *"Z"* )
    rm $0
    rm $0.log
    ;;
esac

