<commit_before>#!/bin/bash
# Fix sum for a package file that is reported wrong by debsums.
# Take the sum of the file on the filesystem as a reference and override the
# sum saved for the package. Most of the time it is because of docs or other
# non-sensitive files. If it is a binary or script, you better investigate.
# -- StalkR

PKGINFO="/var/lib/dpkg/info"

main() {
  local FILE NEWSUM LIST SUMS FILENOROOT OLDSUM
  if [ $# -lt 1 ]; then
    echo "Usage: $0 <file>"
    exit 1
  fi
  FILE=$1
  
  NEWSUM=$(md5sum "$FILE" | cut -d' ' -f1)
  LIST=$(grep -Hrl "$FILE" "$PKGINFO")
  [ -z "$LIST" ] && error "File not found in any package."
  [ $(echo "$LIST" | wc -l) -ne 1 ] && error "Multiple matches for this file."
  SUMS=${LIST%.*}.md5sums
  [ ! -f "$SUMS" ] && error "No $SUMS file."
  # files do not have the / at the beginning
  FILENOROOT=${FILE#/*}
  OLDSUM=$(grep "$FILENOROOT" "$SUMS" | cut -d' ' -f1)
  [ -z "$OLDSUM" ] && error "Cannot find file in sums file $SUMS."
  [ $(echo "$OLDSUM" | wc -l) -ne 1 ] && error "Multiple sums for this file?"
  [ "$OLDSUM" == "$NEWSUM" ] && error "Sums are the same."
  sed -i "s#$OLDSUM  \(.*\)#$NEWSUM  \1#" "$SUMS"
  echo "Sums updated."
}

error() {
  echo "Error: $@" >&2
  exit 1
}

if [ "${BASH_SOURCE[0]}" == "$0" ]; then
  main "$@"
fi
<commit_msg>debsums_fix.sh: fix matching bug, replace grep+cut with sed, error message prepares manual command<commit_after>#!/bin/bash
# Fix sum for a package file that is reported wrong by debsums.
# Take the sum of the file on the filesystem as a reference and override the
# sum saved for the package. Most of the time it is because of docs or other
# non-sensitive files. If it is a binary or script, you better investigate.
# -- StalkR

PKGINFO="/var/lib/dpkg/info"

main() {
  local FILE NEWSUM LIST SUMS FILENOROOT OLDSUM
  if [ $# -lt 1 ]; then
    echo "Usage: $0 <file>"
    exit 1
  fi
  FILE=$1

  NEWSUM=$(md5sum "$FILE" | cut -d' ' -f1)
  LIST=$(grep -Hrl "^$FILE\$" "$PKGINFO")
  [ -z "$LIST" ] && error "File not found in any package."
  [ $(echo "$LIST" | wc -l) -ne 1 ] && \
    error "Multiple matches for this file." \
          "See: grep -Hr \"$FILE\" \"$PKGINFO\""
  SUMS=${LIST%.*}.md5sums
  [ ! -f "$SUMS" ] && error "No $SUMS file."
  # files do not have the / at the beginning
  FILENOROOT=${FILE#/*}
  OLDSUM=$(sed -n "s#\([0-9a-f]\{32\}\)  $FILENOROOT\$#\1#p" "$SUMS")
  [ -z "$OLDSUM" ] && error "Cannot find file in sums file $SUMS."
  [ $(echo "$OLDSUM" | wc -l) -ne 1 ] && \
    error "Multiple sums for this file?" \
          "See: grep \"$FILENOROOT\" \"$SUMS\""
  [ "$OLDSUM" == "$NEWSUM" ] && error "Sums are the same."
  sed -i "s#$OLDSUM  \(.*\)#$NEWSUM  \1#" "$SUMS"
  echo "Sums updated."
}

error() {
  echo "Error: $@" >&2
  exit 1
}

if [ "${BASH_SOURCE[0]}" == "$0" ]; then
  main "$@"
fi


{'fraction_non_alphanumeric': 0.1837742504409171, 'fraction_numerical': 0.01199294532627866, 'mean_word_length': 2.9117241379310346, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5272110', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1089, 'n_words': 382}