-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript-maintenance.sh
More file actions
701 lines (596 loc) · 12.7 KB
/
script-maintenance.sh
File metadata and controls
701 lines (596 loc) · 12.7 KB
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
#!/bin/bash
# Script de maintenance faire pendant le stge à goupil.
# Fait RUFFENACH Timothée
# Le 02/06/2022
# Version 1
function sudo_activate {
# password storage
data=$(tempfile 2>/dev/null)
# trap it
trap "rm -f $data" 0 1 2 5 15
# get password
dialog --title "Demande mot de passe root" \
--clear \
--insecure \
--passwordbox "Saisissez votre mot de passe" 10 30 2> $data
ret=$?
# make decision
case $ret in
0)
echo $(cat $data) | sudo -S -s ls >/dev/null;;
1)
echo "Bye";;
255)
echo "Touche ESC appuyée."
esac
}
function display_output(){
local h=${1-10} # box height default 10
local w=${2-41} # box width default 41
local t=${3-Output} # box title
dialog --backtitle "Linux Shell Script Tutorial" --title "${t}" --clear --msgbox "$(<$OUTPUT)" ${h} ${w}
}
#
# Automatique menu pour le choix des disque
#
function autoMenuDisque(){
declare -a array
i=1 #Index counter for adding to array
j=1 #Option menu value generator
while read line
do
array[ $i ]=$line
(( j++ ))
array[ ($i+1) ]=""
(( i=($i+2) ))
done < <(lsblk -l -d | grep sd | cut -d " " -f 1) # selectionne les disques
#Define parameters for menu
TERMINAL=$(tty) #Gather current terminal session for appropriate redirection
HEIGHT=20
WIDTH=76
CHOICE_HEIGHT=16
BACKTITLE="Back_Title"
TITLE="Disque"
MENU="Choisissez le disque (si usb sdb):"
#Build the menu with variables & dynamic content
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${array[@]}" \
2>&1 >$TERMINAL)
}
#
# Affiche les informations systèmes
#
function infoSysteme(){
hardinfo
}
#
# test l'écran
#
function testMoniteur(){
screentest
}
#
# Relevé Ram
#
function releveRAM(){
sudo inxi -m > $OUTPUT
display_output 20 60 "Relevé RAM"
}
#
# Relevé CPU
#
function releveCPU(){
sudo inxi -C > $OUTPUT
display_output 20 60 "Relevé CPU"
}
#
# Relevé batterie
#
function releveBatterie(){
sudo acpi -i > $OUTPUT
display_output 20 60 "Relevé batterie"
}
#
# Relevé réseau
#
function releveReseau(){
sudo inxi -N > $OUTPUT
display_output 20 60 "Relevé réseau"
}
#
# Santé disque
#
function santeDisque(){
autoMenuDisque
sudo skdump --overall /dev/$CHOICE > $OUTPUT
display_output 20 60 "Santé disque"
}
#
# Info disque
#
function infoDisque(){
autoMenuDisque
sudo smartctl -i /dev/$CHOICE > $OUTPUT
display_output 20 60 "Santé disque"
}
#
# Info GPU
#
function infoGPU(){
sudo inxi -G > $OUTPUT
display_output 20 60 "info GPU"
}
#
# stress CPU
#
function stressCPU(){
#nbCore=$(cat /proc/cpuinfo | uniq | cut -d " " -f 3)
sudo inxi -s > $OUTPUT
display_output 20 60 "Température de départ"
DIALOG=${DIALOG=dialog}
sudo stress-ng --matrix 0 --ignite-cpu --log-brief --metrics-brief --times --tz --verify --timeout 190 -q &
COUNT=0
(
while test $COUNT != 100
do
echo $COUNT
echo "XXX"
inxi -s
echo "XXX"
COUNT=`expr $COUNT + 1`
sleep 1.8
done
) |
$DIALOG --title "Tempétarure en temps réel" --gauge "Temps(s)" 20 70 0
inxi -s > $OUTPUT
display_output 20 60 "Température après 3 min"
}
#
# test USB
#
function testUSB()
{
lsusb > /tmp/usbBefore
echo "veuillez insérer un périphérique USB" > $OUTPUT
display_output 20 60 "Message"
lsusb > /tmp/usbAfter
marque=$(diff /tmp/usbBefore /tmp/usbAfter | grep ID | cut -d " " -f 8-100)
if [ -z "$marque" ]
then
echo "Le port USB ne fonctionne pas ou aucun périphérique inseré" > $OUTPUT
display_output 20 60 "Message"
else
echo "Le périphérique usb inseré est : $marque" > $OUTPUT
display_output 20 60 "Message"
fi
dialog --backtitle "choix" --title "demande d'une réponse" \
--yesno "
Souhaitez-vous tester un nouveau port USB ? " 12 60
if [ $? = 0 ]
then
testUSB
else
return
fi
}
#
# test Son
#
function testSon
{
mplayer ./test.wav > /dev/null 2>&1 &
echo "Test du son" > $OUTPUT
display_output 20 60 "Message"
}
#
# test Micro
#
function testMicro
{
# on passe en anglais
export LANG=en.UTF-8
# génération des menus pour la carte son.
declare -a array
i=1 #Index counter for adding to array
j=1 #Option menu value generator
while read line
do
array[ $i ]=$line
(( j++ ))
array[ ($i+1) ]=""
(( i=($i+2) ))
done < <(arecord -l | grep card ) # selectionne les disques
#Define parameters for menu
TERMINAL=$(tty) #Gather current terminal session for appropriate redirection
HEIGHT=20
WIDTH=76
CHOICE_HEIGHT=16
BACKTITLE="Back_Title"
TITLE="Carte Son"
MENU="Choisissez la carte son :"
#Build the menu with variables & dynamic content
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${array[@]}" \
2>&1 >$TERMINAL)
export LANG=fr_FR.UTF-8
echo "Appuyer sur Accepter pour commencer l'enregistrement de 10 s " > $OUTPUT
display_output 20 60 "Enregistrement"
# On récupère les données que l'on veut.
card=$(echo $CHOICE | grep -E -o "card.{0,2}" | cut -d " " -f2 )
device=$(echo $CHOICE | grep -E -o "device.{0,2}" | cut -d " " -f2 )
fullDevice="hw:${card},${device}"
# enregistre pendant 10 s
arecord -f S16_LE -d 10 -c 2 --device="$fullDevice" /tmp/test-mic.wav >/dev/null 2>&1 &
DIALOG=${DIALOG=dialog}
COUNT=0
(
while test $COUNT != 100
do
echo $COUNT
echo "XXX"
echo "enregistrement"
echo "XXX"
COUNT=`expr $COUNT + 10`
sleep 1
done
) |
$DIALOG --title "Enregistrement micro" --gauge "Temps(s)" 20 70 0
mplayer /tmp/test-mic.wav >/dev/null 2>&1 &
DIALOG=${DIALOG=dialog}
COUNT=0
(
while test $COUNT != 100
do
echo $COUNT
echo "XXX"
echo "Lecture de l'enregistrement"
echo "XXX"
COUNT=`expr $COUNT + 10`
sleep 1
done
) |
$DIALOG --title "Lecture de l'enregistement" --gauge "Temps(s)" 20 70 0
}
#
# Test la WebCam
#
function testWebCam
{
# génération des menus pour la webCam.
declare -a array
i=1 #Index counter for adding to array
j=1 #Option menu value generator
while read line
do
array[ $i ]=$line
(( j++ ))
array[ ($i+1) ]=""
(( i=($i+2) ))
done < <(ls -l /dev/video* | grep -o -E "/dev/video." ) # l'entré vidéo
#Define parameters for menu
TERMINAL=$(tty) #Gather current terminal session for appropriate redirection
HEIGHT=20
WIDTH=76 # on remet en français
export LANG=fr_FR.UTF-8
#Build the menu with variables & dynamic content
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${array[@]}" \
2>&1 >$TERMINAL)
sudo cheese $CHOICE
}
#
# Test du clavier
#
function testClavier
{
x-www-browser https://www.test-clavier.fr/
}
function testConnexionInternet
{
# on passe en anglais
export LANG=en.UTF-8
DIALOG=${DIALOG=dialog}
COUNT=0
(
while test $COUNT != 100
do
echo $COUNT
echo "XXX"
echo "Ping en cours"
echo "XXX"
COUNT=`expr $COUNT + 25`
done
) |
$DIALOG --title "Ping en cours" --gauge "Temps(s)" 20 70 0
testPing=$(ping -c 4 www.google.fr -q | grep packets | cut -d " " -f4 &)
if (( $testPing == "4" )); then
answerPing="L'adresse www.google.fr répond avec la commande ping"
testCurl=$(curl -s -I www.google.fr | grep -o OK)
if (( testCurl == "OK" )); then
answerCurl="Le site www.google.fr fonctionne"
export LANG=fr_FR.UTF-8
echo "$answerPing\n$answerCurl" > $OUTPUT
display_output 20 60 "État de la connexion internet"
DIALOG=${DIALOG=dialog}
return
else
answerCurl="Le site www.google.fr à un problème"
export LANG=fr_FR.UTF-8
echo $answerCurl > $OUTPUT
display_output 20 60 "État de la connexion internet"
DIALOG=${DIALOG=dialog}
return
fi
else
answerPing="Problème de connexion réseau"
export LANG=fr_FR.UTF-8
echo $answerPing > $OUTPUT
display_output 20 60 "État de la connexion internet"
DIALOG=${DIALOG=dialog}
return
fi
# regarde la réponse sur le site internet.
# on remet en français
export LANG=fr_FR.UTF-8
# test informations
display_output 20 60 "État de la connexion internet"
DIALOG=${DIALOG=dialog}
}
#
# Fait une mise du système
#
function majSysteme
{
DIALOG=${DIALOG=dialog}
COUNT=0
(
while test $COUNT != 100
do
cat <<EOF
XXX
$COUNT
Mise à jour de la liste des paquets existant
XXX
EOF
sudo apt update -y >/dev/null 2>&1
(( COUNT+=25 ))
cat <<EOF
XXX
$COUNT
Mise à jour des logiciels
XXX
EOF
sudo apt upgrade -y >/dev/null 2>&1
(( COUNT+=25 ))
cat <<EOF
XXX
$COUNT
Suppression des logiciels non nécessaire
XXX
EOF
sudo apt autoremove -y >/dev/null 2>&1
(( COUNT+=25 ))
cat <<EOF
XXX
$COUNT
Suppression du cache logiciel
XXX
EOF
sudo apt autoclean -y >/dev/null 2>&1
(( COUNT+=25 ))
done
) |
$DIALOG --title "Mise à Jour du système" --gauge "Temps(s)" 20 70 0
}
#
# Installation des bon logiciels pour le scripte fonctionne
#
function installLogiciel
{
DIALOG=${DIALOG=dialog}
COUNT=0
(
while test $COUNT != 100
do
######1
cat <<EOF
XXX
$COUNT
Installation de hardinfo
XXX
EOF
sudo apt install hardinfo -y >/dev/null 2>&1
(( COUNT+=8 ))
######2
cat <<EOF
XXX
$COUNT
Installation de stress-ng
XXX
EOF
sudo apt install stress-ng -y >/dev/null 2>&1
(( COUNT+=8 ))
######3
cat <<EOF
XXX
$COUNT
Installation de screentest
XXX
EOF
sudo apt install screentest -y >/dev/null 2>&1
(( COUNT+=8 ))
######4
cat <<EOF
XXX
$COUNT
Installation d'inxi
XXX
EOF
sudo apt install inxi -y >/dev/null 2>&1
(( COUNT+=8 ))
######5
cat <<EOF
XXX
$COUNT
Installation d'acpi
XXX
EOF
sudo apt install acpi -y >/dev/null 2>&1
(( COUNT+=8 ))
######6
cat <<EOF
XXX
$COUNT
Installation de libatasmart-bin
XXX
EOF
sudo apt install libatasmart-bin -y >/dev/null 2>&1
(( COUNT+=8 ))
######7
cat <<EOF
XXX
$COUNT
Installation de smartmontools
XXX
EOF
sudo apt install smartmontools -y >/dev/null 2>&1
(( COUNT+=8 ))
######8
cat <<EOF
XXX
$COUNT
Installation de mplayer
XXX
EOF
sudo apt install mlayer -y >/dev/null 2>&1
(( COUNT+=8 ))
######9
cat <<EOF
XXX
$COUNT
Installation d'alsautils
XXX
EOF
sudo apt install alsautils -y >/dev/null 2>&1
(( COUNT+=8 ))
######10
cat <<EOF
XXX
$COUNT
Installation de cheese
XXX
EOF
sudo apt install cheese -y >/dev/null 2>&1
(( COUNT+=8 ))
######11
cat <<EOF
XXX
$COUNT
Installation d'x-www-browser
XXX
EOF
sudo apt install x-www-brower -y >/dev/null 2>&1
(( COUNT+=8 ))
######12
cat <<EOF
XXX
$COUNT
Installation de curl
XXX
EOF
sudo apt install curl -y >/dev/null 2>&1
(( COUNT+=12 ))
done
) |
$DIALOG --title "Installation des logiciels" --gauge "Temps(s)" 20 70 0
}
function main {
# utilitymenu.sh - A sample shell script to display menus on screen
# Store menu options selected by the user
INPUT=/tmp/menu.sh.$$
# Storage file for displaying cal and date command output
OUTPUT=/tmp/output.sh.$$
# trap and delete temp files
trap "rm $OUTPUT; rm $INPUT; exit" SIGHUP SIGINT SIGTERM
#
# Purpose - display output using msgbox
# $1 -> set msgbox height
# $2 -> set msgbox width
# $3 -> set msgbox title
#
# mettre le clavier en français
setxkbmap fr
# activation des droits administrateur
sudo_activate
#
# set infinite loop
#
while true
do
### display main menu ###
dialog --clear --help-button --backtitle "Maintenance" \
--title "Menu principal" \
--menu "Vous pouvez utiliser les touches Haut ou Bas, la première \n\
afficher en subrillance , ou les \n\
nombre du clavier pour faire votre choix.\n\
Choose the TASK" 80 80 80 \
Information_système_en_graphique "" \
Test_du_moniteur "" \
Relevé_RAM "" \
Relevé_CPU "" \
Relevé_batterie "" \
Relevé_réseau "" \
Santé_disque "" \
Infos_disque "" \
Infos_carte_graphique "" \
Stress_test_du_CPU "" \
Test_des_ports_USB "" \
Test_son "" \
Test_micro "" \
Test_webCam "" \
Test_Clavier "" \
Test_Connexion_internet "" \
Ré_installer_les_logiciels "" \
MAJ_du_système "" \
Quit "" 2>"${INPUT}"
menuitem=$(<"${INPUT}")
# make decsion
case $menuitem in
Information_système_en_graphique ) infoSysteme;;
Test_du_moniteur ) testMoniteur;;
Relevé_RAM ) releveRAM;;
Relevé_CPU ) releveCPU;;
Relevé_batterie ) releveBatterie;;
Relevé_réseau ) releveReseau;;
Santé_disque ) santeDisque;;
Infos_disque ) infoDisque;;
Infos_carte_graphique ) infoGPU;;
Stress_test_du_CPU ) stressCPU;;
Test_des_ports_USB) testUSB;;
Test_son ) testSon;;
Test_micro ) testMicro;;
Test_webCam ) testWebCam;;
Test_Clavier ) testClavier;;
Test_Connexion_internet) testConnexionInternet;;
Ré_installer_les_logiciels ) installLogiciel ;;
MAJ_du_système ) majSysteme ;;
Quit) echo "Bye"; break;;
esac
done
# if temp files found, delete em
[ -f $OUTPUT ] && rm $OUTPUT
[ -f $INPUT ] && rm $INPUT
}
main