#! /bin/sh
#http://pkgs.slitaz.org/search.cgi
#http://www.slitaz.org/fr/doc/releases/3.0/relnotes.fr.html#utf-8
#http://code.google.com/p/burg/wiki/ManualInstall
#http://www.slitaz.org/fr/doc/handbook/livecd.html#home
#http://www.slitaz.org/fr/doc/handbook/openbox.html

#http://hg.slitaz.org/tazpkg/raw-file/tip/doc/tazpkg.fr.html
#tazpkg recharge
#tazpkg upgrade
#tazpkg check
#tazpkg check --full
#tazpkg clean-cache

#var
dossier="/usr/local/share/multisystem"
user_taz="tux"
home_taz="/home/tux"

if [ ! "$(which tazpkg)" ]; then
echo tazpkg?
exit 0
fi

if [ "$USER" != "${user_taz}" ]; then
echo ${user_taz}?
exit 0
fi

if [ ! -d "${home_taz}" ]; then
echo ${home_taz}?
exit 0
fi

if [ "$HOME" != "/root" ]; then
xterm -e "gksu "$0";read"
exit 0
fi

mkdir -p /usr/local/share/
cd /usr/local/share/
wget http://liveusb.info/multisystem/multisystem.tar.bz2
tar xjf ./multisystem.tar.bz2
rm ./multisystem.tar.bz2
cd -

if [ ! -d "/usr/local/share/multisystem" ]; then
exit 0
fi

#chmod 777 /media
if [ "$(stat -c %a /media)" != "777" ]; then
chmod 777 /media
fi

#Recharge la liste des paquets disponibles sur le miroir (packages.list).
tazpkg recharge

#La commande 'upgrade' permet de mettre à jour tous les paquets installés et disponibles sur le miroir courant.
#tazpkg upgrade

#remove
#echo "y" | tazpkg remove sqlite #pas supprimer!
echo "y" | tazpkg remove midori
echo "y" | tazpkg remove beaver
echo "y" | tazpkg remove osmo
echo "y" | tazpkg remove lua
echo "y" | tazpkg remove sudoku-savant
#echo "y" | tazpkg remove mtpaint
echo "y" | tazpkg remove viewnior
echo "y" | tazpkg remove lostirc
echo "y" | tazpkg remove pidgin
echo "y" | tazpkg remove transmission
echo "y" | tazpkg remove mhwaveedit
echo "y" | tazpkg remove alsaplayer
echo "y" | tazpkg remove asunder

#Install
tazpkg get-install sudo
tazpkg get-install bash
#tazpkg get-install zsh #Virer!
tazpkg get-install gettext
tazpkg get-install zenity
tazpkg get-install grub2
tazpkg get-install xdotool
tazpkg get-install wmctrl
tazpkg get-install fuseiso
tazpkg get-install qemu
tazpkg get-install xdg-utils
tazpkg get-install imagemagick
tazpkg get-install mtools
tazpkg get-install dosfstools
tazpkg get-install coreutils
tazpkg get-install cryptsetup
tazpkg get-install rsync
tazpkg get-install lsof
#tazpkg get-install glibc-locale #(see also locale-*).
tazpkg get-install fuse
tazpkg get-install vim
tazpkg get-install sed
tazpkg get-install unzip
tazpkg get-install coreutils-disk
tazpkg get-install gawk
tazpkg get-install procps
tazpkg get-install xorg-xprop
tazpkg get-install syslinux --forced
tazpkg get-install syslinux-extra --forced
tazpkg get-install syslinux-modules
tazpkg get-install syslinux-tools
tazpkg get-install coreutils-command
tazpkg get-install cabextract
tazpkg get-install wget --forced
#commande id
tazpkg get-install coreutils-context-user
#pour commande date +%N
tazpkg get-install coreutils-context-system
#qques ajouts...
tazpkg get-install sakura
tazpkg get-install tilda
#tazpkg get-install xorg-xkill

#rox-filer
tazpkg get-install rox-filer
tazpkg get-install rox-default-icons
tazpkg get-install rox-filer-locales

#Install firefox
tazpkg get-install firefox

