testsAndMisc-archive/linux_configuration/scripts/single_use/utils/lib/plagiarism_sherlock.sh
Krzysztof kuhy Rudnicki e47c72329a install_plagiarism_tools.sh: split 534 -> 94 + 3 libs, with a real test harness
Wraps the four install stages into named functions, one per lib/plagiarism_*.sh
sibling (matching install_exercism.sh's convention), and extracts the two
embedded Python heredocs into real, lint-clean check_plagiarism.py/sherlock.py
files -- check_plagiarism.py needed a second split into plagiarism_similarity.py
to also clear the 250-line cap. Every function reaches 100% shell coverage via
a PATH-shim test harness (fake python3/pip/git/java/wine); the two Python CLIs
were separately verified against a real venv with actual nltk/scikit-learn.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
2026-08-18 20:41:18 +02:00

41 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Stage 2: Sherlock text plagiarism detector.
#
# Sourced by install_plagiarism_tools.sh; split out to keep it under the
# 250-line cap. Sourced rather than run, so it inherits the caller's strict
# mode and the color/log helpers and INSTALL_DIR global defined above the
# source line.
# Clone the upstream sherlock-py tool, falling back to the bundled
# sherlock.py (n-gram fingerprinting) when git or the clone is unavailable.
# $1 is the directory install_plagiarism_tools.sh lives in, so the fallback
# sherlock.py can be copied from beside it.
install_sherlock() {
local script_dir="$1"
echo ""
echo "=== 2. Installing Sherlock Text Plagiarism Detector ==="
local sherlock_dir="$INSTALL_DIR/sherlock"
if [ -d "$sherlock_dir" ]; then
warn "Sherlock already installed at $sherlock_dir"
return
fi
if ! command -v git &>/dev/null; then
warn "Git not available, skipping Sherlock installation"
return
fi
# There are several Sherlock implementations; using a popular Python one
if git clone --depth 1 https://github.com/Zedeldi/sherlock-py.git "$sherlock_dir" 2>/dev/null; then
success "Sherlock installed at $sherlock_dir"
return
fi
warn "Could not clone sherlock-py, trying alternative..."
mkdir -p "$sherlock_dir"
install -m 755 "$script_dir/sherlock.py" "$sherlock_dir/sherlock.py"
success "Sherlock installed at $sherlock_dir"
}