-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVERIFY.sh
More file actions
executable file
·171 lines (147 loc) · 5.46 KB
/
VERIFY.sh
File metadata and controls
executable file
·171 lines (147 loc) · 5.46 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
#!/bin/bash
# ============================================================================
# Metetch File Verification Script
# Copyright (c) 2025 techoraye
# Licensed under the MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
# ============================================================================
set -e
# ============================================================================
# Colors - Synchronized with include/colors.h
# ============================================================================
RED='\033[0;31m' # STATUS_CRIT color
GREEN='\033[0;32m' # STATUS_OK variant
YELLOW='\033[1;33m' # BOLD_YELLOW - used for emphasis
BLUE='\033[0;34m' # Blue standard
CYAN='\033[1;36m' # Bold cyan
NC='\033[0m' # No Color (RESET)
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
print_header() {
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║${NC} ${YELLOW}🔒 METETCH FILE VERIFICATION 🔒${NC} ${BLUE}║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
}
print_check() {
echo -e "${GREEN}✓${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
detect_distro() {
# Detect Flatpak runtime
if [ -n "$FLATPAK_ID" ] || [ -f "/.flatpak-info" ]; then
echo "flatpak"
return
fi
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "${ID}"
elif command -v lsb_release &> /dev/null; then
lsb_release -si | tr '[:upper:]' '[:lower:]'
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
echo "${DISTRIB_ID}" | tr '[:upper:]' '[:lower:]'
else
echo "unknown"
fi
}
verify_checksums() {
echo ""
echo -e "${BLUE}Verifying file integrity...${NC}"
echo ""
cd "$SCRIPT_DIR"
if [ ! -f "CHECKSUMS.sha256" ]; then
print_error "CHECKSUMS.sha256 not found!"
exit 1
fi
# Try different sha256sum commands based on what's available
local sha_cmd=""
if command -v sha256sum &> /dev/null; then
sha_cmd="sha256sum"
elif command -v shasum &> /dev/null; then
sha_cmd="shasum -a 256"
elif command -v sha256 &> /dev/null; then
# BSD sha256
sha_cmd="sha256"
else
print_error "No SHA256 checksum tool found (sha256sum, shasum, or sha256)"
exit 1
fi
print_info "Using checksum tool: $sha_cmd"
local failed=0
while IFS= read -r line; do
if [ -z "$line" ]; then
continue
fi
# Parse checksum line (format: "hash filename" or "filename = hash")
local hash filename
if [[ "$line" =~ ^([a-f0-9]+)[[:space:]]+(.+)$ ]]; then
hash="${BASH_REMATCH[1]}"
filename="${BASH_REMATCH[2]}"
elif [[ "$line" =~ ^(.+)[[:space:]]*=[[:space:]]*([a-f0-9]+)$ ]]; then
filename="${BASH_REMATCH[1]}"
hash="${BASH_REMATCH[2]}"
else
continue
fi
if [ ! -f "$filename" ]; then
print_error "File not found: $filename"
failed=1
continue
fi
# Calculate hash based on tool available
local computed_hash
if [ "$sha_cmd" = "sha256sum" ]; then
computed_hash=$(sha256sum "$filename" | awk '{print $1}')
elif [ "$sha_cmd" = "shasum -a 256" ]; then
computed_hash=$(shasum -a 256 "$filename" | awk '{print $1}')
elif [ "$sha_cmd" = "sha256" ]; then
# BSD sha256
computed_hash=$(sha256 -q "$filename")
fi
if [ "$computed_hash" = "$hash" ]; then
print_check "$filename"
else
print_error "$filename (hash mismatch)"
failed=1
fi
done < CHECKSUMS.sha256
if [ $failed -eq 0 ]; then
echo ""
print_check "All files verified successfully!"
return 0
else
echo ""
print_error "Checksum verification FAILED!"
print_warning "One or more files have been modified or corrupted"
exit 1
fi
}
main() {
print_header
verify_checksums
echo ""
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║${NC} ${YELLOW}✓ Verification Successful ✓${NC} ${GREEN}║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════╝${NC}"
echo ""
}
main "$@"