Skip to content

Commit 759f0bb

Browse files
authored
fix(checksum-sort): update example usage and improve sorting functionality (#647)
* fix(checksum-sort): update example usage and improve sorting functionality - Changed example usage in error messages to reflect the correct filter file. - Simplified temporary file naming for consistency. - Enhanced sorting functionality to utilize Rust-based FOP CLI, with error handling for missing dependencies. - Improved logging for sorting process and error messages. These changes streamline the script's functionality and improve user guidance. * fix(checksum-sort): update example usage in error messages - Changed example filter file in usage messages from 'combined-filters.txt' to 'ultralist.txt' for accuracy. - Updated help message examples to reflect the correct usage of the script. These changes enhance user guidance and ensure clarity in script usage.
1 parent 02125e3 commit 759f0bb

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

scripts/checksum-sort.sh

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -152,34 +152,39 @@ add_checksum() {
152152
log_info "📝 Checksum: $checksum"
153153
}
154154

155-
# Sort the filter file (sort filter rules while preserving header)
155+
# Sort the filter file using FOP CLI
156156
sort_filter() {
157157
local file="$1"
158-
local temp_file="$file.tmp.$$"
159-
local header_end=0
160-
local line_num=0
161-
162-
# Find where header ends (first non-comment line)
163-
while IFS= read -r line; do
164-
line_num=$((line_num + 1))
165-
if [[ ! "$line" =~ ^'!' ]] && [[ -n "$line" ]]; then
166-
header_end=$line_num
167-
break
168-
fi
169-
done <"$file"
170-
171-
if [[ $header_end -eq 0 ]]; then
172-
# No filter rules, just return
173-
return
174-
fi
175-
176-
# Extract header (lines before first filter rule)
177-
head -n $((header_end - 1)) "$file" >"$temp_file"
178158

179-
# Sort and append filter rules (skip empty lines at start of content)
180-
tail -n +"$header_end" "$file" | sort -u >>"$temp_file"
159+
log_info "🔀 Using FOP CLI to sort filter rules..."
181160

182-
mv "$temp_file" "$file"
161+
# Use the Rust-based FOP CLI (required)
162+
if command -v fop >/dev/null 2>&1; then
163+
log_info "🔀 Using Rust-based FOP CLI"
164+
if fop "$file" >/dev/null 2>&1; then
165+
log_info "✅ FOP CLI sorting completed successfully"
166+
return
167+
else
168+
log_error "❌ FOP CLI encountered errors while processing the file"
169+
log_error "❌ Please check the FOP CLI installation and try again"
170+
exit 1
171+
fi
172+
elif command -v fop-cli >/dev/null 2>&1; then
173+
log_info "🔀 Using FOP CLI (fop-cli)"
174+
if fozp-cli "$file" >/dev/null 2>&1; then
175+
log_info "✅ FOP CLI sorting completed successfully"
176+
return
177+
else
178+
log_error "❌ FOP CLI encountered errors while processing the file"
179+
log_error "❌ Please check the FOP CLI installation and try again"
180+
exit 1
181+
fi
182+
else
183+
log_error "❌ FOP CLI not found"
184+
log_error "❌ Please install the Rust-based FOP CLI from https://github.com/ryanbr/fop-rs"
185+
log_error "❌ This script requires FOP CLI and will not fall back to other sorting methods"
186+
exit 1
187+
fi
183188
}
184189

185190
# Process the filter file

0 commit comments

Comments
 (0)