Version 6 des scripts.
Améliorations :
- installation de GRUB (@Josepe : cf mon mail, j'ai utilisé ta méthode, à vérifier svp)
- dialogues de clean_boot_repair, exemple ci-dessous :
#! /bin/bash
## YannUbuntu 21/10/2010 - https://launchpad.net/~yannubuntu - licensed under GNU-GPL v3 (http://www.gnu.org/licenses/gpl.html)
## Special thanks to Josepe36 and all contributors of this thread : http://forum.ubuntu-fr.org/viewtopic.php?pid=3786646
## IMPROVED UBUNTU INSTALLER (clean_ubuntu_installer)
## AUTOMATICALLY SAVES THE 63 ORIGINAL SECTORS OF THE sda DISK, DUPLICATES THE BACKUP INTO SYSTEM PARTITIONS (Windows, Mac & Linux), THEN LAUNCHES UBIQUITY, THEN DUPLICATES THE BACKUP ON THE NEW UBUNTU PARTITION.
## To test this script, you need to execute it (sudo ./clean_ubuntu_installer) from a live-session .
## For a better integration, you can replace the "Install Ubuntu" launcher on the Desktop of the live-CD by this script.
## To be improved : multi-disk support (sdb, sdc..).
## After installation, you can test the "clean_ubuntu_uninstaller" script that allows to perform clean uninstall of any Linux distribution installed via this "clean_ubuntu_installer" script.
## INSTALLATEUR UBUNTU AMELIORÉ
## SAUVE AUTOMATIQUEMENT LES 63 SECTEURS D'ORIGINE DE sda, LE DUPLIQUE DANS LES PARTITIONS contenant un OS (Windows, Mac et Linux), puis lance Ubiquity, puis duplique le backup sur la partition de l'Uubuntu nouvellement installée.
## Pour tester ce script, il suffit de l'exécuter (sudo ./clean_ubuntu_installer) à partir d'une session-live .
## Pour une meilleure intégration, il suffit de remplacer le lanceur "Installation Ubuntu" qui se trouve sur le bureau du live-CD par ce script.
## Améliorations possibles : support du multi-disques (sdb, sdc..).
## Après installation, vous pouvez tester le script "clean_ubuntu_uninstaller" qui permet de désinstaller proprement n'importe-quelle distribution Linux ayant été installée via ce script "clean_ubuntu_installer".
duplicate63sectors(){
##ON DUPLIQUE LE BACKUP DANS LES PARTITIONS SYSTEME de type $TEMP_FILESYSTEM
tab=$(sudo fdisk -l|grep -i "$TEMP_FILESYSTEM"|cut -c1-10) ;
for i in $tab
do
sudo umount $i ;
sudo mount $i /mnt;
folder=$(sudo ls /mnt |grep -i "$TEMP_SYSTEMFOLDER");
if [ "$folder" ]
then control=$(sudo ls /mnt/boot | grep "save-63-sectors.img") ;
if [ "$control" ]
then echo "la partition $i est une partion $TEMP_FILESYSTEM systeme contenant déjà un backup";
else
if [ "$TEMP_SYSTEMFOLDER" != "boot" ];then sudo mkdir /mnt/boot ; fi
sudo dd if=/tmp/save-63-sectors.img of=/mnt/boot/save-63-sectors.img bs=512 count=63 ;
echo "***The 63 sectors have been duplicated into folder /boot of partition $i " ;
QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP+1)) ;
QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP-1)) ;
fi
fi
sudo umount $i ;
done
}
#__________________________________________________________________________________________________________________________________________________________________
save63sectors(){
##BOUCLE DE MONTAGE DES PARTITIONS de type $TEMP_FILESYSTEM, POUR DEFINIR LA PARTITION SYSTEME ET Y INSTALLER UNE SAUVEGARDE Des 63 secteurs
tab=$(sudo fdisk -l|grep -i "$TEMP_FILESYSTEM"|cut -c1-10) ;
for i in $tab
do
sudo umount $i ;
sudo mount $i /mnt;
folder=$(sudo ls /mnt |grep -i "$TEMP_SYSTEMFOLDER");
if [ "$folder" ]; then
if [ "$TEMP_SYSTEMFOLDER" != "boot" ];then sudo mkdir /mnt/boot ; fi
sudo dd if=/dev/sda of=/mnt/boot/save-63-sectors.img bs=512 count=63 ;
echo "***The 63 sectors have been saved into folder /boot of partition $i " ;
QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP+1)) ;
QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP-1)) ;
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP" = "1" ]; then
sudo dd if=/mnt/boot/save-63-sectors.img of=/tmp/save-63-sectors.img bs=512 count=63
fi
fi
sudo umount $i ;
done
}
#__________________________________________________________________________________________________________________________________________________________________
detect_backup(){
tab=$(sudo fdisk -l|grep -i "$TEMP_FILESYSTEM"|cut -c1-10) ;
if [ "$tab" ]; then
echo "voici les partitons $TEMP_FILESYSTEM existantes = $tab" ;
##BOUCLE DE MONTAGE DES PARTITIONS de type $TEMP_FILESYSTEM, DETECTE CELLES QUI SONT PARTITION SYSTEME ET CELLES QUI ONT UNE SAUVEGARDE DES 63 secteurs
for i in $tab
do
sudo umount $i ;
sudo mount $i /mnt;
folder=$(sudo ls /mnt |grep -i "$TEMP_SYSTEMFOLDER");
if [ "$folder" ]; then
control=$(sudo ls /mnt/boot | grep "save-63-sectors.img") ;
if [ "$control" ]
then echo "la partition $i est une partion $TEMP_FILESYSTEM systeme contenant un backup";
QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP+1)) ;
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP" = "1" ]; then
sudo dd if=/mnt/boot/save-63-sectors.img of=/tmp/save-63-sectors.img bs=512 count=63
fi
else echo "la partition $i est une partion $TEMP_FILESYSTEM systeme ne contenant pas de backup";
QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP+1))
fi
fi
sudo umount $i ;
done
else echo "There is no $TEMP_FILESYSTEM partition." ;
fi
}
#__________________________________________________________________________________________________________________________________________________________________
## BEGINNING OF SCRIPT
## CONTROLS IF A BACKUP OF THE 63 FIRST SECTORS ALREADY EXISTS ON THE DISK, IF YES IT IS MEMORIZED IN /tmp.
QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP=0
QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP=0
LINUX_SYSTEM_FOLDER="boot"
HFS_SYSTEM_FOLDER="boot"
NTFS_SYSTEM_FOLDER="Windows"
FAT_SYSTEM_FOLDER="WINDOWS"
TEMP_FILESYSTEM="linux"; TEMP_SYSTEMFOLDER="$LINUX_SYSTEM_FOLDER" #Guess the backup on Linux partition has better reliability (not affected by virus)
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $LIST_OF_PARTITIONS_WITHOUT_BACKUP
TEMP_FILESYSTEM="hfs"; TEMP_SYSTEMFOLDER="$HFS_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $LIST_OF_PARTITIONS_WITHOUT_BACKUP
TEMP_FILESYSTEM="ntfs"; TEMP_SYSTEMFOLDER="$NTFS_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $LIST_OF_PARTITIONS_WITHOUT_BACKUP
TEMP_FILESYSTEM="fat"; TEMP_SYSTEMFOLDER="$FAT_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $LIST_OF_PARTITIONS_WITHOUT_BACKUP
echo "We detected $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP backup(s), et $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP OS without backup."
##IF NO BACKUP HAVE BEEN DETECTED, WE CREATE ONE INTO ALL OS, AND WE ALSO MEMORIZE IT IN /tmp.
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP" = "0" ] && [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP" != "0" ]; then
echo "No backup detected. We will backup the 63 sectors on all existing systems"
##SAUVE DU MBR DANS LES PARTITIONS NTFS (CONTENANT WINDOWS)
TEMP_FILESYSTEM="ntfs"; TEMP_SYSTEMFOLDER="$NTFS_SYSTEM_FOLDER"
save63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
##SAUVE DU MBR DANS LES PARTITIONS FAT (CONTENANT WINDOWS)
TEMP_FILESYSTEM="fat"; TEMP_SYSTEMFOLDER="$FAT_SYSTEM_FOLDER"
save63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
##SAUVE DU MBR DANS LES PARTITIONS HFS (CONTENANT MACOS)
TEMP_FILESYSTEM="hfs"; TEMP_SYSTEMFOLDER="$HFS_SYSTEM_FOLDER"
save63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
##SAUVE DU MBR DANS LES PARTITIONS LINUX (CONTENANT UNE DISTRIBUTION)
TEMP_FILESYSTEM="linux"; TEMP_SYSTEMFOLDER="$LINUX_SYSTEM_FOLDER"
save63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
fi
##IF SOME OS WITHOUT BACKUP REMAIN, WE DUPLICATE THE BACKUP INTO THEM (INCREASES SAFETY)
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP" != "0" ] && [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP" != "0" ]; then
echo "Some OS without backup have been detected. We will duplicate the backup in all of them."
##SAUVE DU MBR DANS LES PARTITIONS NTFS (CONTENANT WINDOWS)
TEMP_FILESYSTEM="ntfs"; TEMP_SYSTEMFOLDER="$NTFS_SYSTEM_FOLDER"
duplicate63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP" != "0" ]; then
##SAUVE DU MBR DANS LES PARTITIONS FAT (CONTENANT WINDOWS)
TEMP_FILESYSTEM="fat"; TEMP_SYSTEMFOLDER="$FAT_SYSTEM_FOLDER"
duplicate63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP" != "0" ]; then
##SAUVE DU MBR DANS LES PARTITIONS HFS (CONTENANT MACOS)
TEMP_FILESYSTEM="hfs"; TEMP_SYSTEMFOLDER="$HFS_SYSTEM_FOLDER"
duplicate63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP" != "0" ]; then
##SAUVE DU MBR DANS LES PARTITIONS LINUX (CONTENANT UNE DISTRIBUTION)
TEMP_FILESYSTEM="linux"; TEMP_SYSTEMFOLDER="$LINUX_SYSTEM_FOLDER"
duplicate63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
fi
fi
fi
fi
echo "Avant de lancer Ubiquity, il y a $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP systèmes d'exploitation avec backup."
##LAUNCH UBIQUITY (same command as the original launcher on the desktop of the live-CD)
ubiquity --desktop %k gtk_ui
echo "Après avoir lancé Ubiquity, il reste $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP backup(s), et $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP systèmes d'exploitation sans backup."
##WE DUPLICATE THE BACKUP INTO THE NEW UBUNTU/LINUX PARTITIONS. (e.g. in case the Windows partition is erased by mistake)
echo "We will duplicate the backup in the new existing Ubuntu/Linux"
TEMP_FILESYSTEM="linux"; TEMP_SYSTEMFOLDER="$LINUX_SYSTEM_FOLDER"
duplicate63sectors $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP
echo "End of script. A backup of the 63 sectors should be present at the root of all existing OS."
exit 0
#! /bin/bash
## YannUbuntu 21/10/2010 - https://launchpad.net/~yannubuntu - licensed under GNU-GPL v3 (http://www.gnu.org/licenses/gpl.html)
## Special thanks to Josepe36 and all contributors of this thread : http://forum.ubuntu-fr.org/viewtopic.php?pid=3786646
## CLEAN REMOVAL OF UBUNTU (clean_ubuntu_uninstaller)
## Allows to perform clean uninstall of any Linux distribution previously installed via the "improved_ubuntu_installer" script.
## To test this script, you need to execute it (sudo ./clean_ubuntu_uninstaller) from a live-session
## For better integration, a launcher can be created e.g. in System->Administration (http://pix.toile-libre.org/?img=1287036329.png), and a "Uninstall Ubuntu" button can also be added to the live-CD welcome screen (http://pix.toile-libre.org/?img=1287036852.png).
## To be improved : display the name/versions of the Linux distros in the menu (http://pix.toile-libre.org/?img=1287037811.png), take into account disks other than sda...
## DESINSTALLATION D'UBUNTU
## Permet de désinstaller proprement n'importe-quelle distribution Linux ayant été installée via le script "improved_ubuntu_installer".
## Pour tester ce script, il suffit de l'exécuter (sudo ./clean_ubuntu_uninstaller) à partir d'une session-live
## Pour une meilleure intégration, un lanceur peut etre créé par ex. dans le menu Systeme->Administration (http://pix.toile-libre.org/?img=1286518777.png), on peut aussi ajouter un bouton "Désinstaller Ubuntu" sur l'écran d'accueil du live-CD (http://pix.toile-libre.org/?img=1286348674.png).
## A améliorer : afficher le nom des distros Linux dans le menu (http://pix.toile-libre.org/?img=1286347844.png), restauration sur disque autre que sda...
detect_backup(){
tab=$(sudo fdisk -l|grep -i "$TEMP_FILESYSTEM"|cut -c1-10) ;
if [ "$tab" ]; then
echo "The existing $TEMP_FILESYSTEM partitions are : $tab" ;
##MOUNTS THE $TEMP_FILESYSTEM PARTITIONS, DETECTS WHICH CONTAIN AN OS, AND WHICH CONTAIN A 63 SECTORS BACKUP
for i in $tab
do
sudo umount $i ;
sudo mount $i /mnt;
folder=$(sudo ls /mnt |grep -i "$TEMP_SYSTEMFOLDER");
if [ "$folder" ]; then
control=$(sudo ls /mnt/$TEMP_SYSTEMFOLDER | grep "save-63-sectors.img") ;
if [ "$control" ]
then echo "$i is a $TEMP_FILESYSTEM partition containing a backup";
QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP+1)) ;
LIST_OF_PARTITIONS_WITH_BACKUP[$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP]=$i
LIST_OF_FOLDERS_WITH_BACKUP[$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP]=$TEMP_SYSTEMFOLDER
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP" = "1" ]; then sudo dd if=/mnt/$TEMP_SYSTEMFOLDER/save-63-sectors.img of=/tmp/save-63-sectors.img bs=512 count=63
fi
else echo "$i is a $TEMP_FILESYSTEM partition without backup";
QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP+1))
fi
##Creates a tab with partitions containing an installation of Linux
if [ "$TEMP_FILESYSTEM" = "linux" ]; then
QUANTITY_OF_DETECTED_LINUX=$(($QUANTITY_OF_DETECTED_LINUX+1))
LIST_OF_EXISTING_LINUX[$QUANTITY_OF_DETECTED_LINUX]="$i"
fi
##Creates a tab with partitions containing an installation of Windows
if [ "$TEMP_FILESYSTEM" = "ntfs" ] || [ "$TEMP_FILESYSTEM" = "fat" ]; then
QUANTITY_OF_DETECTED_WINDOWS=$(($QUANTITY_OF_DETECTED_WINDOWS+1))
fi
##Creates a tab with partitions containing an installation of MacOS
if [ "$TEMP_FILESYSTEM" = "hfs" ] ; then
QUANTITY_OF_DETECTED_MACOS=$(($QUANTITY_OF_DETECTED_MACOS+1))
fi
fi
sudo umount $i ;
done
else echo "There is no $TEMP_FILESYSTEM partition" ;
fi
}
#__________________________________________________________________________________________________________________________________________________________________
### MAIN MENU
uninstall_linux()
{
## CONTROLS IF A BACKUP OF THE 63 FIRST SECTORS ALREADY EXISTS ON THE DISK, IF YES IT IS MEMORIZED IN /tmp. ALSO COUNTS THE QUANTITY OF OS.
QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP=0
QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP=0
QUANTITY_OF_DETECTED_LINUX=0
QUANTITY_OF_DETECTED_WINDOWS=0
QUANTITY_OF_DETECTED_MACOS=0
LINUX_SYSTEM_FOLDER="boot"
HFS_SYSTEM_FOLDER="boot"
NTFS_SYSTEM_FOLDER="Windows"
FAT_SYSTEM_FOLDER="WINDOWS"
echo "10"
TEMP_FILESYSTEM="linux"; TEMP_SYSTEMFOLDER="$LINUX_SYSTEM_FOLDER" #I put Linux first because I guess the backups on Linux partitions have better reliability (not affected by virus)
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $QUANTITY_OF_DETECTED_LINUX $LIST_OF_EXISTING_LINUX $LIST_OF_PARTITIONS_WITH_BACKUP $LIST_OF_FOLDERS_WITH_BACKUP
##IF NO LINUX HAVE BEEN DETECTED
if [ "$QUANTITY_OF_DETECTED_LINUX" = "0" ]; then
echo "100"
if [ "$language" = "English" ]; then
zenity --error --text="No Linux installation has been found on this computer."
else
zenity --error --text="Aucune installation Linux n'a été détectée sur cet ordinateur."
fi
##IF MINIMUM ONE LINUX HAS BEEN DETECTED
else
echo "30"
TEMP_FILESYSTEM="hfs"; TEMP_SYSTEMFOLDER="$HFS_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $QUANTITY_OF_DETECTED_MACOS $LIST_OF_PARTITIONS_WITH_BACKUP $LIST_OF_FOLDERS_WITH_BACKUP
echo "60"
TEMP_FILESYSTEM="ntfs"; TEMP_SYSTEMFOLDER="$NTFS_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $QUANTITY_OF_DETECTED_WINDOWS $LIST_OF_PARTITIONS_WITH_BACKUP $LIST_OF_FOLDERS_WITH_BACKUP
echo "80"
TEMP_FILESYSTEM="fat"; TEMP_SYSTEMFOLDER="$FAT_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $QUANTITY_OF_DETECTED_WINDOWS $LIST_OF_PARTITIONS_WITH_BACKUP $LIST_OF_FOLDERS_WITH_BACKUP
echo "100" #Closes the progress indication dialog (for safety purpose we need to prevent the user from cancelling in the middle of removal operations)
echo "We detected $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP backup(s), et $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP OS without backup."
echo "We detected $QUANTITY_OF_DETECTED_LINUX Linux distribution(s), $QUANTITY_OF_DETECTED_MACOS MacOS, and $QUANTITY_OF_DETECTED_WINDOWS Windows."
##IF ONLY ONE LINUX HAS BEEN DETECTED, THEN WE RESTORE THE 63 ORIGINAL SECTORS
if [ "$QUANTITY_OF_DETECTED_LINUX" = "1" ]
then
##IF NO BACKUP HAVE BEEN DETECTED
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP" = "0" ]; then
##Dual-boot Linux-Windows
if [ "$QUANTITY_OF_DETECTED_WINDOWS" != "0" ]; then
if [ "$language" = "English" ]; then
zenity --info --title="Automatic removal is impossible" --text="There is no boot backup on this computer. To uninstall Ubuntu, it is recommended to delete the Ubuntu partition then reinstall a Windows bootloader (with a Windows repair CD for example). It is a non-trivial and risky manipulation, so please backup your data before doing it."
else
zenity --info --title="Impossible de désinstaller automatiquement" --text="Il n'existe pas de sauvegarde d'amorcage sur cet ordinateur. Pour désinstaller Ubuntu, il est recommandé d'effacer la partition Ubuntu puis réinstaller un amorceur Windows (avec un CD de réparation Windows par exemple). Il s'agit d'une manipulation non-triviale et risquée, donc pensez à sauver vos données auparavant."
fi
##Dual-boot Linux-MacOS
elif [ "$QUANTITY_OF_DETECTED_MACOS" != "0" ]; then
if [ "$language" = "English" ]; then
zenity --info --title="Automatic removal is impossible" --text="There is no boot backup on this computer. To uninstall Ubuntu, it is recommended to delete the Ubuntu partition then reinstall a MacOS bootloader (with a MacOS repair CD for example). It is a non-trivial and risky manipulation, so please backup your data before doing it."
else
zenity --info --title="Impossible de désinstaller automatiquement" --text="Il n'existe pas de sauvegarde d'amorcage sur cet ordinateur. Pour désinstaller Ubuntu, il est recommandé d'effacer la partition Ubuntu puis réinstaller un amorceur MacOS (avec un CD de réparation MacOS par exemple). Il s'agit d'une manipulation non-triviale et risquée, donc pensez à sauver vos données auparavant."
fi
else
##The disk contains only one OS (Linux)
if [ "$language" = "English" ]; then
zenity --info --title="Automatic removal is impossible" --text="There is no other operating system nor boot backup on this computer. You can uninstall Ubuntu by deleting its partition, but then your computer won't have any operating system any more."
else
zenity --info --title="Impossible de désinstaller automatiquement" --text="Il n'existe pas d'autre système d'exploitation, ni de sauvegarde d'amorcage sur cet ordinateur. Vous pouvez désinstaller Ubuntu en effacant sa partition, mais votre ordinateur n'aura alors plus de système d'exploitation pour le faire fonctionner."
fi
fi
##IF MINIMUM ONE BACKUP HAS BEEN DETECTED
else
##Dual-boot Linux-Windows
if [ "$QUANTITY_OF_DETECTED_WINDOWS" != "0" ]; then
if [ "$language" = "English" ]; then
zenity --question --title="Are you sure you want to uninstall Ubuntu ?" --text="This will delete Ubuntu and restore the initial boot sector of your computer, thus giving back access to Windows only. All your data in Ubuntu will be lost. Do you want to continue ?" || exit 101;
else
zenity --question --title="Etes-vous sûr de vouloir désinstaller Ubuntu ?" --text="Ceci effacera Ubuntu et restaurera l'amorcage initial de votre ordinateur, vous redonnant accès à Windows uniquement. Attention, toutes vos données contenues dans Ubuntu seront effacées. Souhaitez-vous continuer ?" || exit 101;
fi
##Dual-boot Linux-MacOS
elif [ "$QUANTITY_OF_DETECTED_MACOS" != "0" ]; then
if [ "$language" = "English" ]; then
zenity --question --title="Are you sure you want to uninstall Ubuntu ?" --text="This will delete Ubuntu and restore the initial boot sector of your computer, thus giving back access to MacOS only. All your data in Ubuntu will be lost. Do you want to continue ?" || exit 101;
else
zenity --question --title="Etes-vous sûr de vouloir désinstaller Ubuntu ?" --text="Ceci effacera Ubuntu et restaurera l'amorcage initial de votre ordinateur, vous redonnant accès à MacOS uniquement. Attention, toutes vos données contenues dans Ubuntu seront effacées. Souhaitez-vous continuer ?" || exit 101;
fi
else
##The disk contains only one OS (Linux)
if [ "$language" = "English" ]; then
zenity --question --title="Are you sure you want to uninstall Ubuntu ?" --text="There is no other operating system on this computer. If you continue, Ubuntu will be deleted and the initial boot sector will be restored. This can sometimes be usefull to facilitate the reinstallation of the original operating system. All your data in Ubuntu will be lost, and your computer won't have any operating system any more. Do you want to continue ?" || exit 101;
else
zenity --question --title="Etes-vous sûr de vouloir désinstaller Ubuntu ?" --text="Il n'existe pas d'autre système d'exploitation sur cet ordinateur. Si vous continuez, Ubuntu sera effacé et l'amorcage initial de votre ordinateur sera restauré. Ceci peut parfois faciliter la réinstallation de l'OS original. Attention, toutes vos données contenues dans Ubuntu seront effacées et votre ordinateur n'aura alors plus de système d'exploitation pour le faire fonctionner. Souhaitez-vous continuer ?" || exit 101;
fi
fi
## RESTORES THE FIRST BACKUP DETECTED ON THE DISK
### saves temporarily the current first sector (in order to restore the current partition table just after)
sudo dd if=/dev/sda of=/tmp/backup_of_current_first_sector.img bs=512 count=1 ;
### restores the boot backup in the 63 first sectors
sudo dd if=/tmp/save-63-sectors.img of=/dev/sda bs=512 count=63 ;
### restores the current partition table
sudo dd if=/tmp/backup_of_current_first_sector.img of=/dev/sda bs=1 skip=446 count=64
## Renames all the backups (in order to avoid interferences with next Ubuntu installation, while keeping it in case of trouble or for test purpose)
i=1; while [ "$i" != "$(($QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP+1))" ]; do
sudo umount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} ;
sudo mount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} /mnt;
sudo mv /mnt/${LIST_OF_FOLDERS_WITH_BACKUP[$i]}/save-63-sectors.img /mnt/${LIST_OF_FOLDERS_WITH_BACKUP[$i]}/sav63sectors_old.img
sudo umount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} ;
i=$(($i+1));
done;
##Erases the partition chosen by the user
sudo umount ${LIST_OF_EXISTING_LINUX[1]} ;
sudo mount ${LIST_OF_EXISTING_LINUX[1]} /mnt;
sudo rm -r /mnt/*
sudo umount ${LIST_OF_EXISTING_LINUX[1]} ;
if [ "$language" = "English" ]; then
zenity --info --title="Ubuntu has been successfully uninstalled" --text="Thank you for trying Ubuntu, see you soon !"
else
zenity --info --title="Ubuntu a été correctement desinstallé" --text="Merci d'avoir essayé Ubuntu, et à bientôt !"
fi
fi
##IF SEVERAL LINUX HAVE BEEN DETECTED, THEN WE ASK THE USER TO CHOSE ONE, WE DELETE IT AND WE REINSTALL GRUB ON ANOTHER REMAINING DISTRIBUTION
else
i=1; while [ "$i" != "$(($QUANTITY_OF_DETECTED_LINUX+1))" ]; do
TAB="$TAB ${LIST_OF_EXISTING_LINUX[$i]}";
i=$(($i+1));
done;
if [ "$language" = "English" ]; then
choice=$(zenity --list --title="Removal of Ubuntu" --text="Which Linux distribution do you want to uninstall ?" --column="" $TAB) || exit 102;
else
choice=$(zenity --list --title="Désinstallation d'Ubuntu" --text="Quelle distribution Linux souhaitez-vous desinstaller ?" --column="" $TAB) || exit 102;
fi
## If we uninstall the first distribution of the list, we reinstall GRUB into the 2nd one
if [ "$choice" = "${LIST_OF_EXISTING_LINUX[1]}" ];then
##Erases the partition chosen by the user
sudo umount ${LIST_OF_EXISTING_LINUX[1]} ;
sudo mount ${LIST_OF_EXISTING_LINUX[1]} /mnt;
sudo rm -r /mnt/*
sudo umount ${LIST_OF_EXISTING_LINUX[1]} ;
##Reinstalls GRUB into the 2nd Linux partition
sudo mount ${LIST_OF_EXISTING_LINUX[2]} /mnt;
for j in "dev" "proc" "sys" ; do sudo mount --bind /$j /mnt/$j;done
sudo chroot /mnt <<EOF
sudo update-grub
sudo grub-install /dev/sda
exit
EOF
sudo umount /mnt/dev /mnt/proc /mnt/sys
sudo umount ${LIST_OF_EXISTING_LINUX[2]}
if [ "$language" = "English" ]; then
zenity --info --title="Ubuntu has been successfully uninstalled" --text="Ubuntu has been successfully removed, and Grub has been reinstalled into ${LIST_OF_EXISTING_LINUX[2]}. Thank you for trying Ubuntu, see you soon !"
else
zenity --info --title="Ubuntu a été correctement desinstallé" --text="Ubuntu a été correctement desinstallé, et Grub a été réinstallé dans ${LIST_OF_EXISTING_LINUX[2]}. Merci d'avoir essayé Ubuntu, et à bientot !"
fi
else
##If we uninstall the 2nd (or 3rd or 4th..) distribution of the list, we reinstall GRUB into the 1st one
##Erases the partition chosen by the user
sudo umount $choice ;
sudo mount $choice /mnt;
sudo rm -r /mnt/*
sudo umount $choice ;
##Reinstalls GRUB into the 1st Linux partition
sudo mount ${LIST_OF_EXISTING_LINUX[1]} /mnt;
for j in "dev" "proc" "sys" ; do sudo mount --bind /$j /mnt/$j;done
sudo chroot /mnt <<EOF
sudo update-grub
sudo grub-install /dev/sda
exit
EOF
sudo umount /mnt/dev /mnt/proc /mnt/sys
sudo umount ${LIST_OF_EXISTING_LINUX[1]}
if [ "$language" = "English" ]; then
zenity --info --title="Ubuntu has been successfully uninstalled" --text="Ubuntu has been successfully removed, and Grub has been reinstalled into ${LIST_OF_EXISTING_LINUX[1]}. Thank you for trying Ubuntu, see you soon !"
else
zenity --info --title="Ubuntu a été correctement desinstallé" --text="Ubuntu a été correctement desinstallé, et Grub a été réinstallé dans ${LIST_OF_EXISTING_LINUX[1]}. Merci d'avoir essayé Ubuntu, et à bientot !"
fi
fi
fi
fi
}
#___________________________________________________________________________________________________________________________________________________________________
## BEGINNING OF SCRIPT
### LANGUAGE MENU
language=$(zenity --list --title="English / French ?" --text="This is a temporary menu. For testing purpose only." --column="" "English" "Français") || exit 102;
if [ "$language" = "English" ]; then
( uninstall_linux $language ) | zenity --progress --auto-close --title="Welcome" --text="Scanning systems" --percentage=0
else
( uninstall_linux $language ) | zenity --progress --auto-close --title="Bienvenue" --text="Détection des systèmes" --percentage=0
fi
echo "End of script."
exit 0
#! /bin/bash
## YannUbuntu 21/10/2010 - https://launchpad.net/~yannubuntu - licensed under GNU-GPL v3 (http://www.gnu.org/licenses/gpl.html)
## Special thanks to Josepe36 and all contributors of this thread : http://forum.ubuntu-fr.org/viewtopic.php?pid=3786646
## CLEAN BOOT REPAIR
## Allows to restore the initial boot sector or repair the GRUB of any Linux distribution previously installed via the "improved_ubuntu_installer" script.
## To test this script, you need to execute it (sudo ./clean_grub_repair) from a live-session
## For better integration, a launcher can be created e.g. in System->Administration, and a "Boot repair" button can also be added to the live-CD welcome screen.
## To be improved : take into account disks other than sda...
## REPARATEUR D'AMORCAGE
## Permet de restaurer l'amorcage initial ou réparer le GRUB de n'importe-quelle distribution Linux ayant été installée via le script "improved_ubuntu_installer".
## Pour tester ce script, il suffit de l'exécuter (sudo ./clean_grub_repair) à partir d'une session-live
## Pour une meilleure intégration, un lanceur peut etre créé par ex. dans le menu Systeme->Administration, on peut aussi ajouter un bouton "Réparer l'amorcage" sur l'écran d'accueil du live-CD.
## A améliorer : restauration sur disque autre que sda...
detect_backup(){
tab=$(sudo fdisk -l|grep -i "$TEMP_FILESYSTEM"|cut -c1-10) ;
if [ "$tab" ]; then
echo "The existing $TEMP_FILESYSTEM partitions are : $tab" ;
##MOUNTS THE $TEMP_FILESYSTEM PARTITIONS, DETECTS WHICH CONTAIN AN OS, AND WHICH CONTAIN A 63 SECTORS BACKUP
for i in $tab
do
sudo umount $i ;
sudo mount $i /mnt;
folder=$(sudo ls /mnt |grep -i "$TEMP_SYSTEMFOLDER");
if [ "$folder" ]; then
control=$(sudo ls /mnt/boot | grep "save-63-sectors.img") ;
if [ "$control" ]
then echo "$i is a $TEMP_FILESYSTEM partition containing a backup";
QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP+1)) ;
LIST_OF_PARTITIONS_WITH_BACKUP[$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP]=$i
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP" = "1" ]; then
sudo dd if=/mnt/boot/save-63-sectors.img of=/tmp/save-63-sectors.img bs=512 count=63
fi
else echo "$i is a $TEMP_FILESYSTEM partition without backup";
QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP=$(($QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP+1))
fi
##Creates a tab with partitions containing an installation of Linux
if [ "$TEMP_FILESYSTEM" = "linux" ]; then
QUANTITY_OF_DETECTED_LINUX=$(($QUANTITY_OF_DETECTED_LINUX+1))
LIST_OF_EXISTING_LINUX[$QUANTITY_OF_DETECTED_LINUX]="$i"
fi
##Creates a tab with partitions containing an installation of Windows
if [ "$TEMP_FILESYSTEM" = "ntfs" ] || [ "$TEMP_FILESYSTEM" = "fat" ]; then
QUANTITY_OF_DETECTED_WINDOWS=$(($QUANTITY_OF_DETECTED_WINDOWS+1))
fi
##Creates a tab with partitions containing an installation of MacOS
if [ "$TEMP_FILESYSTEM" = "hfs" ] ; then
QUANTITY_OF_DETECTED_MACOS=$(($QUANTITY_OF_DETECTED_MACOS+1))
fi
fi
sudo umount $i ;
done
else echo "There is no $TEMP_FILESYSTEM partition" ;
fi
}
#__________________________________________________________________________________________________________________________________________________________________
### MAIN MENU
uninstall_linux()
{
## CONTROLS IF A BACKUP OF THE 63 FIRST SECTORS ALREADY EXISTS ON THE DISK, IF YES IT IS MEMORIZED IN /tmp. ALSO COUNTS THE QUANTITY OF OS.
QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP=0
QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP=0
QUANTITY_OF_DETECTED_LINUX=0
QUANTITY_OF_DETECTED_WINDOWS=0
QUANTITY_OF_DETECTED_MACOS=0
LINUX_SYSTEM_FOLDER="boot"
HFS_SYSTEM_FOLDER="boot"
NTFS_SYSTEM_FOLDER="Windows"
FAT_SYSTEM_FOLDER="WINDOWS"
echo "10"
TEMP_FILESYSTEM="linux"; TEMP_SYSTEMFOLDER="$LINUX_SYSTEM_FOLDER" #I put Linux first because I guess the backups on Linux partitions have better reliability (not affected by virus)
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $QUANTITY_OF_DETECTED_LINUX $LIST_OF_EXISTING_LINUX $LIST_OF_PARTITIONS_WITH_BACKUP
echo "30"
TEMP_FILESYSTEM="hfs"; TEMP_SYSTEMFOLDER="$HFS_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $QUANTITY_OF_DETECTED_MACOS $LIST_OF_PARTITIONS_WITH_BACKUP
echo "60"
TEMP_FILESYSTEM="ntfs"; TEMP_SYSTEMFOLDER="$NTFS_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $QUANTITY_OF_DETECTED_WINDOWS $LIST_OF_PARTITIONS_WITH_BACKUP
echo "80"
TEMP_FILESYSTEM="fat"; TEMP_SYSTEMFOLDER="$FAT_SYSTEM_FOLDER"
detect_backup $TEMP_FILESYSTEM $TEMP_SYSTEMFOLDER $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP $QUANTITY_OF_DETECTED_WINDOWS $LIST_OF_PARTITIONS_WITH_BACKUP
echo "100" #Closes the progress indication dialog (for safety purpose we need to prevent the user from cancelling in the middle of removal operations)
echo "We detected $QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP backup(s), et $QUANTITY_OF_DETECTED_SYSTEMS_WITHOUT_BACKUP OS without backup."
echo "We detected $QUANTITY_OF_DETECTED_LINUX Linux distribution(s), $QUANTITY_OF_DETECTED_MACOS MacOS, and $QUANTITY_OF_DETECTED_WINDOWS Windows."
##IF NO BACKUP HAVE BEEN DETECTED
if [ "$QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP" = "0" ]; then
##Dual-boot Linux-Windows
if [ "$QUANTITY_OF_DETECTED_WINDOWS" != "0" ]; then
if [ "$language" = "English" ]; then
zenity --info --title="Automatic repair is impossible" --text="There is no boot backup on this computer. To repair your boot sector, it is recommended to use a Windows repair CD for example. It is a non-trivial and risky manipulation, so please backup your data before doing it."
else
zenity --info --title="Impossible de réparer automatiquement" --text="Il n'existe pas de sauvegarde d'amorcage sur cet ordinateur. Pour désinstaller Ubuntu, il est recommandé d'effacer la partition Ubuntu puis réinstaller un amorceur Windows (avec un CD de réparation Windows par exemple). Il s'agit d'une manipulation non-triviale et risquée, donc pensez à sauver vos données auparavant."
fi
##Dual-boot Linux-MacOS
elif [ "$QUANTITY_OF_DETECTED_MACOS" != "0" ]; then
if [ "$language" = "English" ]; then
zenity --info --title="Automatic repair is impossible" --text="There is no boot backup on this computer. To repair your boot sector, it is recommended to use a MacOS repair CD for example. It is a non-trivial and risky manipulation, so please backup your data before doing it."
else
zenity --info --title="Impossible de réparer automatiquement" --text="Il n'existe pas de sauvegarde d'amorcage sur cet ordinateur. Pour désinstaller Ubuntu, il est recommandé d'effacer la partition Ubuntu puis réinstaller un amorceur MacOS (avec un CD de réparation MacOS par exemple). Il s'agit d'une manipulation non-triviale et risquée, donc pensez à sauver vos données auparavant."
fi
else
##The disk contains only one OS (Linux)
if [ "$language" = "English" ]; then
##Reinstalls GRUB into the 1st Linux partition
sudo mount ${LIST_OF_EXISTING_LINUX[1]} /mnt;
for j in "dev" "proc" "sys" ; do sudo mount --bind /$j /mnt/$j;done
sudo chroot /mnt <<EOF
sudo update-grub
sudo grub-install /dev/sda
exit
EOF
sudo umount /mnt/dev /mnt/proc /mnt/sys
sudo umount ${LIST_OF_EXISTING_LINUX[1]}
if [ "$language" = "English" ]; then
zenity --info --title="Your boot sector has been successfully repaired" --text="Grub has been successfully reinstalled into ${LIST_OF_EXISTING_LINUX[1]}. Thank you and see you soon !"
else
zenity --info --title="Votre secteur d'amorcage a été correctement réparé" --text="GRUB a été correctement reinsinstallé dans ${LIST_OF_EXISTING_LINUX[1]}. Merci et à bientot !"
fi
fi
fi
##IF MINIMUM ONE BACKUP HAS BEEN DETECTED, WE PROPOSE TO RESTORE THE BACKUP AND OPTIONNALY TO REINSTALL GRUB
else
##IF NO LINUX WAS DETECTED (was deleted by mistake for example), WE ONLY PROPOSE TO RESTORE THE BACKUP
if [ "$QUANTITY_OF_DETECTED_LINUX" = "0" ]; then
if [ "$QUANTITY_OF_DETECTED_WINDOWS" != "0" ]; then
if [ "$language" = "English" ]; then
zenity --question --title="Are you sure you want to repair your boot sector ?" --text="This will restore the Windows boot sector that was on your computer before installing Ubuntu. Do you want to continue ?" || exit 101;
else
zenity --question --title="Etes-vous sûr de vouloir réparer votre amorcage ?" --text="Ceci restaurera l'amorcage Winsows qui se trouvait sur votre ordinateur avant l'installation d'Ubuntu. Souhaitez-vous continuer ?" || exit 101;
fi
##Dual-boot Linux-MacOS
elif [ "$QUANTITY_OF_DETECTED_MACOS" != "0" ]; then
if [ "$language" = "English" ]; then
zenity --question --title="Are you sure you want to repair your boot sector ?" --text="This will restore the MacOS boot sector that was on your computer before installing Ubuntu. Do you want to continue ?" || exit 101;
else
zenity --question --title="Etes-vous sûr de vouloir réparer votre amorcage ?" --text="Ceci restaurera l'amorcage MacOS qui se trouvait sur votre ordinateur avant l'installation d'Ubuntu. Souhaitez-vous continuer ?" || exit 101; exit 101;
fi
else
if [ "$language" = "English" ]; then
zenity --question --title="Are you sure you want to repair your boot sector ?" --text="This will restore the boot sector that was on your computer before installing Ubuntu. Do you want to continue ?" || exit 101;
else
zenity --question --title="Etes-vous sûr de vouloir réparer votre amorcage ?" --text="Ceci restaurera l'amorcage qui se trouvait sur votre ordinateur avant l'installation d'Ubuntu. Souhaitez-vous continuer ?" || exit 101; exit 101;
fi
fi
## RESTORES THE FIRST BACKUP DETECTED ON THE DISK
### saves temporarily the current first sector (in order to restore the current partition table just after)
sudo dd if=/dev/sda of=/tmp/backup_of_current_first_sector.img bs=512 count=1 ;
### restores the boot backup in the 63 first sectors
sudo dd if=/tmp/save-63-sectors.img of=/dev/sda bs=512 count=63 ;
### restores the current partition table
sudo dd if=/tmp/backup_of_current_first_sector.img of=/dev/sda bs=1 skip=446 count=64
## Renames all the backups (in order to avoid interferences with next Ubuntu installation, while keeping it in case of trouble or for test purpose)
i=1; while [ "$i" != "$(($QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP+1))" ]; do
sudo umount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} ;
sudo mount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} /mnt;
sudo mv /mnt/boot/save-63-sectors.img /mnt/boot/sav63sectors_old.img
sudo umount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} ;
i=$(($i+1));
done;
##IF MINIMUM ONE LINUX HAS BEEN DETECTED, WE PROPOSE TO RESTORE THE BACKUP AND OPTIONNALY TO REINSTALL GRUB
else
if [ "$QUANTITY_OF_DETECTED_WINDOWS" != "0" ]; then
if [ "$language" = "English" ]; then
choice=$(zenity --list --title="Repair of the boot sector" --text="Please read carefully :\n
- if you cannot start any operating system after running Windows (this happens generally when
a Windows software installs an anti-copy protection in the boot sector), restoring GRUB should
restore access to all your operating systems (Windows, Ubuntu..).
- if Windows does not start any more since Ubuntu's installation, or if you cannot start any
operating system since Ubuntu's installation (this happens generally when the computer is locked
with Windows), you can restore the boot sector you had before installing Ubuntu. Ubuntu won't be
accessible any more until you install a bootloader.\n
What do you want to do ?" --column="" "Restore GRUB bootloader." "Restore the pre-Ubuntu boot sector." ) || exit 102;
else
choice=$(zenity --list --title="Réparation de l'amorcage" --text="Lisez attentivement svp :\n
- si vous ne pouvez plus démarrer aucun système d'exploitation après avoir utilisé Windows (cela survient généralement
quand un logiciel Windows installe une protection anti-copie dans le secteur d'amorcage, restaurer GRUB devrait restaurer
l'accès à tous vos systèmes d'exploitation.
- si depuis que vous avez installé Ubuntu vous ne pouvez plus démarrer Windows ou bien plus démarrer aucun système
d'exploitation (cela survient généralement quand l'ordinateur est tatoué), vous pouvez restaurer le secteur d'amorcage
d'avant l'installation d'Ubuntu. Ubuntu ne sera plus accessible tant que vous n'aurez pas installé un amorceur.\n
Que souhaitez-vous faire ?" --column="" "Restaurer l'amorceur GRUB." "Restaurer l'amorcage pré-Ubuntu.") || exit 102;
fi
elif [ "$QUANTITY_OF_DETECTED_MACOS" != "0" ]; then
if [ "$language" = "English" ]; then
choice=$(zenity --list --title="Repair of the boot sector" --text="Please read carefully :\n
- if you cannot start any operating system after running MacOS (this happens generally when
a MacOS software installs an anti-copy protection in the boot sector), restoring GRUB should
restore access to all your operating systems (MacOS, Ubuntu..).
- if MacOS does not start any more since Ubuntu's installation, or if you cannot start any
operating system since Ubuntu's installation (this happens generally when the computer is locked
with MacOS), you can restore the boot sector you had before installing Ubuntu. Ubuntu won't be
accessible any more until you install a bootloader.\n
What do you want to do ?" --column="" "Restore GRUB bootloader." "Restore the pre-Ubuntu boot sector." ) || exit 102;
else
choice=$(zenity --list --title="Réparation de l'amorcage" --text="Lisez attentivement svp :\n
- si vous ne pouvez plus démarrer aucun système d'exploitation après avoir utilisé MacOS (cela survient généralement
quand un logiciel MacOS installe une protection anti-copie dans le secteur d'amorcage, restaurer GRUB devrait restaurer
l'accès à tous vos systèmes d'exploitation.
- si depuis que vous avez installé Ubuntu vous ne pouvez plus démarrer MacOS ou bien plus démarrer aucun système
d'exploitation (cela survient généralement quand l'ordinateur est tatoué), vous pouvez restaurer le secteur d'amorcage
d'avant l'installation d'Ubuntu. Ubuntu ne sera plus accessible tant que vous n'aurez pas installé un amorceur.\n
Que souhaitez-vous faire ?" --column="" "Restaurer l'amorceur GRUB." "Restaurer l'amorcage pré-Ubuntu.") || exit 102;
fi
else
if [ "$language" = "English" ]; then
choice=$(zenity --list --title="Repair of the boot sector" --text="Please read carefully :\n
- if you cannot start any operating system after running your other OS (this happens generally when
a non-free software installs an anti-copy protection in the boot sector), restoring GRUB should
restore access to all your operating systems.
- if your other operating system does not start any more since Ubuntu's installation, or if you cannot
start any operating system since Ubuntu's installation (this happens generally when the computer is locked
with an OS), you can restore the boot sector you had before installing Ubuntu. Ubuntu won't be
accessible any more until you install a bootloader.\n
What do you want to do ?" --column="" "Restore GRUB bootloader." "Restore the pre-Ubuntu boot sector." ) || exit 102;
else
choice=$(zenity --list --title="Réparation de l'amorcage" --text="Lisez attentivement svp :\n
- si vous ne pouvez plus démarrer aucun système d'exploitation après avoir utilisé votre autre OS (cela survient généralement
quand un logiciel non-libre installe une protection anti-copie dans le secteur d'amorcage, restaurer GRUB devrait restaurer
l'accès à tous vos systèmes d'exploitation.
- si depuis que vous avez installé Ubuntu vous ne pouvez plus démarrer votre autre OS ou bien plus démarrer aucun système
d'exploitation (cela survient généralement quand l'ordinateur est tatoué), vous pouvez restaurer le secteur d'amorcage
d'avant l'installation d'Ubuntu. Ubuntu ne sera plus accessible tant que vous n'aurez pas installé un amorceur.\n
Que souhaitez-vous faire ?" --column="" "Restaurer l'amorceur GRUB." "Restaurer l'amorcage pré-Ubuntu.") || exit 102;
fi
fi
## RESTORES THE FIRST BACKUP DETECTED ON THE DISK
### saves temporarily the current first sector (in order to restore the current partition table just after)
sudo dd if=/dev/sda of=/tmp/backup_of_current_first_sector.img bs=512 count=1 ;
### restores the boot backup in the 63 first sectors
sudo dd if=/tmp/save-63-sectors.img of=/dev/sda bs=512 count=63 ;
### restores the current partition table
sudo dd if=/tmp/backup_of_current_first_sector.img of=/dev/sda bs=1 skip=446 count=64
if [ "$choice" = "Restore the boot sector then reinstall GRUB. Should restore access to all your current operating systems. Recommended if your boot sector has been broken by another OS." ] || [ "$choice" = "Restaure l'amorcage puis reinstalle GRUB. Devrait restaurer l'accès à tous vos OS actuels. Recommendé si votre amorcage a été endommagé par un autre OS." ];then
##Reinstalls GRUB into the 1st Linux partition
sudo mount ${LIST_OF_EXISTING_LINUX[1]} /mnt;
sudo grub-install --root-directory=/mnt /dev/sda
sudo umount ${LIST_OF_EXISTING_LINUX[1]}
if [ "$language" = "English" ]; then
zenity --info --title="Your boot sector has been successfully repaired" --text="Grub has been reinstalled into ${LIST_OF_EXISTING_LINUX[1]}. Thank you and see you soon !"
else
zenity --info --title="Votre secteur d'amorcage a été réparé avec succès" --text="GRUB a été correctement reinsinstallé dans ${LIST_OF_EXISTING_LINUX[1]}. Merci et à bientot !"
fi
else
## Renames all the backups (in order to avoid interferences with next Ubuntu installation, while keeping it in case of trouble or for test purpose)
i=1; while [ "$i" != "$(($QUANTITY_OF_DETECTED_SYSTEMS_WITH_BACKUP+1))" ]; do
sudo umount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} ;
sudo mount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} /mnt;
sudo mv /mnt/boot/save-63-sectors.img /mnt/boot/sav63sectors_old.img
sudo umount ${LIST_OF_PARTITIONS_WITH_BACKUP[$i]} ;
i=$(($i+1));
done;
if [ "$language" = "English" ]; then
zenity --info --title="Your boot sector has been successfully restored" --text="Thank you for trying Ubuntu, see you soon !"
else
zenity --info --title="Votre secteur d'amorcage a été restauré avec succès" --text="Merci d'avoir essayé Ubuntu, et à bientôt !"
fi
fi
fi
fi
}
#___________________________________________________________________________________________________________________________________________________________________
## BEGINNING OF SCRIPT
### LANGUAGE MENU
language=$(zenity --list --title="English / French ?" --text="This is a temporary menu. For testing purpose only." --column="" "English" "Français") || exit 102;
if [ "$language" = "English" ]; then
( uninstall_linux $language ) | zenity --progress --auto-close --title="Welcome" --text="Scanning systems" --percentage=0
else
( uninstall_linux $language ) | zenity --progress --auto-close --title="Bienvenue" --text="Détection des systèmes" --percentage=0
fi
echo "End of script."
exit 0