-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysical.sh
More file actions
executable file
·96 lines (81 loc) · 2.51 KB
/
physical.sh
File metadata and controls
executable file
·96 lines (81 loc) · 2.51 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
#!/usr/bin/env bash
AUTHORIZED_BY_SETUP=$1
if [[ "$AUTHORIZED_BY_SETUP" != "yes" ]]; then
echo "Error: physical.sh can only be run via setup.sh!"
exit 1
fi
set -euo pipefail
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LANG_FILE="$SCRIPT_ROOT/languages.txt"
LANG_CHOICE="${1:-EN}"
msg() {
local key="$1"
local col
case "$LANG_CHOICE" in
EN) col=2 ;;
UZ) col=3 ;;
RU) col=4 ;;
*) col=2 ;;
esac
awk -F'|' -v k="$key" -v c="$col" '$1==k {print $c}' "$LANG_FILE"
}
choose_path() {
local current_dir="$1"
while true; do
local entries=()
for item in "$current_dir"/*; do
[[ -d "$item" ]] && entries+=("📁 $(basename "$item")")
[[ -f "$item" ]] && entries+=("📄 $(basename "$item")")
done
if [[ ${#entries[@]} -eq 0 ]]; then
echo "❌ $(msg empty): $current_dir"
return
fi
echo -e "\n📂 $(msg current): $current_dir"
echo "0) $(msg back)"
local i=1
for e in "${entries[@]}"; do
echo "$i) $e"
((i++))
done
read -rp "> $(msg choose): " num
[[ "$num" =~ ^[0-9]+$ ]] || { echo "$(msg number_err)"; continue; }
if (( num == 0 )); then
return
elif (( num >= 1 && num <= ${#entries[@]} )); then
local selected="${entries[$((num-1))]}"
local name
name=$(echo "$selected" | sed -E 's/^[^ ]+ //' )
local full="$current_dir/$name"
if [[ -d "$full" ]]; then
if [[ "$name" == "About malwares" ]]; then
local run_file="$full/run.sh"
if [[ -f "$run_file" ]]; then
bash "$run_file"
return
else
echo "❌ run.sh not found in $full"
return
fi
else
choose_path "$full"
continue
fi
elif [[ -f "$full" ]]; then
local target="$SCRIPT_ROOT/malwares"
mkdir -p "$target"
cp "$full" "$target/"
echo "✅ '$name' $(msg copied) $target/"
return
fi
else
echo "$(msg number_err)"
fi
done
}
START_DIR="$SCRIPT_ROOT/tools/physical"
if [[ ! -d "$START_DIR" ]]; then
echo "❌ $(msg start_notfound): $START_DIR"
exit 1
fi
choose_path "$START_DIR"