#!/bin/bash
# Launch in current folder with sh install.sh
# Post install to custom Xubuntu 24.04
# Exclusive lock / OK
sudo dpkg --configure -a
# Clean / OK
sudo apt-get purge -y --autoremove atril mate-calc parole ristretto mousepad sgt-puzzles xterm hexchat rhythmbox
# Update / OK
sudo apt-get update && sudo apt-get upgrade -y
# Install / Retrait libgconf-2-4 Synaptic déjà installé / OK
sudo apt-get install -y gedit usb-creator-gtk xubuntu-restricted-addons jmtpfs firmware-b43-installer gnome-disk-utility shotwell libdvd-pkg libavcodec-extra unrar lame gparted printer-driver-gutenprint simplescreenrecorder libreoffice libreoffice-help-fr libreoffice-l10n-fr redshift redshift-gtk evince vlc hardinfo firefox-locale-fr clementine eog gnome-calculator blockout2 flobopuyo aisleriot gnome-mahjongg inkscape frozen-bubble supertux ttf-mscorefonts-installer tuxpaint tuxmath gcompris-qt stellarium pingus ri-li gtans slimevolley kbreakout neverball pybik foobillardplus gnome-mastermind raincat kfourinline knavalbattle kreversi klickety gnome-klotski khangman marble gufw
# Add guest user and get rid of warning on session connexion
sudo cp -a ./config/guest/lightdm.conf.d/40-enable-guest.conf /etc/lightdm/lightdm.conf.d/
sudo cp -a ./config/guest/guest-session/prefs.sh /etc/guest-session/
# Install Faenza Icons / OK
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/faenza-icon-theme/faenza-icon-theme_1.3.zip &&
unzip faenza-icon-theme_1.3.zip &&
for file in *.tar.gz; do tar -zxf $file; done &&
sudo mv -t /usr/share/icons/ emesene/ Faenza/ Faenza-Ambiance/ Faenza-Dark/ Faenza-Darker/ Faenza-Darkest/ Faenza-Radiance/ &&
rm -r AUTHORS ChangeLog COPYING INSTALL README UNINSTALL emesene-faenza-theme.tar.gz Faenza.tar.gz Faenza-Ambiance.tar.gz Faenza-Dark.tar.gz Faenza-Darker.tar.gz Faenza-Darkest.tar.gz faenza-icon-theme_1.3.zip Faenza-Radiance.tar.gz
gtk-update-icon-cache /usr/share/icons/Faenza-Radiance/
gtk-update-icon-cache /usr/share/icons/Faenza-Darkest/
gtk-update-icon-cache /usr/share/icons/Faenza-Darker/
gtk-update-icon-cache /usr/share/icons/Faenza-Dark/
gtk-update-icon-cache /usr/share/icons/Faenza/
gtk-update-icon-cache /usr/share/icons/Faenza-Ambiance/ 
# Reconfigure libdvd-pkg for DVD reading / OK
sudo dpkg-reconfigure libdvd-pkg -f noninteractive
# Set background / OK
mkdir -p $(xdg-user-dir PICTURES)/wallpaper
cp -a -r ./config/background/. $(xdg-user-dir PICTURES)/wallpaper
# Install Memo and documentation on Desktop / OK
sudo cp -a -r ./memo/* $(xdg-user-dir DESKTOP)
# Right path to wallpaper / OK
sed -i -e "s/xubuntu/$USER/g" ./config/user1/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml &&
# Install Config User (local, config...) / OK
cp -a -r ./config/user1/.[!.]* $HOME/
# Install Config User (snap firefox) / OK
if [[ $(grep -r '\[Profile[^0]\]' $HOME/snap/firefox/common/.mozilla/firefox/profiles.ini) ]]
then PROFPATH=$(grep -E '^\[Profile|^Path|^Default' $HOME/snap/firefox/common/.mozilla/firefox/profiles.ini | grep -1 '^Default=1' | grep '^Path' | cut -c6-)
else PROFPATH=$(grep 'Path=' $HOME/snap/firefox/common/.mozilla/firefox/profiles.ini | sed 's/^Path=//')
cp -a -r ./config/user1/config_firefox/* $HOME/snap/firefox/common/.mozilla/firefox/$PROFPATH
fi
# No LTS upgrade proposed / OK
sudo sed -i 's/Prompt=lts/Prompt=never/g' /etc/update-manager/release-upgrades
# No apport error / OK
sudo sed -i -e "s/enabled=1/enabled=0/g" /etc/default/apport
# Change swappiness to 10 / OK
sudo sed -i "1i\vm.swappiness=10\n" /etc/sysctl.conf
# Create shortcut Thunar folder (left side) / OK
echo "file://$(xdg-user-dir DOCUMENTS)
file://$(xdg-user-dir PICTURES)
file://$(xdg-user-dir MUSIC)
file://$(xdg-user-dir VIDEOS)
file://$(xdg-user-dir DOWNLOAD)" > ./config/user1/.config/gtk-3.0/bookmarks &&
# Install shortcut Thunar folder (left side) / OK
cp -a ./config/user1/.config/gtk-3.0/bookmarks $HOME/.config/gtk-3.0/ &&
# Delete desktop shortcut if not in english / OK
if grep -F 'XDG_DESKTOP_DIR="$HOME/Desktop"' "$HOME/.config/user-dirs.dirs"; 
then
  echo "English language"
else
    echo
sed -i "\|file:///home/$USER/Desktop|d" $HOME/.config/gtk-3.0/bookmarks
fi
# full-upgrade
sudo apt-get full-upgrade -y
# sleep
sleep 10
# reboot
pkill -KILL -u `whoami`
