<commit_before>#!/bin/bash

###   This script attempts to download the signature file SHA256SUMS.asc from terracoin.io
###   It first checks if the signature passes, and then downloads the files specified in
###   the file, and checks if the hashes of these files match those that are specified
###   in the signature file.
###   The script returns 0 if everything passes the checks. It returns 1 if either the
###   signature check or the hash check doesn't pass. If an error occurs the return value is 2

function clean_up {
   for file in $*
   do
      rm "$file" 2> /dev/null
   done
}

WORKINGDIR="/tmp/terracoin"
TMPFILE="hashes.tmp"

SIGNATUREFILENAME="SHA256SUMS.asc"
RCSUBDIR="test/"
BASEDIR="https://terracoin.io/bin/"
VERSIONPREFIX="terracoin-core-"
RCVERSIONSTRING="rc"

#this URL is used if a version number is not specified as an argument to the script
SIGNATUREFILE="$BASEDIR""$VERSIONPREFIX""0.12.2.4/""$RCSUBDIR""$SIGNATUREFILENAME"

if [ ! -d "$WORKINGDIR" ]; then
   mkdir "$WORKINGDIR"
fi

cd "$WORKINGDIR"

#test if a version number has been passed as an argument
if [ -n "$1" ]; then
   #let's also check if the version number includes the prefix 'terracoin-',
   #  and add this prefix if it doesn't
   if [[ $1 == "$VERSIONPREFIX"* ]]; then
      VERSION="$1"
   else
      VERSION="$VERSIONPREFIX$1"
   fi

   #now let's see if the version string contains "rc", and strip it off if it does
   #  and simultaneously add RCSUBDIR to BASEDIR, where we will look for SIGNATUREFILENAME
   if [[ $VERSION == *"$RCVERSIONSTRING"* ]]; then
      BASEDIR="$BASEDIR${VERSION/%-$RCVERSIONSTRING*}/"
      BASEDIR="$BASEDIR$RCSUBDIR"
   else
      BASEDIR="$BASEDIR$VERSION/"
   fi

   SIGNATUREFILE="$BASEDIR$SIGNATUREFILENAME"
else
   BASEDIR="${SIGNATUREFILE%/*}/"
fi

#first we fetch the file containing the signature
WGETOUT=$(wget -N "$BASEDIR$SIGNATUREFILENAME" 2>&1)

#and then see if wget completed successfully
if [ $? -ne 0 ]; then
   echo "Error: couldn't fetch signature file. Have you specified the version number in the following format?"
   echo "[$VERSIONPREFIX]<version>-[$RCVERSIONSTRING[0-9]] (example: "$VERSIONPREFIX"0.12.2.4-"$RCVERSIONSTRING"1)"
   echo "wget output:"<commit_msg>Update yml files to 0.12.2.5<commit_after>#!/bin/bash

###   This script attempts to download the signature file SHA256SUMS.asc from terracoin.io
###   It first checks if the signature passes, and then downloads the files specified in
###   the file, and checks if the hashes of these files match those that are specified
###   in the signature file.
###   The script returns 0 if everything passes the checks. It returns 1 if either the
###   signature check or the hash check doesn't pass. If an error occurs the return value is 2

function clean_up {
   for file in $*
   do
      rm "$file" 2> /dev/null
   done
}

WORKINGDIR="/tmp/terracoin"
TMPFILE="hashes.tmp"

SIGNATUREFILENAME="SHA256SUMS.asc"
RCSUBDIR="test/"
BASEDIR="https://terracoin.io/bin/"
VERSIONPREFIX="terracoin-core-"
RCVERSIONSTRING="rc"

#this URL is used if a version number is not specified as an argument to the script
SIGNATUREFILE="$BASEDIR""$VERSIONPREFIX""0.12.2.5/""$RCSUBDIR""$SIGNATUREFILENAME"

if [ ! -d "$WORKINGDIR" ]; then
   mkdir "$WORKINGDIR"
fi

cd "$WORKINGDIR"

#test if a version number has been passed as an argument
if [ -n "$1" ]; then
   #let's also check if the version number includes the prefix 'terracoin-',
   #  and add this prefix if it doesn't
   if [[ $1 == "$VERSIONPREFIX"* ]]; then
      VERSION="$1"
   else
      VERSION="$VERSIONPREFIX$1"
   fi

   #now let's see if the version string contains "rc", and strip it off if it does
   #  and simultaneously add RCSUBDIR to BASEDIR, where we will look for SIGNATUREFILENAME
   if [[ $VERSION == *"$RCVERSIONSTRING"* ]]; then
      BASEDIR="$BASEDIR${VERSION/%-$RCVERSIONSTRING*}/"
      BASEDIR="$BASEDIR$RCSUBDIR"
   else
      BASEDIR="$BASEDIR$VERSION/"
   fi

   SIGNATUREFILE="$BASEDIR$SIGNATUREFILENAME"
else
   BASEDIR="${SIGNATUREFILE%/*}/"
fi

#first we fetch the file containing the signature
WGETOUT=$(wget -N "$BASEDIR$SIGNATUREFILENAME" 2>&1)

#and then see if wget completed successfully
if [ $? -ne 0 ]; then
   echo "Error: couldn't fetch signature file. Have you specified the version number in the following format?"
   echo "[$VERSIONPREFIX]<version>-[$RCVERSIONSTRING[0-9]] (example: "$VERSIONPREFIX"0.12.2.5-"$RCVERSIONSTRING"1)"
   echo "wget output:"
{'fraction_non_alphanumeric': 0.11840035946978207, 'fraction_numerical': 0.014603459896652437, 'mean_word_length': 4.0590909090909095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7229168', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1429, 'n_words': 503}