#google-chrome
#tazpkg get-install get-google-chrome

#Install cairo-clock
tazpkg get-install cairo
tazpkg get-install cairo-clock
tazpkg get-install cairo-clock-themes

#xpad
tazpkg get-install xpad
#Configurer xpad (message avertissement)
mkdir -p ${home_taz}/.config/xpad/
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/xpad/content-PRRPCV -O ${home_taz}/.config/xpad/content-PRRPCV
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/xpad/info-RSRPCV -O ${home_taz}/.config/xpad/info-RSRPCV
chown ${user_taz}:${user_taz} ${home_taz}/.config/xpad/
chown ${user_taz}:${user_taz} ${home_taz}/.config/xpad/content-PRRPCV
chown ${user_taz}:${user_taz} ${home_taz}/.config/xpad/info-RSRPCV

#Install wicd
tazpkg get-install wicd
tazpkg get-install pygobject
tazpkg get-install libffi
tazpkg get-install pygtk
#Ajouter lancement de daemon wicd
#sed -i "s/network.sh/network.sh wicd/g" /etc/rcS.conf
sed -i "s/dbus hald firewall slim/dbus hald firewall slim wicd/g" /etc/rcS.conf

#Ajouter lien vers liveusb.info
sed -i "s@<strong>SliTaz :</strong>@<strong>SliTaz :</strong>\n\t<a href="http://liveusb.info/dotclear/">WebSite MultiSystem</a> | @g" /usr/share/webhome/index.html
#tous droits pour user qui installe multisystem
if [ ! "$(grep "${user_taz} ALL=NOPASSWD: ALL" /etc/sudoers)" ]; then
echo -e "${user_taz} ALL=NOPASSWD: ALL" | tee -a /etc/sudoers
fi
#Ajouter user ${user_taz} au groupe disk
if [ ! "$(grep "disk:x:3:${user_taz}" /etc/group)" ]; then
sed -i "s/disk:x:3:/disk:x:3:${user_taz}/" /etc/group
fi
#Supprimer ces dépendances pour Slitaz dans multisystem
sed -i "s/gksudo//" ${dossier}/dependances.txt
sed -i "s/apt-get//" ${dossier}/dependances.txt
sed -i "s/fatresize//" ${dossier}/dependances.txt
#rechercher et remplacer mount -l par mount sauf dans update-src.sh
grep 'mount -l' -r ${dossier} | awk -F":" '{print $1}' | uniq | grep -v 'update-src.sh' | tee /tmp/multisystem-mform2-slitaz
cat /tmp/multisystem-mform2-slitaz | while read line
do
sed -i "s@mount -l@mount@g" "$line"
done
rm /tmp/multisystem-mform2-slitaz
#Modifier les echo des input car Slitaz accepte option -e !!! et pas Ubuntu/Debian
echo "" | tee /tmp/multisystem-mform-slitaz
grep '<input>echo ' -r ${dossier} | grep -v ' -e ' | awk -F":" '{print $1}' | uniq | tee /tmp/multisystem-mform-slitaz
cat /tmp/multisystem-mform-slitaz | while read line
do
sed -i "s@<input>echo @<input>echo -e @g" "$line"
done
rm /tmp/multisystem-mform-slitaz
#Ajouter Lanceur de multisystem
mkdir -p /usr/local/share/pixmaps/
cp -f ${dossier}/pixmaps/multisystem-liveusb.png /usr/local/share/pixmaps/multisystem-liveusb.png
cp -f ${dossier}/pixmaps/multisystem-vbox.png /usr/local/share/pixmaps/multisystem-vbox.png
cp -f ${dossier}/launcher/multisystem-liveusb.desktop /usr/share/applications/multisystem-liveusb.desktop
cp -f ${dossier}/launcher/multisystem-vbox.desktop /usr/share/applications/multisystem-vbox.desktop
xdg-desktop-menu install /usr/share/applications/multisystem-liveusb.desktop
xdg-desktop-menu install /usr/share/applications/multisystem-vbox.desktop
xdg-desktop-menu forceupdate --mode user
xdg-desktop-menu forceupdate --mode system
#copier img couleur pour réglages de gurb2
mkdir -p /usr/local/share/pixmaps 2>/dev/null
cp -f ${dossier}/img/*.png /usr/local/share/pixmaps
#Remplacer Icon de Rox-Filer
sed -i 's/Icon=pcmanfm/Icon=multisystem-rox-filer/' /usr/share/applications/rox-filer.desktop
#Copier Icone Rox-Filer
cp -f /usr/local/share/multisystem/pixmaps/multisystem-rox-filer.png /usr/share/pixmaps/multisystem-rox-filer.png
#Changer icone car est trop petite
wget http://liveusb.info/multisystem/slitaz-multisystem/img/media-flash.png -O /usr/share/pixmaps/media-flash.png
sed -i "s@/usr/share/icons/SliTaz/16x16/devices/media-flash.png@/usr/share/pixmaps/media-flash.png@g" /usr/share/applications/mountbox.desktop
#Changer Wallpaper
rm /usr/share/images/slitaz-background.jpg
wget http://liveusb.info/multisystem/slitaz-multisystem/img/slitaz-background.jpg -O /usr/share/images/slitaz-background.jpg
#sudo -u ${user_taz} pcmanfm --set-wallpaper /usr/share/images/slitaz-background.jpg &

#fermer panel
#lxpanelctl exit

#Configurer Tilda
mkdir -p ${home_taz}/.tilda/
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/tilda/config_0 -O ${home_taz}/.tilda/config_0
chown ${user_taz}:${user_taz} ${home_taz}/.tilda/
chown ${user_taz}:${user_taz} ${home_taz}/.tilda/config_0

#Mettre fichier autostart perso openbox
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/openbox/autostart.sh -O ${home_taz}/.config/openbox/autostart.sh
chmod +x ${home_taz}/.config/openbox/autostart.sh
chown ${user_taz}:${user_taz} ${home_taz}/.config/openbox/autostart.sh
#conf de openbox
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/openbox/rc.xml -O ${home_taz}/.config/openbox/rc.xml
chown ${user_taz}:${user_taz} ${home_taz}/.config/openbox/rc.xml
#conf de openbox new user autostart
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/openbox/autostart.sh -O /etc/xdg/openbox/autostart.sh

#panels de lxde
mkdir -p ${home_taz}/.config/lxpanel/default/panels
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/lxpanel/default/panels/bottom -O ${home_taz}/.config/lxpanel/default/panels/bottom
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/lxpanel/default/panels/panel -O ${home_taz}/.config/lxpanel/default/panels/panel
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/lxpanel/default/config -O ${home_taz}/.config/lxpanel/default/config
chown ${user_taz}:${user_taz} ${home_taz}/.config/lxpanel/default/panels/bottom
chown ${user_taz}:${user_taz} ${home_taz}/.config/lxpanel/default/panels/panel
chown ${user_taz}:${user_taz} ${home_taz}/.config/lxpanel/default/config
#lxde defaut ==> /etc/lxpanel/default/panels/panel
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/lxpanel/default/panels/bottom -O /etc/lxpanel/default/panels/bottom
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/lxpanel/default/panels/panel -O /etc/lxpanel/default/panels/panel
wget http://liveusb.info/multisystem/slitaz-multisystem/slitaz.config/lxpanel/default/config -O /etc/lxpanel/default/config

#Installer Grub2 version 1.98
wget http://mirror.slitaz.org/packages/cooking/grub2-1.98.tazpkg -O /tmp/grub2-1.98.tazpkg
tazpkg install /tmp/grub2-1.98.tazpkg --forced
rm /tmp/grub2-1.98.tazpkg*

#fermer panel
lxpanelctl exit

#Ménage
tazpkg clean-cache

#sudo -u ${user_taz} nohup ${dossier}/gui_multisystem.sh&
zenity --info --text "Veuillez relancer la session pour finaliser l'installation\nBouton Fermer la session X"
#zenity --info --text "Please restart the session to finalize the installation\nBouton Log X"
lxsession-logout
echo -e "F.I.N"
exit 0
#▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
