4
2
mirror of https://github.com/getbible/v2_builder.git synced 2024-06-05 07:00:46 +00:00

Formated the hash code with my IDE.

This commit is contained in:
Robot 2021-04-21 02:41:43 +00:00
parent a53aac8f37
commit 1a03831b50
No known key found for this signature in database
GPG Key ID: 5A920ED2DA4160A2
3 changed files with 132 additions and 145 deletions

View File

@ -1,14 +1,19 @@
#! /bin/bash
# Do some prep work
command -v jq >/dev/null 2>&1 || { echo >&2 "We require jq for this script to run, but it's not installed. Aborting."; exit 1; }
command -v sha1sum >/dev/null 2>&1 || { echo >&2 "We require sha1sum for this script to run, but it's not installed. Aborting."; exit 1; }
command -v jq >/dev/null 2>&1 || {
echo >&2 "We require jq for this script to run, but it's not installed. Aborting."
exit 1
}
command -v sha1sum >/dev/null 2>&1 || {
echo >&2 "We require sha1sum for this script to run, but it's not installed. Aborting."
exit 1
}
# make sure we have at least one argument
if [ $# -eq 0 ]
then
if [ $# -eq 0 ]; then
echo >&2 "Target folder must be supplied. Aborting."
exit 1;
exit 1
fi
# target folder
@ -17,10 +22,9 @@ target_folder="$1"
counter=0
# check if the folder exist
if [ ! -d $target_folder ]
then
echo >&2 "Folder $target_folder not found. Aborting.";
exit 1;
if [ ! -d $target_folder ]; then
echo >&2 "Folder $target_folder not found. Aborting."
exit 1
fi
for filename in $target_folder/*.json; do
@ -33,18 +37,15 @@ for filename in $target_folder/*.json; do
abbreviation="${filename/.json/}"
abbreviation="${abbreviation/${target_folder}\//}"
# do not work with the translations or checksum file
if [[ "$abbreviation" == 'translations' || "$abbreviation" == 'checksum' ]]
then
if [[ "$abbreviation" == 'translations' || "$abbreviation" == 'checksum' ]]; then
continue
fi
# do not work with the books or chapters file
if [[ "$abbreviation" == 'books' || "$abbreviation" == 'chapters' ]]
then
if [[ "$abbreviation" == 'books' || "$abbreviation" == 'chapters' ]]; then
continue
fi
# make sure the book directory is build
if [ -d "${target_folder}/$abbreviation" ]
then
if [ -d "${target_folder}/$abbreviation" ]; then
# load the translation in
bible=$(cat "${filename}" | jq '.' -a)
# get book numbers
@ -62,19 +63,16 @@ for filename in $target_folder/*.json; do
# checksum
checksumBucket="# filename sha\n"
# add more
next=$(($counter+15))
next=$((counter + 12))
# make sure next is not above 99
if (("$next" > 99))
then
if (("$next" > 99)); then
next=99
fi
counter_inner=$counter
# read book names
for nr in "${booknr[@]}";
do
for nr in "${booknr[@]}"; do
# check if file is set
if [ -f "${target_folder}/${abbreviation}/${nr}.json" ]
then
if [ -f "${target_folder}/${abbreviation}/${nr}.json" ]; then
# load the book in
book=$(cat "${target_folder}/${abbreviation}/${nr}.json" | jq '.' -a)
# update the file formatting
@ -101,8 +99,7 @@ for filename in $target_folder/*.json; do
# build query for jq
jq_query+=" | .[\$key${nr}]=\$value${nr}"
# check if we have counter upto next
if (("$counter_inner" >= "$next"))
then
if (("$counter_inner" >= "$next")); then
counter_inner=$counter
fi
# increment the counter
@ -119,8 +116,7 @@ for filename in $target_folder/*.json; do
jq "${jq_args[@]}" "$jq_query" <<<'{}' >"${target_folder}/${abbreviation}/checksum.json"
jq "${jq_t_args[@]}" "$jq_t_query" <<<'{}' >"${target_folder}/${abbreviation}/books.json"
# check if we have counter upto 98
if (("$counter" >= 98))
then
if (("$counter" >= 98)); then
counter=70
fi
# add more
@ -129,4 +125,3 @@ for filename in $target_folder/*.json; do
echo -e "XXX\n${counter}\nDone Hashing $abbreviation books\nXXX"
fi
done

View File

@ -1,14 +1,19 @@
#! /bin/bash
# Do some prep work
command -v jq >/dev/null 2>&1 || { echo >&2 "We require jq for this script to run, but it's not installed. Aborting."; exit 1; }
command -v sha1sum >/dev/null 2>&1 || { echo >&2 "We require sha1sum for this script to run, but it's not installed. Aborting."; exit 1; }
command -v jq >/dev/null 2>&1 || {
echo >&2 "We require jq for this script to run, but it's not installed. Aborting."
exit 1
}
command -v sha1sum >/dev/null 2>&1 || {
echo >&2 "We require sha1sum for this script to run, but it's not installed. Aborting."
exit 1
}
# make sure we have at least one argument
if [ $# -eq 0 ]
then
if [ $# -eq 0 ]; then
echo >&2 "Target folder must be supplied. Aborting."
exit 1;
exit 1
fi
# target folder
@ -17,10 +22,9 @@ target_folder="$1"
counter=0
# check if the folder exist
if [ ! -d $target_folder ]
then
echo >&2 "Folder $target_folder not found. Aborting.";
exit 1;
if [ ! -d $target_folder ]; then
echo >&2 "Folder $target_folder not found. Aborting."
exit 1
fi
for filename in $target_folder/*.json; do
@ -29,18 +33,15 @@ for filename in $target_folder/*.json; do
abbreviation="${abbreviation/${target_folder}\//}"
echo "$abbreviation"
# do not work with the translations or checksum file
if [[ "$abbreviation" == 'translations' || "$abbreviation" == 'checksum' ]]
then
if [[ "$abbreviation" == 'translations' || "$abbreviation" == 'checksum' ]]; then
continue
fi
# do not work with the books or chapters file
if [[ "$abbreviation" == 'books' || "$abbreviation" == 'chapters' ]]
then
if [[ "$abbreviation" == 'books' || "$abbreviation" == 'chapters' ]]; then
continue
fi
# make sure the book directory is build
if [ -d "${target_folder}/$abbreviation" ]
then
if [ -d "${target_folder}/$abbreviation" ]; then
# set language
language=$(cat "${filename}" | jq '.language' -r)
# set translation
@ -50,24 +51,21 @@ for filename in $target_folder/*.json; do
# get booknumbers
readarray -t booknr < <(cat "${filename}" | jq -r '.books[].nr')
# add more
next=$(($counter+15))
next=$((counter + 12))
# make sure next is not above 99
if (("$next" > 99))
then
if (("$next" > 99)); then
next=99
fi
counter_inner=$counter
# read book names
for nr in "${booknr[@]}";
do
for nr in "${booknr[@]}"; do
# setup: positional arguments to pass in literal variables, query with code
jq_args=()
jq_query='.'
jq_t_args=()
jq_t_query='.'
# check if file is set
if [ -f "${target_folder}/${abbreviation}/${nr}.json" ]
then
if [ -f "${target_folder}/${abbreviation}/${nr}.json" ]; then
# chapters details
chaptersBucket="# language translation abbreviation textdirection book_nr book_name filename sha\n"
# checksum
@ -77,11 +75,9 @@ for filename in $target_folder/*.json; do
# get all chapters
readarray -t chapters < <(cat "${target_folder}/${abbreviation}/${nr}.json" | jq -r '.chapters[].chapter' | sort -g)
# get chapters
for chapter in "${chapters[@]}";
do
for chapter in "${chapters[@]}"; do
# only build hash chapter for existing files
if [ -f "${target_folder}/${abbreviation}/${nr}/${chapter}.json" ]
then
if [ -f "${target_folder}/${abbreviation}/${nr}/${chapter}.json" ]; then
# get the hash
fileHash=$(sha1sum "${target_folder}/${abbreviation}/${nr}/${chapter}.json" | awk '{print $1}')
# load the book in
@ -102,8 +98,7 @@ for filename in $target_folder/*.json; do
# build query for jq
jq_query+=" | .[\$key${chapter}]=\$value${chapter}"
# check if we have counter upto next
if (("$counter_inner" >= "$next"))
then
if (("$counter_inner" >= "$next")); then
counter_inner=$counter
fi
# increment the counter
@ -122,8 +117,7 @@ for filename in $target_folder/*.json; do
fi
done
# check if we have counter upto 98
if (("$counter" >= 98))
then
if (("$counter" >= 98)); then
counter=70
fi
# add more
@ -132,4 +126,3 @@ for filename in $target_folder/*.json; do
echo -e "XXX\n${counter}\nDone Hashing $abbreviation chapters\nXXX"
fi
done

View File

@ -1,14 +1,19 @@
#! /bin/bash
# Do some prep work
command -v jq >/dev/null 2>&1 || { echo >&2 "We require jq for this script to run, but it's not installed. Aborting."; exit 1; }
command -v sha1sum >/dev/null 2>&1 || { echo >&2 "We require sha1sum for this script to run, but it's not installed. Aborting."; exit 1; }
command -v jq >/dev/null 2>&1 || {
echo >&2 "We require jq for this script to run, but it's not installed. Aborting."
exit 1
}
command -v sha1sum >/dev/null 2>&1 || {
echo >&2 "We require sha1sum for this script to run, but it's not installed. Aborting."
exit 1
}
# make sure we have at least one argument
if [ $# -eq 0 ]
then
if [ $# -eq 0 ]; then
echo >&2 "Target folder must be supplied. Aborting."
exit 1;
exit 1
fi
# setup: positional arguments to pass in literal variables, query with code
@ -26,10 +31,9 @@ target_folder="$1"
counter=0
# check if the folder exist
if [ ! -d $target_folder ]
then
echo >&2 "Folder $target_folder not found. Aborting.";
exit 1;
if [ ! -d $target_folder ]; then
echo >&2 "Folder $target_folder not found. Aborting."
exit 1
fi
# book names
@ -37,19 +41,16 @@ echo "# language translation abbreviation direction filename sha" > "${target_fo
# checksum
echo "# filename sha" >"${target_folder}/checksum"
for filename in $target_folder/*.json; do
# get the abbreviation
abbreviation="${filename/.json/}"
abbreviation="${abbreviation/${target_folder}\//}"
# do not work with the translations or checksum file
if [[ "$abbreviation" == 'translations' || "$abbreviation" == 'checksum' ]]
then
if [[ "$abbreviation" == 'translations' || "$abbreviation" == 'checksum' ]]; then
continue
fi
# do not work with the books or chapters file
if [[ "$abbreviation" == 'books' || "$abbreviation" == 'chapters' ]]
then
if [[ "$abbreviation" == 'books' || "$abbreviation" == 'chapters' ]]; then
continue
fi
# load the translation in
@ -85,8 +86,7 @@ for filename in $target_folder/*.json; do
#next
nr=$((nr + 1))
# check if we have counter upto 98
if (("$counter" >= 98))
then
if (("$counter" >= 98)); then
counter=70
fi
# add more
@ -98,4 +98,3 @@ done
# run the generated command with jq
jq "${jq_args[@]}" "$jq_query" <<<'{}' >"${target_folder}/checksum.json"
jq "${jq_t_args[@]}" "$jq_t_query" <<<'{}' >"${target_folder}/translations.json"