-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.sh
More file actions
441 lines (408 loc) · 17.1 KB
/
menu.sh
File metadata and controls
441 lines (408 loc) · 17.1 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
#!/bin/bash
# ============================
# Funzioni di utilità
# ============================
check_cmd() {
# Controlla se un comando è presente nel PATH
# Uso: check_cmd comando
# Ritorna 0 se presente, 1 se assente
command -v "$1" &>/dev/null
}
error_dialog() {
# Mostra un messaggio di errore con dialog e attende pressione tasto
# Uso: error_dialog "Messaggio di errore"
dialog --msgbox "$1" 10 60
}
# Funzione per ottenere indirizzo IP locale
get_local_ip() {
ip addr show | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}' | cut -d/ -f1 | head -n 1
}
# Funzione per ottenere indirizzo IP esterno
get_external_ip() {
curl -s ifconfig.me
}
# ============================
# Controllo dipendenze minime
# ============================
REQUIRED_CMDS="dialog curl ip awk grep cut date whoami"
for cmd in $REQUIRED_CMDS; do
if ! check_cmd "$cmd"; then
echo "Errore: Il comando '$cmd' non è installato o non è nel PATH."
exit 1
fi
done
# Comandi opzionali (verranno controllati prima dell'uso)
OPT_CMDS_HTOP="htop"
OPT_CMDS_SENSORS="sensors"
OPT_CMDS_SPEEDTEST="speedtest-cli"
OPT_CMDS_NEOMUTT="neomutt"
OPT_CMDS_ELINKS="elinks"
OPT_CMDS_MC="mc"
OPT_CMDS_SC="sc"
OPT_CMDS_CALCURSE="calcurse"
OPT_CMDS_CALC="calc"
OPT_CMDS_SSH="ssh"
OPT_CMDS_TAR="tar"
OPT_CMDS_NANO="nano"
OPT_CMDS_PYTHON3="python3" # Per EvoDiary
while true; do
DATE=$(date '+%d-%m-%Y')
TIME=$(date '+%H:%M:%S')
LOCAL_IP=$(get_local_ip)
EXTERNAL_IP=$(get_external_ip)
USER=$(whoami)
CHOICE=$(dialog --clear --title "Launcher Testuale" \
--backtitle "Data: $DATE | Ora: $TIME | Utente: $USER | IP Locale: $LOCAL_IP | IP Esterno: $EXTERNAL_IP" \
--menu "Seleziona un'opzione" 20 70 10 \
1 "Diagnostica" \
2 "Rete" \
3 "Gestione files" \
4 "Ufficio" \
5 "Sistema" \
6 "Altro" \
0 "Esci" \
3>&1 1>&2 2>&3)
[ $? -ne 0 ] && break # Se l'utente preme ESC o Annulla
case $CHOICE in
1) # Diagnostica di sistema
DIAG_CHOICE=$(dialog --clear --title "Diagnostica di Sistema" \
--menu "Scegli un'opzione" 20 70 10 \
1 "Visualizza processi attivi (htop)" \
2 "Mostra memoria (free -h)" \
3 "Spazio su disco (df -h)" \
4 "Dettagli rete (ip addr show)" \
5 "Temperatura CPU (sensors)" \
6 "Ultimi log di sistema (journalctl)" \
7 "Test velocità connessione (speedtest-cli)" \
0 "Torna indietro" \
3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
TEMP_FILE=$(mktemp)
case $DIAG_CHOICE in
1)
if check_cmd "$OPT_CMDS_HTOP"; then
htop
else
error_dialog "htop non installato. Installarlo per usare questa funzione."
fi
;;
2) free -h > "$TEMP_FILE" && dialog --textbox "$TEMP_FILE" 20 70 ;;
3) df -h > "$TEMP_FILE" && dialog --textbox "$TEMP_FILE" 20 70 ;;
4) ip addr show > "$TEMP_FILE" && dialog --textbox "$TEMP_FILE" 20 70 ;;
5)
if check_cmd "$OPT_CMDS_SENSORS"; then
sensors > "$TEMP_FILE" 2>/dev/null || echo "Nessun sensore disponibile" > "$TEMP_FILE"
dialog --textbox "$TEMP_FILE" 20 70
else
error_dialog "lm-sensors non installato. Installarlo per questa funzione."
fi
;;
6) journalctl -q | tail -50 > "$TEMP_FILE" && dialog --textbox "$TEMP_FILE" 20 110 ;;
7)
if check_cmd "$OPT_CMDS_SPEEDTEST"; then
speedtest-cli > "$TEMP_FILE" 2>&1 || echo "Errore nell'esecuzione di speedtest-cli" > "$TEMP_FILE"
dialog --textbox "$TEMP_FILE" 20 70
else
error_dialog "speedtest-cli non installato. Installarlo per questa funzione."
fi
;;
0) ;;
esac
rm -f "$TEMP_FILE"
;;
2) # Rete
NEOMUTT_LABEL="Avvia Neomutt"
check_cmd "$OPT_CMDS_NEOMUTT" || NEOMUTT_LABEL="$NEOMUTT_LABEL (NON DISPONIBILE)"
ELINKS_LABEL="Avvia eLinks"
check_cmd "$OPT_CMDS_ELINKS" || ELINKS_LABEL="$ELINKS_LABEL (NON DISPONIBILE)"
# --- Modifica Feed RSS -> Archivio RSS ---
ARCHIVIO_RSS_LABEL="Archivio RSS (esterno)"
# Comando aggiornato per Archivio RSS
RSS_COMMAND="/home/randolph/rss_archiver/./rss_archiver.py"
SCAN_LAN_LABEL="Scansione LAN (esterno)"
TOR_LABEL="TOR Network (esterno)"
WIFI_LABEL="WiFi Manager (esterno)"
TORRENTS_LABEL="Gestione Torrents (esterno)"
SSH_LAUNCHER_LABEL="Connessioni SSH (esterno)"
NETWORK_CHOICE=$(dialog --clear --title "Rete" \
--backtitle "Utilizzo: Seleziona uno strumento di rete" \
--menu "Scegli un'opzione" 20 70 10 \
1 "$NEOMUTT_LABEL" \
2 "$ELINKS_LABEL" \
3 "$ARCHIVIO_RSS_LABEL" \
4 "$SCAN_LAN_LABEL" \
5 "$TOR_LABEL" \
6 "$WIFI_LABEL" \
7 "$TORRENTS_LABEL" \
8 "$SSH_LAUNCHER_LABEL" \
0 "Torna indietro" \
3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
case $NETWORK_CHOICE in
1)
if check_cmd "$OPT_CMDS_NEOMUTT"; then
clear && neomutt
else
error_dialog "neomutt non installato."
fi
;;
2)
if check_cmd "$OPT_CMDS_ELINKS"; then
clear && elinks
else
error_dialog "elinks non installato."
fi
;;
3) # Archivio RSS
if [ -x "$RSS_COMMAND" ]; then
clear && "$RSS_COMMAND"
else
error_dialog "Script $RSS_COMMAND non trovato o non eseguibile."
fi
;;
4)
if [ -x /home/randolph/scan_lan.sh ]; then
clear && /home/randolph/scan_lan.sh
else
error_dialog "Script /home/randolph/scan_lan.sh non trovato o non eseguibile."
fi
;;
5)
if [ -x /home/randolph/tor_proxy.sh ]; then
clear && /home/randolph/tor_proxy.sh
else
error_dialog "Script /home/randolph/tor_proxy.sh non trovato o non eseguibile."
fi
;;
6)
if [ -x /home/randolph/wifi_manager.sh ]; then
clear && /home/randolph/wifi_manager.sh
else
error_dialog "Script /home/randolph/wifi_manager.sh non trovato o non eseguibile."
fi
;;
7)
if [ -x /home/randolph/torrents_manager.sh ]; then
clear && /home/randolph/torrents_manager.sh
else
error_dialog "Script /home/randolph/torrents_manager.sh non trovato o non eseguibile."
fi
;;
8)
if [ -x /home/randolph/ssh_launcher.sh ]; then
clear && /home/randolph/ssh_launcher.sh
else
error_dialog "Script /home/randolph/ssh_launcher.sh non trovato o non eseguibile."
fi
;;
0) ;;
esac
;;
3) # Gestione file
FILE_CHOICE=$(dialog --clear --title "Gestione File" \
--menu "Scegli un'opzione" 20 70 10 \
1 "Midnight Commander (mc)" \
2 "Cerca file nel sistema" \
3 "Visualizza file di testo" \
4 "Rimuovi file o directory" \
0 "Torna indietro" \
3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
case $FILE_CHOICE in
1)
if check_cmd "$OPT_CMDS_MC"; then
mc
else
error_dialog "Midnight Commander (mc) non installato."
fi
;;
2)
QUERY=$(dialog --inputbox "Inserisci il nome del file da cercare:" 10 50 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
[ -z "$QUERY" ] && error_dialog "Nessun nome file inserito." && continue
TEMP_FILE=$(mktemp)
find / -name "$QUERY" 2>/dev/null > "$TEMP_FILE"
if [ -s "$TEMP_FILE" ]; then
dialog --textbox "$TEMP_FILE" 20 70
else
error_dialog "Nessun file trovato con il nome: $QUERY"
fi
rm -f "$TEMP_FILE"
;;
3)
FILE=$(dialog --fselect / 15 50 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
[ ! -f "$FILE" ] && error_dialog "Il file selezionato non esiste." && continue
cat "$FILE" | dialog --textbox - 20 70
;;
4)
FILE=$(dialog --fselect / 15 50 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
if [ -e "$FILE" ]; then
rm -r "$FILE" && dialog --msgbox "Rimosso: $FILE" 10 50 || error_dialog "Errore nella rimozione di $FILE."
else
error_dialog "Il file o directory selezionato non esiste."
fi
;;
0) ;;
esac
;;
4) # Strumenti di ufficio
SC_LABEL="sc (foglio elettronico)"
check_cmd "$OPT_CMDS_SC" || SC_LABEL="$SC_LABEL (NON DISPONIBILE)"
NANO_LABEL="nano (editor di testo)"
check_cmd "$OPT_CMDS_NANO" || NANO_LABEL="$NANO_LABEL (NON DISPONIBILE)"
CALCURSE_LABEL="calcurse (calendario)"
check_cmd "$OPT_CMDS_CALCURSE" || CALCURSE_LABEL="$CALCURSE_LABEL (NON DISPONIBILE)"
CALC_LABEL="calc (calcolatrice)"
check_cmd "$OPT_CMDS_CALC" || CALC_LABEL="$CALC_LABEL (NON DISPONIBILE)"
# --- Aggiunta EvoDiary ---
EVODIARY_LABEL="EvoDiary (esterno)"
if ! check_cmd "$OPT_CMDS_PYTHON3"; then
EVODIARY_LABEL="$EVODIARY_LABEL (NON DISPONIBILE)"
fi
OFFICE_CHOICE=$(dialog --clear --title "Strumenti di Ufficio" \
--menu "Scegli uno strumento" 20 70 10 \
1 "$SC_LABEL" \
2 "$NANO_LABEL" \
3 "$CALCURSE_LABEL" \
4 "$CALC_LABEL" \
5 "$EVODIARY_LABEL" \
0 "Torna indietro" \
3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
case $OFFICE_CHOICE in
1)
if check_cmd "$OPT_CMDS_SC"; then
sc
else
error_dialog "sc non installato."
fi
;;
2)
if check_cmd "$OPT_CMDS_NANO"; then
FILE=$(dialog --inputbox "Inserisci il nome del file da creare/modificare:" 10 50 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
nano "$FILE"
else
error_dialog "nano non installato."
fi
;;
3)
if check_cmd "$OPT_CMDS_CALCURSE"; then
calcurse
else
error_dialog "calcurse non installato."
fi
;;
4)
if check_cmd "$OPT_CMDS_CALC"; then
calc
else
error_dialog "calc non installato."
fi
;;
5) # EvoDiary
if check_cmd "$OPT_CMDS_PYTHON3"; then
# --- Modifica comando EvoDiary ---
/home/randolph/my_diary/./main.py
else
error_dialog "python3 non installato. Impossibile eseguire EvoDiary."
fi
;;
0) ;;
esac
;;
5) # Sistema
SYSTEM_CHOICE=$(dialog --clear --title "Sistema" \
--menu "Scegli un'opzione" 20 70 10 \
1 "Reboot" \
2 "Shutdown" \
3 "Display OFF (esterno)" \
4 "Display ON (esterno)" \
5 "Gestore APT (esterno)" \
0 "Torna indietro" \
3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
case $SYSTEM_CHOICE in
1)
dialog --yesno "Sei sicuro di voler riavviare il sistema?" 10 50
[ $? -eq 0 ] && sudo reboot
;;
2)
dialog --yesno "Sei sicuro di voler spegnere il sistema?" 10 50
[ $? -eq 0 ] && sudo poweroff
;;
3)
[ -x /home/randolph/display_off.sh ] && /home/randolph/display_off.sh || error_dialog "Script display_off.sh non trovato o non eseguibile."
;;
4)
[ -x /home/randolph/display_on.sh ] && /home/randolph/display_on.sh || error_dialog "Script display_on.sh non trovato o non eseguibile."
;;
5) # --- Aggiunta Gestore APT ---
if [ -x /home/randolph/gestore_apt.sh ]; then
clear && /home/randolph/gestore_apt.sh
else
error_dialog "Script /home/randolph/gestore_apt.sh non trovato o non eseguibile."
fi
;;
0) ;;
esac
;;
6) # Altro
OTHER_CHOICE=$(dialog --clear --title "Altro" \
--menu "Scegli un'opzione" 20 70 10 \
1 "Comando personalizzato" \
2 "Backup rapido directory (tar)" \
3 "Database ADS-B (esterno)" \
4 "SkyTool (esterno)" \
0 "Torna indietro" \
3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
case $OTHER_CHOICE in
1)
CMD=$(dialog --inputbox "Inserisci un comando da eseguire:" 10 50 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
[ -z "$CMD" ] && error_dialog "Nessun comando inserito." && continue
OUTPUT=$(eval "$CMD" 2>&1)
dialog --msgbox "$OUTPUT" 20 70
;;
2)
if ! check_cmd "$OPT_CMDS_TAR"; then
error_dialog "tar non installato. Impossibile eseguire il backup."
continue
fi
DIR=$(dialog --dselect / 15 50 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
[ -z "$DIR" ] && error_dialog "Nessuna directory selezionata." && continue
OUTPUT=$(dialog --inputbox "Nome del file di backup (es. backup.tar.gz):" 10 50 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && continue
[ -z "$OUTPUT" ] && error_dialog "Nessun nome di output inserito." && continue
if tar -czf "$OUTPUT" "$DIR" 2>/dev/null; then
dialog --msgbox "Backup completato! File: $OUTPUT" 10 50
else
error_dialog "Errore durante la creazione del backup."
fi
;;
3)
if check_cmd "$OPT_CMDS_SSH"; then
clear && ssh pi@192.168.178.32 "/home/pi/query.sh" || error_dialog "Errore nell'esecuzione di SSH o dello script remoto."
else
error_dialog "ssh non installato."
fi
;;
4)
if [ -x /home/randolph/skytool/./skyinfo.sh ]; then
clear && /home/randolph/skytool/./skyinfo.sh
else
error_dialog "Script /home/randolph/skytool/skyinfo.sh non trovato o non eseguibile."
fi
;;
0) ;;
esac
;;
0)
break
;;
esac
done