Skip to content

Instantly share code, notes, and snippets.

@EtaCassiopeia
Last active April 4, 2025 16:27
Show Gist options
  • Save EtaCassiopeia/00cd4e1458564572466a0a694721f400 to your computer and use it in GitHub Desktop.
Save EtaCassiopeia/00cd4e1458564572466a0a694721f400 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Path to your Hercules.properties file
PROPERTIES_FILE="Hercules.properties"
# Temporary files
SBT_OUTPUT="sbt_update_output.txt"
PROPERTIES_DEPS="properties_deps.txt"
SBT_DEPS="sbt_deps.txt"
# Function to extract and clean DEPENDENCIES from Hercules.properties
extract_properties_deps() {
if [ ! -f "$PROPERTIES_FILE" ]; then
echo "Error: $PROPERTIES_FILE not found!"
exit 1
fi
# Extract DEPENDENCIES block, remove quotes, and clean URLs
sed -n '/^DEPENDENCIES="/,/"/p' "$PROPERTIES_FILE" | \
grep '^http' | \
tr -d '\\' | \
tr ',' '\n' | \
grep -v '^$' | \
sort > "$PROPERTIES_DEPS"
}
# Function to run sbt and extract dependency URLs
extract_sbt_deps() {
echo "Running 'sbt show update' to fetch resolved dependencies..."
sbt "show update" > "$SBT_OUTPUT" 2>/dev/null
if [ ! -f "$SBT_OUTPUT" ]; then
echo "Error: Failed to generate sbt output!"
exit 1
fi
# Extract full URLs from sbt update output
grep -oE 'Some\(https://[^)]+\.jar\)' "$SBT_OUTPUT" | \
sed 's/Some(//;s/)$//' | \
sort | \
uniq > "$SBT_DEPS"
}
# Function to compare dependencies
compare_deps() {
echo "Comparing dependencies from $PROPERTIES_FILE with sbt update..."
# Missing in sbt (present in properties but not in sbt)
echo -e "\nDependencies missing in sbt update (present in $PROPERTIES_FILE):"
comm -23 "$PROPERTIES_DEPS" "$SBT_DEPS" | \
while read -r line; do
[ -n "$line" ] && echo "$line" || echo "None"
done
# Missing in properties (present in sbt but not in properties)
echo -e "\nDependencies missing in $PROPERTIES_FILE (present in sbt update):"
comm -13 "$PROPERTIES_DEPS" "$SBT_DEPS" | \
while read -r line; do
[ -n "$line" ] && echo "$line" || echo "None"
done
}
# Function to clean up temporary files
cleanup() {
rm -f "$PROPERTIES_DEPS" "$SBT_DEPS" "$SBT_OUTPUT"
}
# Main execution
main() {
if ! command -v sbt >/dev/null 2>&1; then
echo "Error: sbt is not installed or not in PATH!"
exit 1
fi
extract_properties_deps
extract_sbt_deps
compare_deps
cleanup
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment