-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash-truth.sh
More file actions
executable file
·301 lines (278 loc) · 11.4 KB
/
Copy pathflash-truth.sh
File metadata and controls
executable file
·301 lines (278 loc) · 11.4 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
#!/usr/bin/env bash
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
# If shell is not an interactive terminal (e.g., running BATS), disable colors
if [[ ! -t 1 ]]; then
RED=''; GREEN=''; YELLOW=''; NC=''
fi
# Translation function
translate() {
case $LANGUAGE in
pt) case $1 in
banner1) echo "USB Flash Drive Checker – FlashTruth";;
banner2) echo "by devDudu-21 👑";;
menu1) echo "Verificar informações do pendrive";;
menu2) echo "Testar pendrive com F3";;
menu0) echo "Sair";;
scanning) echo "Analisando informações do dispositivo:";;
confirm_format) echo "Deseja formatar o pendrive antes do teste? (s/n):";;
format_warn) echo "ATENÇÃO: Todos os dados serão apagados!";;
select_fs) echo "Escolha o sistema de arquivos:";;
done_format) echo "Formatação concluída.";;
files_found) echo "Conteúdo detectado (${2} itens).";;
remove_temp) echo "Remover arquivos temporários gerados pelo teste? (s/n):";;
saved_report) echo "Relatório salvo em:";;
mock_mode) echo "Modo MOCK ativado. Simulando pendrive...";;
unknown_option) echo "[ERROR] Opção desconhecida:";;
no_devices) echo "Nenhum pendrive montado encontrado.";;
devices_detected)echo "Dispositivos montados detectados:";;
invalid_choice) echo "Escolha inválida.";;
select_option) echo "Selecione uma opção:";;
invalid_option) echo "Opção inválida.";;
prompt_option) echo "Opção: ";;
press_enter) echo "Pressione ENTER para voltar ao menu.";;
mock_mountpoint) echo "Mock mountpoint em";;
exiting) echo "Saindo...";;
status_high) echo "🟢 Alta confiabilidade";;
status_moderate) echo "🟡 Moderada";;
status_low) echo "🔴 Provável falsificação";;
report_device) echo "Dispositivo:";;
report_manufacturer) echo "Fabricante:";;
report_model) echo "Modelo:";;
report_serial) echo "Serial:";;
report_filesystem) echo "Sistema de Arquivos:";;
report_size) echo "Tamanho:";;
report_reliability) echo "Confiabilidade:";;
report_prefix) echo "flashtruth_relatorio";;
*) echo "$1";;
esac;;
en) case $1 in
banner1) echo "USB Flash Drive Checker – FlashTruth";;
banner2) echo "by devDudu-21 👑";;
menu1) echo "Check USB drive info";;
menu2) echo "Test USB drive with F3";;
menu0) echo "Exit";;
scanning) echo "Analyzing device information:";;
confirm_format) echo "Do you want to format the drive before testing? (y/n):";;
format_warn) echo "WARNING: All data will be erased!";;
select_fs) echo "Choose filesystem type:";;
done_format) echo "Formatting complete.";;
files_found) echo "Content detected (${2} items).";;
remove_temp) echo "Remove temporary files generated by the test? (y/n):";;
saved_report) echo "Report saved to:";;
mock_mode) echo "Mock mode enabled. Simulating drive...";;
unknown_option) echo "[ERROR] Unknown option:";;
no_devices) echo "No mounted USB drive found.";;
devices_detected)echo "Mounted devices found:";;
invalid_choice) echo "Invalid choice.";;
select_option) echo "Select an option:";;
invalid_option) echo "Invalid option.";;
prompt_option) echo "Option: ";;
press_enter) echo "Press ENTER to return to the menu.";;
mock_mountpoint) echo "Mock mountpoint at";;
exiting) echo "Exiting...";;
status_high) echo "🟢 High reliability";;
status_moderate) echo "🟡 Moderate";;
status_low) echo "🔴 Likely counterfeit";;
report_device) echo "Device:";;
report_manufacturer) echo "Manufacturer:";;
report_model) echo "Model:";;
report_serial) echo "Serial:";;
report_filesystem) echo "Filesystem:";;
report_size) echo "Size:";;
report_reliability) echo "Reliability:";;
report_prefix) echo "flashtruth_report";;
*) echo "$1";;
esac;;
*) echo "$1";;
esac
}
MOCK_MODE=false
DEBUG=false
RUN_CHECK=false
# Parse options
while [[ $# -gt 0 ]]; do
case $1 in
--mock) MOCK_MODE=true ;;
--debug) DEBUG=true ;;
--mock-check) MOCK_MODE=true; RUN_CHECK=true ;;
*) echo -e "${RED}$(translate unknown_option) $1${NC}"; exit 1 ;;
esac
shift
done
log_debug() { $DEBUG && echo "[DEBUG] $1"; }
# Detects the language
if [[ ! "${LANGUAGE:-}" =~ ^(pt|en)$ ]]; then
SYSTEM_LANG=$(locale | awk -F= '/^LANG=/ {print $2}' | cut -d_ -f1)
if [[ "$SYSTEM_LANG" =~ ^(pt|en)$ ]]; then
export LANGUAGE="$SYSTEM_LANG"
else
export LANGUAGE="en" # Default to English
fi
fi
if $MOCK_MODE; then
echo -e "${YELLOW}[MOCK] $(translate mock_mode)${NC}"
MOCK_DEVICE_NAME="/tmp/flashtruth-mockdrive"
mkdir -p "$MOCK_DEVICE_NAME"
touch "$MOCK_DEVICE_NAME/PLACEHOLDER.txt"
log_debug "$(translate mock_mountpoint) $MOCK_DEVICE_NAME"
fi
print_banner() {
echo -e "${GREEN}"
echo "███████╗██╗ █████╗ ███████╗██╗ ██╗ ████████╗██████╗ ██╗ ██╗████████╗██╗ ██╗"
echo "██╔════╝██║ ██╔══██╗██╔════╝██║ ██║ ╚══██╔══╝██╔══██╗██║ ██║╚══██╔══╝██║ ██║"
echo "█████╗ ██║ ███████║███████╗███████║ ██║ ██████╔╝██║ ██║ ██║ ███████║"
echo "██╔══╝ ██║ ██╔══██║╚════██║██╔══██║ ██║ ██╔══██╗██║ ██║ ██║ ██╔══██║"
echo "██║ ███████╗██║ ██║███████║██║ ██║ ██║ ██║ ██║╚██████╔╝ ██║ ██║ ██║"
echo "╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝"
echo -e "${NC}"
echo " $(translate banner1)"
echo " $(translate banner2)"
echo ""
}
# Lists devices and sets mount_path
list_devices() {
local mount_points=()
if $MOCK_MODE; then
mount_points=("/tmp/flashtruth-mockdrive [SIMULADO]")
mount_path="/tmp/flashtruth-mockdrive"
else
for base in /media/$USER /run/media/$USER; do
[ -d "$base" ] || continue
for dir in "$base"/*; do
[ -d "$dir" ] && mount_points+=("$dir")
done
done
fi
if [ ${#mount_points[@]} -eq 0 ]; then
echo -e "${RED}[-] $(translate no_devices)${NC}"
exit 1
fi
echo -e "${YELLOW}[?] $(translate devices_detected)${NC}"
for i in "${!mount_points[@]}"; do
echo "[$((i+1))] ${mount_points[$i]}"
done
echo ""
read -r -p "$(translate prompt_option)" choice
if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt "${#mount_points[@]}" ]; then
echo -e "${RED}[-] $(translate invalid_choice)${NC}"
exit 1
fi
mount_path="${mount_points[$((choice-1))]}"
}
# Formats the drive
format_drive() {
dev=$(df "$mount_path" | tail -1 | awk '{print $1}' | sed 's/[0-9]*$//')
echo -e "${RED}[!] $(translate format_warn)${NC}"
read -r -p "$(translate confirm_format) " c
[[ ! "$c" =~ ^[sSyYnN]$ ]] && return
echo -e "${YELLOW}$(translate select_fs)${NC}"
echo "[1] FAT32"; echo "[2] exFAT"; echo "[3] ext4"
read -r -p "$(translate prompt_option)" fs_type
case $fs_type in
1) fs_type="vfat";;
2) fs_type="exfat";;
3) fs_type="ext4";;
*) echo -e "${RED}$(translate invalid_option)${NC}"; return;;
esac
sudo umount "${dev}"* &>/dev/null
sudo mkfs."$fs_type" -F "$dev"
echo -e "${GREEN}$(translate done_format)${NC}"; sleep 1
}
# Checks device info
check_info() {
list_devices
if $MOCK_MODE; then
vendor="FakeVendor"; model="FlashTruthMock"
serial="MOCK123456789"; serial_short="MOCK123"
fs="vfat"; size_gb="16.0"; points=9
else
dev=$(df "$mount_path" | tail -1 | awk '{print $1}')
base_dev=$(lsblk -no PKNAME "$dev" 2>/dev/null)
dev="/dev/$base_dev"
info=$(udevadm info --query=all --name="$dev")
vendor=$(echo "$info" | grep ID_VENDOR= | cut -d= -f2)
model=$(echo "$info" | grep ID_MODEL= | cut -d= -f2)
serial=$(echo "$info" | grep ID_SERIAL= | cut -d= -f2)
serial_short=$(echo "$info" | grep ID_SERIAL_SHORT= | cut -d= -f2)
fs=$(lsblk -no FSTYPE "$dev" | head -n1)
fs=${fs:-"Desconhecido"}
size_bytes=$(LC_ALL=C lsblk -bno SIZE "$dev" | head -n1 | tr -d '[:space:]')
if [[ "$size_bytes" =~ ^[0-9]+$ ]]; then
size_gb=$(LC_ALL=C awk -v bytes="$size_bytes" 'BEGIN { printf "%.1f", bytes / 1073741824 }')
else
size_gb="0.0"
fi
points=0
[[ "$vendor" && ! "$vendor" =~ (Generic|Unknown) ]] && ((points+=2))
[[ "$model" && ! "$model" =~ (USB_DISK|Mass_Storage) ]] && ((points+=2))
[[ "$serial" ]] && ((points+=2))
[[ "$serial_short" ]] && ((points+=1))
[[ "$fs" =~ ^(vfat|exfat|ext4|ntfs|iso9660)$ ]] && ((points+=1))
if (( $(echo "$size_gb >= 8" | bc -l) )); then ((points+=2)); fi
fi
if ((points>=9)); then
status=$(translate status_high)
elif ((points>=6)); then
status=$(translate status_moderate)
else
status=$(translate status_low)
fi
echo ""; echo -e "${GREEN}[+] $(translate scanning) $mount_path${NC}"
echo "Modelo: $model"; echo "Fabricante: $vendor"
echo "Serial: $serial"; echo "Filesystem: $fs"
echo "Tamanho: ${size_gb}GB"
echo -e "${YELLOW}Confiabilidade: $points/10 $status${NC}"
report_prefix="$(translate report_prefix)"
dt=$(date "+%Y-%m-%d_%H%M")
file="${report_prefix}_${dt}.txt"
{
echo "$(translate report_device) $mount_path"
echo "$(translate report_manufacturer) $vendor"
echo "$(translate report_model) $model"
echo "$(translate report_serial) $serial"
echo "$(translate report_filesystem) $fs"
echo "$(translate report_size) $size_gb GB"
echo "$(translate report_reliability) $points/10 $status"
} > "$file"
echo -e "${GREEN}$(translate saved_report) $file${NC}"
read -r -p "$(translate press_enter)"
}
# Tests the drive with f3
test_drive() {
sudo apt install -y f3 &>/dev/null
list_devices
files=$(find "$mount_path" -mindepth 1 | wc -l)
if [ "$files" -gt 0 ]; then
echo -e "${RED}[!] $(translate files_found "$files")${NC}"
read -r -p "$(translate confirm_format) " c
[[ "$c" =~ ^[sSyY]$ ]] && format_drive
fi
f3write "$mount_path"; f3read "$mount_path"
read -r -p "$(translate remove_temp) " c
[[ "$c" =~ ^[sSyY]$ ]] && rm -f "$mount_path"/*.h2w "$mount_path"/.f3* &>/dev/null
read -r -p "$(translate press_enter)"
}
# Main menu function
main_menu() {
while true; do
clear; print_banner
echo -e "${YELLOW}$(translate select_option)${NC}"
echo "[1] $(translate menu1)"; echo "[2] $(translate menu2)"; echo "[0] $(translate menu0)"
echo ""; read -r -p "$(translate prompt_option)" o
case $o in
1) check_info ;;
2) test_drive ;;
0) echo -e "${GREEN}$(translate exiting)${NC}"; exit 0 ;;
*)
echo -e "${RED}$(translate invalid_option)${NC}"
sleep 1 ;;
esac
done
}
# Direct mock-check
if $RUN_CHECK; then
check_info
exit 0
fi
# Entry point
main_menu