1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
| #!/bin/bash
############################################
#Script utilitaire
# auteur: jean-françois BAERT
#Licence Creativ Common BY - SA http://creativecommons.org/licenses/by-sa/2.0/fr/ ou GPL v3
#
#
#
#systemes testés: ubuntu et variantes
#dependance: zenity
#
############################################
#declaration des fonctions:
install()
{
#Installation d'un programme (comme son nom l'indique)
prog=$(zenity --entry --title="Programme" --text="Quel programme voulez vous installer ?" --entry-text= "Programme")
zenity --question --title="Question" --text="Vous allez installer $prog, merci de confirmer"
zenity --password | sudo -S apt-get -y install $prog
main
}
update()
{
#Mise a jour du système
zenity --password | sudo -S apt-get update && sudo apt-get dist-upgrade
main
}
space()
{
#contrôle espace disques
df -h | awk '{print $5 " utilise sur " $6}' | grep % | grep -v Use| sort -n | zenity --text-info --title="Occupation des disques"
main
}
profil_creation()
{
#creation d'un fichier peremttant de lancer des programmes en fonction d'un profil defini
ici=`pwd`
nom_profil=$(zenity --entry --title="Création du profil" --text="Entrez le nom du profil")
profil=$ici/$nom_profil".desk"
if test -e $profil
then
zenity --warning --title="Erreur" --text="Ce profil existe déjà"
question=$(zenity --entry --width=600 --title="Voulez vous modifier le profil existant?" --text= "Non" Oui)
case $question in
Non)
exit 0
;;
Oui)
rm $profil
programmes=$(zenity --entry --width=600 --title="Programmes à lancer" --text="Entrez les programmes à lancer séparés par un espace")
for i in $programmes
do echo $i >> $profil
done
echo $programmes | zenity --text-info --width=400 --title="Ces programmes seront lancés"
chmod u+x $profil
;;
esac
else
programmes=$(zenity --entry --title="Programmes à lancer" --text="Entrez les programmes à lancer séparés par un espace")
for i in $programmes
do echo $i >> $profil
done
echo $programmes| zenity --text-info --width=400 --title="Ces programmes seront lancés"
chmod u+x $profil
fi
main
}
profil_login()
{
#Lancement des programmes precedemment definis dans le profil (fonction ci-dessus)
ici=`pwd`
ls -lrt *desk |awk '{print $9}'| cut -d'.' -f1 > choix_profil
var=`awk '{print $1}' choix_profil`
execute=$(zenity --list --separator='\n' --title="Choix du profil à lancer" --column="Profil" $var)
./$execute".desk"
rm choix_profil
main
}
charge_profil()
{
#création du fichier .desktop et copie vers /etc/xdg/autostart pour lancement automatique des programmes au demarrage de la machine
ici=`pwd`
ls -lrt *desktop |awk '{print $9}'| cut -d'.' -f1 > choix_profil
var1=`awk '{print $1}' choix_profil`
prof=$(zenity --list --separator='\n' --title="Choix du profil à lancer" --column="Profil" $var1)
fic=$ici/$prof".desktop"
echo "[Desktop Entry]" > $fic
echo "Encoding=UTF-8" >> $fic
echo "Name=$prof" >> $fic
echo "Exec=$ici/$prof".desktop"" >>$fic
echo "Terminal=false" >>$fic
echo "Type=Application" >> $fic
chmod 644 $fic
zenity --password --title="Authentification" --text="Entrez votre mot de passe" | sudo -S cp $fic /etc/xdg/autostart/ && sudo chown root:root $fic
main
}
aide()
{
ici=`pwd`
firefox $ici/aide.html
main
}
sauvegarde()
{
#permet de creer une archive compressée d'un dossier
ici=`pwd`
# Selection du repertoire a explorer ($HOME par defaut)
chemin=$(zenity --file-selection --title="Dossier à sauvegarder" --directory --filename=$HOME/)
tar -cvf $chemin".tar" $chemin && bzip2 $chemin".tar" | zenity --info --title="En cours" --text="Archivage et compression de $chemin en cours"
}
recherche()
{
# Fonction de recherche de fichiers divers (choix) et affichage des resultat en page web
# on se place dans le home du user courant
cd
ici=`pwd`
##On cree/vide le fichier
> $ici/index.html
# Selection du repertoire a explorer ($HOME par defaut)
chemin=$(zenity --file-selection --title="Select Directory" --directory --filename=$HOME/)
#Selection du type de fichier a chercher
doc=$(zenity --entry --ok-label="Valider" --cancel-label="Annuler" --width=400 --height=100 --title="Saisie" --text="Faites votre choix" --entry-text="Films" Musiques Documents Ebook)
case $doc in
1)
exit
;;
Films)
rep=$(zenity --entry --ok-label="Valider" --cancel-label="Annuler" --width=400 --height=100 --title=" Saisie" --text="Entrez tout ou partie du nom du film ou laissez vide pour tous" )
set -x
# recherche des fichiers videos, on se limite aux avi AVI, mp4 MP4 et mkv MKV
if [$rep == ""] ;then
find $chemin $file -type f -iname '*.mp4' -o -iname '*.avi' -o -iname '*.mkv' | while read i
#on ajoute les fichiers trouves dans la page html
do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
done
else
find $chemin $file -type f -iname "*$rep*.mp4" -o -iname "*$rep*.avi" -o -iname "*$rep*.mkv" | while read i
do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
done
fi
;;
Musiques)
rep=$(zenity --entry --ok-label="Valider" --cancel-label="Annuler" --width=400 --height=100 --title=" Saisie" --text="Entrez tout ou partie du titre recherché, laissez vide pour tous" )
# recherche des fichiers sons on se limite aux mp3, flac, wav
if [$rep == ""] ;then
find $chemin $file -type f -iname '*.mp3' -o -iname '*.flac' -o -iname '*.wav' | while read i
#on ajoute les fichiers trouves dans la page html
do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
done
else
find $chemin $file -type f -iname "*$rep*.mp3" -o -iname "*$rep*.flac" -o -iname "*$rep*.wav" | while read i
do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
done
fi
;;
Documents)
rep=$(zenity --entry --ok-label="Valider" --cancel-label="Annuler" --width=400 --height=100 --title=" Saisie" --text="Entrez tout ou partie du nom du document, laissez vide pour tous" )
# recherche des fichiers on se limite aux doc, xls, odt, ods
if [$rep == ""] ;then
find $chemin $file -type f -iname '*.doc' -o -iname '*.odt' -o -iname '*.xls' -o -iname '*.ods' | while read i
#on ajoute les fichiers trouves dans la page html
do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
done
else
find $chemin $file -type f -iname "*$rep*.doc" -o -iname "*$rep*.odt " -o -iname "*$rep*.xls" -o -iname "*$rep*.ods"| while read i
do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
done
fi
;;
Ebook)
rep=$(zenity --entry --ok-label="Valider" --cancel-label="Annuler" --width=400 --height=100 --title=" Saisie" --text="Entrez tout ou partie du nom du document, laissez vide pour tous" )
# recherche des fichiers on se limite aux epub, pdf
if [$rep == ""] ;then
find $chemin $file -type f -iname '*.epub' -o -iname '*.pdf' | while read i
#on ajoute les fichiers trouves dans la page html
do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
done
else
find $chemin $file -type f -iname "*$rep*.epub" -o -iname "*$rep*.pdf " | while read i
do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
done
fi
;;
esac
#Generation de la page web # en-tete
echo '<html>' >> $ici/index.html
echo '<li><a href="'${i}'">'${i}'</a></li>' >> $ici/index.html
echo '</ul></body></html>' >> $ici/index.html
# firefox ouvre la page
firefox $ici/index.html
}
list_start()
{
ls -lrt /etc/xdg/autostart/* | awk '{print $9}'| awk -F '/' '{print $5}'| cut -d'.' -f1 | zenity --text-info --title="Programmes lancés au démarrage"
}
#Interface pricipale
main()
{
rep=`pwd`
choix=$(zenity --entry --title="Bonjour" --text="Faites votre choix" --entry-text= Utilitaire Administration Aide)
case $choix in
1)
exit 0
;;
Utilitaire)
utile=$(zenity --entry --title="Choix" --text="Faites votre choix" --entry-text= "Recherche" Espace_disque Programmes_au_demarrage Sauvegarde)
case $utile in
1)
exit 1
;;
Recherche)
recherche
;;
Espace_disque)
space
;;
Programmes_au_demarrage)
list_start
;;
Sauvegarde)
sauvegarde
;;
esac
;;
Administration)
tache=$(zenity --entry --title="Choix" --text="Que voulez vous faire?" --entry= "Update" Install_programm Creer_profil Lancer_profil Charger_profil)
case $tache in
1)
exit 1
;;
Update)
update
;;
Install_programm)
install
;;
Creer_profil)
profil_creation
;;
Lancer_profil)
profil_login
;;
Charger_profil)
charge_profil
;;
esac
;;
Aide)
aide
;;
esac
}
#lancement de la fonction "main", l'interface quoi!
main |
Partager