185 lines
3.6 KiB
Bash
Executable File
185 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
#MENU Linux Image Disk
|
|
|
|
#pres requis:
|
|
#root
|
|
if [ "$EUID" -ne 0 ]
|
|
then echo "Please run as root"
|
|
exit
|
|
fi
|
|
|
|
#echo "/home/xavier/Téléchargements/PI/" > directoryhome
|
|
|
|
|
|
HOME=$(cat directoryhome)
|
|
|
|
#echo $HOME
|
|
|
|
if [ "$HOME" == "" ]; then
|
|
echo "/home/xavier/Téléchargements/PI/" > directoryhome
|
|
HOME=$(cat directoryhome)
|
|
fi
|
|
#echo $HOME
|
|
|
|
|
|
while : ; do
|
|
|
|
choix=$(whiptail --title "<-- Linux Image Disk V 1.0 (C) GNU GPL In4Matik-->" --menu " >> Faite votre choix: " 23 69 16 \
|
|
1 " Sauvegarde du media vers fichier" \
|
|
2 " Restauration du fichier vers media" \
|
|
22 " Configuration repertoire " \
|
|
23 " Fin " 3>&1 1>&2 2>&3)
|
|
|
|
exitstatus=$?
|
|
|
|
|
|
#on recupere ce choix
|
|
#exitstatus=$?
|
|
if [ $exitstatus = 0 ]; then
|
|
echo "Vous avez choisi l option:" $choix
|
|
else
|
|
echo "Votre choix Fin."; break;
|
|
fi
|
|
|
|
|
|
# case : action en fonction du choix
|
|
|
|
case $choix in
|
|
|
|
1)
|
|
clear
|
|
#Detection des media disponible
|
|
i=0
|
|
AllPartsArr=()
|
|
_media=`ls -1 /sys/block`
|
|
|
|
for i in $_media
|
|
do
|
|
AllPartsArr+=($i " ")
|
|
done
|
|
|
|
while true
|
|
do
|
|
media=$(whiptail --title "Choix du media" --menu " >> Selectionner le media (SOURCE): " 33 69 26 "${AllPartsArr[@]}" 3>&1 1>&2 2>&3)
|
|
if [ $? != 0 ]; then
|
|
|
|
break;
|
|
elif [ $media != "" ]; then
|
|
|
|
break;
|
|
fi
|
|
|
|
done
|
|
#echo $media
|
|
media="/dev/$media"
|
|
#Choix du nom de fichier destination
|
|
|
|
|
|
while true
|
|
do
|
|
|
|
filename=$(whiptail --title "Choix du fichier" --inputbox " >> Saissir le nom du fichier (DESTINATION): " 8 39 backup.img 3>&1 1>&2 2>&3)
|
|
if [ $? != 0 ]; then
|
|
|
|
break;
|
|
elif [ $filename != "" ]; then
|
|
|
|
break;
|
|
fi
|
|
|
|
done
|
|
filename="$HOME$filename"
|
|
#echo $filename
|
|
|
|
# Exec cmd dd
|
|
|
|
$(dd status=progress if=$media of=$filename ) | whiptail --title "Sauvegarde du media" --msgbox "en cours de transfert du media $media vers le fichier $filename." 8 78
|
|
#show information
|
|
whiptail --title "Sauvegarde du media." --msgbox "Sauvegarde terminee: du media $media vers le fichier $filename" 8 78
|
|
exit 0 ;;
|
|
|
|
2)
|
|
clear
|
|
#Choix du nom de fichier
|
|
i=0
|
|
AllfileArr=()
|
|
_filename=`cd $HOME ; ls *.img`
|
|
|
|
for i in $_filename
|
|
do
|
|
AllfileArr+=($i " ")
|
|
done
|
|
|
|
while true
|
|
do
|
|
filename=$(whiptail --title "Choix du fichier" --menu " >> Selectionner le fichier (SOURCE) : " 33 69 26 "${AllfileArr[@]}" 3>&1 1>&2 2>&3)
|
|
if [ $? != 0 ]; then
|
|
|
|
break;
|
|
elif [ $filename != "" ]; then
|
|
|
|
break;
|
|
fi
|
|
|
|
done
|
|
#echo $filename
|
|
#Detection des media disponible
|
|
i=0
|
|
AllPartsArr=()
|
|
_media=`ls -1 /sys/block`
|
|
|
|
for i in $_media
|
|
do
|
|
AllPartsArr+=($i " ")
|
|
done
|
|
|
|
while true
|
|
do
|
|
media=$(whiptail --title "Choix du media" --menu " >> Selectionner le media (DESTINATION): " 33 69 26 "${AllPartsArr[@]}" 3>&1 1>&2 2>&3)
|
|
if [ $? != 0 ]; then
|
|
|
|
break;
|
|
elif [ $media != "" ]; then
|
|
|
|
break;
|
|
fi
|
|
|
|
done
|
|
#echo $media
|
|
|
|
media="/dev/$media"
|
|
# Exec cmd dd
|
|
$(dd status=progress if=$filename of=$media bs=4M) | whiptail --title "Restauration du Fichier" --msgbox "en cours de transfert du fichier $filename vers le media $media." 8 78
|
|
|
|
#show information
|
|
whiptail --title "Restauration du fichier." --msgbox "Restauration terminee: du fichier $filename sur le media $media" 8 78
|
|
exit 0 ;;
|
|
|
|
22)
|
|
#Choix du chemin HOME
|
|
|
|
|
|
while true
|
|
do
|
|
|
|
filehome=$(whiptail --title "Choix du chemin" --inputbox " >> Saissir le chemin de sauvegarde: " 8 39 $HOME 3>&1 1>&2 2>&3)
|
|
if [ $filehome != "" ]; then
|
|
|
|
break;
|
|
fi
|
|
|
|
done
|
|
if [ "$filehome" != "" ]; then
|
|
echo $filehome > directoryhome
|
|
HOME=$filehome
|
|
fi
|
|
|
|
;;
|
|
23)
|
|
exit 0;;
|
|
|
|
esac
|
|
done
|
|
exit 0
|
|
|