2021-04-20 00:38:47 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
# Do some prep work
|
2021-04-20 22:08:00 +00:00
|
|
|
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 git >/dev/null 2>&1 || {
|
|
|
|
echo >&2 "We require git for this script to run, but it's not installed. Aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
command -v whiptail >/dev/null 2>&1 || {
|
|
|
|
echo >&2 "We require whiptail for this script to run, but it's not installed. Aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
command -v python3 >/dev/null 2>&1 || {
|
|
|
|
echo >&2 "We require python3 for this script to run, but it's not installed. Aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-04-21 02:26:16 +00:00
|
|
|
# get start time
|
|
|
|
STARTBUILD=$(date +"%s")
|
|
|
|
# use UTC+00:00 time also called zulu
|
|
|
|
STARTDATE=$(TZ=":ZULU" date +"%m/%d/%Y @ %R (UTC)")
|
2021-04-20 22:08:00 +00:00
|
|
|
# main project Header
|
|
|
|
HEADERTITLE="getBible JSON API.v2"
|
|
|
|
|
|
|
|
# main function ˘Ô≈ôﺣ
|
|
|
|
function main() {
|
|
|
|
# Only Hash existing scripture JSON files
|
|
|
|
if (("$HASHONLY" == 1)); then
|
2021-04-21 04:09:09 +00:00
|
|
|
# numbers
|
|
|
|
number=$(ls "${DIR_zip}" | wc -l)
|
|
|
|
each_count=$((98 / number))
|
2021-04-20 22:08:00 +00:00
|
|
|
# the hashing of all files
|
2021-04-21 04:09:09 +00:00
|
|
|
hashingAll "${each_count:-1}"
|
2021-04-21 02:26:16 +00:00
|
|
|
# show completion message
|
|
|
|
completedBuildMessage
|
2021-04-20 22:08:00 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
# download Crosswire modules
|
|
|
|
if (("$DOWNLOAD" == 1)); then
|
2021-04-20 00:38:47 +00:00
|
|
|
getModules "${DIR_zip}"
|
|
|
|
fi
|
|
|
|
# numbers
|
|
|
|
number=$(ls "${DIR_zip}" | wc -l)
|
2021-04-21 04:09:09 +00:00
|
|
|
each_count=$((98 / number))
|
|
|
|
# prep the Scripture Main Git Folder
|
|
|
|
prepScriptureMainGit "${DIR_api}_scripture"
|
2021-04-20 00:38:47 +00:00
|
|
|
# Build Static JSON Files
|
2021-04-21 04:09:09 +00:00
|
|
|
setStaticJsonFiles "${DIR_api}_scripture" "${DIR_zip}" "${each_count:-1}"
|
2021-04-20 00:38:47 +00:00
|
|
|
# Remove Empty Folder & Static Files
|
|
|
|
cleanSystem "${DIR_api}_scripture"
|
2021-04-20 22:08:00 +00:00
|
|
|
# the hashing of all files
|
2021-04-21 04:09:09 +00:00
|
|
|
hashingAll "${each_count:-1}"
|
2021-04-20 00:38:47 +00:00
|
|
|
# finally check if we must commit and push changes
|
2021-04-20 22:08:00 +00:00
|
|
|
if (("$PUSH" == 1)); then
|
2021-04-20 00:38:47 +00:00
|
|
|
"${DIR_src}/moveToGithub.sh" "${DIR_api}"
|
|
|
|
fi
|
2021-04-21 02:26:16 +00:00
|
|
|
# show completion message
|
|
|
|
completedBuildMessage
|
|
|
|
|
|
|
|
exit 0
|
2021-04-20 00:38:47 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 02:26:16 +00:00
|
|
|
# completion message
|
|
|
|
function completedBuildMessage() {
|
|
|
|
# set the build time
|
|
|
|
ENDBUILD=$(date +"%s")
|
|
|
|
SECONDSBUILD=$((ENDBUILD - STARTBUILD))
|
|
|
|
# use UTC+00:00 time also called zulu
|
|
|
|
ENDDATE=$(TZ=":ZULU" date +"%m/%d/%Y @ %R (UTC)")
|
|
|
|
# give completion message
|
2021-04-20 22:08:00 +00:00
|
|
|
if (("$QUIET" == 0)); then
|
2021-04-21 02:26:16 +00:00
|
|
|
whiptail --title "${HEADERTITLE}" --separate-output --infobox "${USER^}, the ${HEADERTITLE} build is complete!\n\n Started: ${STARTDATE}\n Ended: ${ENDDATE}\nBuild Time: ${SECONDSBUILD} seconds" 12 77
|
2021-04-21 21:52:21 +00:00
|
|
|
sleep 10
|
2021-04-21 02:26:16 +00:00
|
|
|
else
|
|
|
|
echo "${HEADERTITLE} build on ${STARTDATE} is completed in ${SECONDSBUILD} seconds!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# show the progress of all tasks
|
|
|
|
function showProgress() {
|
|
|
|
if (("$QUIET" == 0)); then
|
2021-04-21 04:09:09 +00:00
|
|
|
# little nerdy ᒡ◯ᵔ◯ᒢ
|
2021-04-20 22:08:00 +00:00
|
|
|
whiptail --title "$1" --gauge "$2" 7 77 0
|
2021-04-21 02:26:16 +00:00
|
|
|
else
|
|
|
|
# looking for a better solution... ¯\_(ツ)_/¯
|
|
|
|
whiptail --title "$1" --gauge "$2" 7 77 0 >>/dev/null
|
2021-04-20 22:08:00 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# download Crosswire modules
|
|
|
|
function getModules() {
|
2021-04-20 00:38:47 +00:00
|
|
|
# set local values
|
|
|
|
local modules_path="$1"
|
2021-04-20 22:08:00 +00:00
|
|
|
# we first delete the old modules
|
2021-04-21 04:09:09 +00:00
|
|
|
rm -fr "${modules_path}"
|
|
|
|
mkdir -p "${modules_path}"
|
2021-04-23 03:50:33 +00:00
|
|
|
# run in github action workflow... ¯\_(ツ)_/¯
|
|
|
|
if (("$GITHUB" == 1)); then
|
2021-04-25 01:41:17 +00:00
|
|
|
echo "Start download of modules..."
|
|
|
|
python3 "${DIR_src}/download.py" \
|
|
|
|
--output_path "${modules_path}" \
|
|
|
|
--bible_conf "${DIR_bible}" >>/dev/null
|
|
|
|
echo "Done downloading modules..."
|
2021-04-23 03:50:33 +00:00
|
|
|
else
|
|
|
|
# then we get the current modules
|
|
|
|
{
|
|
|
|
sleep 1
|
|
|
|
echo -e "XXX\n0\nStart download of modules... \nXXX"
|
|
|
|
sleep 1
|
|
|
|
python3 -u "${DIR_src}/download.py" \
|
|
|
|
--output_path "${modules_path}" \
|
|
|
|
--bible_conf "${DIR_bible}"
|
|
|
|
sleep 1
|
|
|
|
echo -e "XXX\n100\nDone downloading modules... \nXXX"
|
|
|
|
sleep 2
|
|
|
|
} | showProgress "Get Crosswire Modules | ${HEADERTITLE}" "Please wait while we download all modules"
|
|
|
|
fi
|
2021-04-20 00:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# prep the Scripture Main Git Folder
|
2021-04-20 22:08:00 +00:00
|
|
|
function prepScriptureMainGit() {
|
2021-04-20 00:38:47 +00:00
|
|
|
# set local values
|
|
|
|
local scripture_path="$1"
|
2021-04-25 01:41:17 +00:00
|
|
|
local pull="$PULL"
|
2021-04-20 00:38:47 +00:00
|
|
|
# if git folder does not exist clone it
|
2021-04-21 04:09:09 +00:00
|
|
|
if [ ! -d "${scripture_path}" ]; then
|
2021-04-25 01:41:17 +00:00
|
|
|
# check if we must pull the REPO
|
|
|
|
if (("$pull" == 1)); then
|
|
|
|
# pull the main scripture repository
|
|
|
|
git clone --depth 1 "${REPOSCRIPTURE}" "${scripture_path}"
|
|
|
|
# pull only once
|
|
|
|
pull=0
|
|
|
|
else
|
|
|
|
# create the git folder (for scripture)
|
|
|
|
mkdir -p "${scripture_path}"
|
|
|
|
fi
|
2021-04-20 00:38:47 +00:00
|
|
|
fi
|
|
|
|
# reset the git folder on each run
|
2021-04-21 04:09:09 +00:00
|
|
|
if [ -d "${scripture_path}/.git" ]; then
|
2021-04-25 01:41:17 +00:00
|
|
|
# make a pull if needed still (update the git history)
|
|
|
|
if (("$pull" == 1)); then
|
|
|
|
cd "${scripture_path}" && git pull && cd -
|
|
|
|
fi
|
2021-04-20 00:38:47 +00:00
|
|
|
mkdir -p "${scripture_path}Tmp"
|
|
|
|
mv -f "${scripture_path}/.git" "${scripture_path}Tmp"
|
|
|
|
mv -f "${scripture_path}/.gitignore" "${scripture_path}Tmp"
|
|
|
|
|
|
|
|
# now we remove all the old git files (so we start clean each time in the build)
|
2021-04-21 04:09:09 +00:00
|
|
|
rm -fr "${scripture_path}"
|
2021-04-20 00:38:47 +00:00
|
|
|
mv -f "${scripture_path}Tmp" "${scripture_path}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-25 01:41:17 +00:00
|
|
|
# moving all public hash files
|
|
|
|
function movePublicHashFiles () {
|
|
|
|
# set local values
|
|
|
|
local scripture_path="$1"
|
|
|
|
local script_name="$2"
|
|
|
|
local w_title="$3"
|
|
|
|
local w_start_ms="$4"
|
|
|
|
local w_end_ms="$5"
|
|
|
|
local w_initial_ms="$6"
|
|
|
|
local each="$7"
|
|
|
|
# run in github action workflow... ¯\_(ツ)_/¯
|
|
|
|
if (("$GITHUB" == 1)); then
|
|
|
|
echo "$w_title | ${HEADERTITLE}"
|
|
|
|
echo "$w_initial_ms"
|
|
|
|
echo "${w_start_ms}..."
|
|
|
|
# now run the hashing
|
|
|
|
. "${DIR_src}/${script_name}.sh" "${scripture_path}" "$each" "$PULL" "${REPOHASH}" >>/dev/null
|
|
|
|
echo "${w_end_ms}..."
|
|
|
|
else
|
|
|
|
# now run the hashing
|
|
|
|
{
|
|
|
|
sleep 1
|
|
|
|
echo -e "XXX\n0\n${w_start_ms}... \nXXX"
|
|
|
|
sleep 1
|
|
|
|
. "${DIR_src}/${script_name}.sh" "${scripture_path}" "$each" "$PULL" "${REPOHASH}"
|
|
|
|
sleep 1
|
|
|
|
echo -e "XXX\n100\n${w_end_ms}... \nXXX"
|
|
|
|
sleep 1
|
|
|
|
} | showProgress "$w_title | ${HEADERTITLE}" "$w_initial_ms"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-20 00:38:47 +00:00
|
|
|
# Build Static JSON Files
|
2021-04-20 22:08:00 +00:00
|
|
|
function setStaticJsonFiles() {
|
2021-04-20 00:38:47 +00:00
|
|
|
# set local values
|
|
|
|
local scripture_path="$1"
|
|
|
|
local modules_path="$2"
|
2021-04-21 04:09:09 +00:00
|
|
|
local each="$3"
|
|
|
|
local counter=0
|
2021-04-23 03:50:33 +00:00
|
|
|
# run in github action workflow... ¯\_(ツ)_/¯
|
|
|
|
if (("$GITHUB" == 1)); then
|
|
|
|
echo "Start Building..."
|
2021-04-20 00:38:47 +00:00
|
|
|
for filename in $modules_path/*.zip; do
|
|
|
|
# give notice
|
2021-04-23 03:50:33 +00:00
|
|
|
echo "Building ${filename} static json files"
|
2021-04-20 00:38:47 +00:00
|
|
|
# run script
|
2021-04-23 03:50:33 +00:00
|
|
|
python3 "${DIR_src}/sword_to_json.py" \
|
2021-04-20 22:08:00 +00:00
|
|
|
--source_file "${filename}" \
|
|
|
|
--output_path "${scripture_path}" \
|
|
|
|
--conf_dir "${DIR_conf}" \
|
2021-04-23 03:50:33 +00:00
|
|
|
--bible_conf "${DIR_bible}" >>/dev/null
|
2021-04-20 00:38:47 +00:00
|
|
|
# give notice
|
2021-04-23 03:50:33 +00:00
|
|
|
echo "Done building ${filename} static json files..."
|
2021-04-20 00:38:47 +00:00
|
|
|
done
|
2021-04-23 03:50:33 +00:00
|
|
|
echo "Done Building..."
|
|
|
|
else
|
|
|
|
# build the files
|
|
|
|
{
|
|
|
|
sleep 1
|
|
|
|
echo -e "XXX\n0\nStart Building... \nXXX"
|
|
|
|
sleep 1
|
|
|
|
for filename in $modules_path/*.zip; do
|
|
|
|
# give notice
|
|
|
|
echo -e "XXX\n${counter}\nBuilding ${filename} static json files...\nXXX"
|
|
|
|
# add more
|
|
|
|
next=$((counter + each))
|
|
|
|
# run script
|
|
|
|
python3 -u "${DIR_src}/sword_to_json.py" \
|
|
|
|
--source_file "${filename}" \
|
|
|
|
--output_path "${scripture_path}" \
|
|
|
|
--counter "$counter" --next "$next" \
|
|
|
|
--conf_dir "${DIR_conf}" \
|
|
|
|
--bible_conf "${DIR_bible}"
|
|
|
|
# add more
|
|
|
|
counter="$next"
|
|
|
|
# give notice
|
|
|
|
echo -e "XXX\n${counter}\nDone building ${filename} static json files...\nXXX"
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo -e "XXX\n100\nDone Building... \nXXX"
|
|
|
|
sleep 1
|
|
|
|
} | showProgress "Build Static JSON Files | ${HEADERTITLE}" "Please wait while build the static json API"
|
|
|
|
fi
|
2021-04-20 00:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Remove Empty Folder & Static Files
|
2021-04-20 22:08:00 +00:00
|
|
|
function cleanSystem() {
|
2021-04-20 00:38:47 +00:00
|
|
|
# set local values
|
|
|
|
local scripture_path="$1"
|
|
|
|
# remove all empty files
|
|
|
|
find "${scripture_path}" -name "*.json" -type f -size -500c -delete
|
|
|
|
# remove all empty folders
|
|
|
|
find "${scripture_path}" -type d -empty -delete
|
|
|
|
}
|
|
|
|
|
2021-04-20 22:08:00 +00:00
|
|
|
# the hashing of all files
|
|
|
|
function hashingAll() {
|
2021-04-21 04:09:09 +00:00
|
|
|
# set local values
|
|
|
|
local each="$1"
|
2021-04-20 22:08:00 +00:00
|
|
|
# start hashing Translations
|
|
|
|
hashingMethod "${DIR_api}_scripture" \
|
|
|
|
"hash_versions" \
|
|
|
|
"Hash Versions" \
|
|
|
|
"Start Versions Hashing" \
|
|
|
|
"Done Hashing Versions" \
|
2021-04-21 04:09:09 +00:00
|
|
|
"Please wait while we hash all versions" "$each"
|
2021-04-20 22:08:00 +00:00
|
|
|
# start hashing Translations Books
|
|
|
|
hashingMethod "${DIR_api}_scripture" \
|
|
|
|
"hash_books" \
|
|
|
|
"Hash Books" \
|
|
|
|
"Start Versions Books Hashing" \
|
|
|
|
"Done Hashing All Versions Books" \
|
2021-04-21 04:09:09 +00:00
|
|
|
"Please wait while we hash all versions books" "$each"
|
2021-04-20 22:08:00 +00:00
|
|
|
# start hashing Translations Books Chapters
|
|
|
|
hashingMethod "${DIR_api}_scripture" \
|
|
|
|
"hash_chapters" \
|
|
|
|
"Hash Chapters" \
|
|
|
|
"Start Versions Books Chapters Hashing" \
|
|
|
|
"Done Hashing All Versions Books Chapters" \
|
2021-04-21 04:09:09 +00:00
|
|
|
"Please wait while we hash all versions books chapters" "$each"
|
2021-04-20 22:08:00 +00:00
|
|
|
# moving all public hash files into place
|
2021-04-25 01:41:17 +00:00
|
|
|
movePublicHashFiles "${DIR_api}" \
|
2021-04-20 22:08:00 +00:00
|
|
|
"movePublicHashFiles" \
|
|
|
|
"Moving Public Hash" \
|
|
|
|
"Start Moving Public Hashes" \
|
|
|
|
"Done Moving All Public Hashes" \
|
2021-04-21 04:09:09 +00:00
|
|
|
"Please wait while we move all the public hashes into place" "$each"
|
2021-04-20 22:08:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 00:38:47 +00:00
|
|
|
# hashing all files in the project
|
2021-04-20 22:08:00 +00:00
|
|
|
function hashingMethod() {
|
2021-04-20 00:38:47 +00:00
|
|
|
# set local values
|
|
|
|
local scripture_path="$1"
|
|
|
|
local script_name="$2"
|
|
|
|
local w_title="$3"
|
|
|
|
local w_start_ms="$4"
|
|
|
|
local w_end_ms="$5"
|
|
|
|
local w_initial_ms="$6"
|
2021-04-21 04:09:09 +00:00
|
|
|
local each="$7"
|
2021-04-23 03:50:33 +00:00
|
|
|
# run in github action workflow... ¯\_(ツ)_/¯
|
|
|
|
if (("$GITHUB" == 1)); then
|
|
|
|
echo "$w_title | ${HEADERTITLE}"
|
|
|
|
echo "$w_initial_ms"
|
|
|
|
echo "${w_start_ms}..."
|
|
|
|
# now run the hashing
|
|
|
|
. "${DIR_src}/${script_name}.sh" "${scripture_path}" "$each" >>/dev/null
|
|
|
|
echo "${w_end_ms}..."
|
|
|
|
else
|
|
|
|
# now run the hashing
|
|
|
|
{
|
|
|
|
sleep 1
|
|
|
|
echo -e "XXX\n0\n${w_start_ms}... \nXXX"
|
|
|
|
sleep 1
|
|
|
|
. "${DIR_src}/${script_name}.sh" "${scripture_path}" "$each"
|
|
|
|
sleep 1
|
|
|
|
echo -e "XXX\n100\n${w_end_ms}... \nXXX"
|
|
|
|
sleep 1
|
|
|
|
} | showProgress "$w_title | ${HEADERTITLE}" "$w_initial_ms"
|
|
|
|
fi
|
2021-04-21 02:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# set any/all default config property
|
|
|
|
function setDefaults() {
|
|
|
|
if [ -f $CONFIGFILE ]; then
|
|
|
|
# set all defaults
|
|
|
|
DIR_api=$(getDefault "getbible.api" "${DIR_api}")
|
|
|
|
DIR_zip=$(getDefault "getbible.zip" "${DIR_zip}")
|
|
|
|
DIR_bible=$(getDefault "getbible.bconf" "${DIR_bible}")
|
|
|
|
DOWNLOAD=$(getDefault "getbible.download" "$DOWNLOAD")
|
2021-04-25 01:41:17 +00:00
|
|
|
REPOSCRIPTURE=$(getDefault "getbible.repo-scripture" "${REPOSCRIPTURE}")
|
|
|
|
REPOHASH=$(getDefault "getbible.repo-hash" "${REPOHASH}")
|
2021-04-21 02:26:16 +00:00
|
|
|
PUSH=$(getDefault "getbible.push" "$PUSH")
|
2021-04-25 01:41:17 +00:00
|
|
|
PULL=$(getDefault "getbible.pull" "$PULL")
|
2021-04-21 02:26:16 +00:00
|
|
|
HASHONLY=$(getDefault "getbible.hashonly" "$HASHONLY")
|
2021-04-23 03:50:33 +00:00
|
|
|
GITHUB=$(getDefault "getbible.github" "$GITHUB")
|
2021-04-21 02:26:16 +00:00
|
|
|
QUIET=$(getDefault "getbible.quiet" "$QUIET")
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# get default properties from config file
|
|
|
|
function getDefault() {
|
|
|
|
PROP_KEY="$1"
|
|
|
|
PROP_VALUE=$(cat $CONFIGFILE | grep "$PROP_KEY" | cut -d'=' -f2)
|
|
|
|
echo "${PROP_VALUE:-$2}"
|
2021-04-20 00:38:47 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 22:08:00 +00:00
|
|
|
# help message ʕ•ᴥ•ʔ
|
|
|
|
function show_help() {
|
|
|
|
cat <<EOF
|
2021-04-20 00:38:47 +00:00
|
|
|
Usage: ${0##*/:-} [OPTION...]
|
|
|
|
|
|
|
|
You are able to change a few default behaviours in the getBible API builder
|
|
|
|
------ Passing no command options will fallback on the defaults -------
|
|
|
|
|
2021-04-21 02:26:16 +00:00
|
|
|
Options
|
2021-04-20 00:38:47 +00:00
|
|
|
======================================================
|
2021-04-20 22:08:00 +00:00
|
|
|
--api=<path>
|
2021-04-20 00:38:47 +00:00
|
|
|
set the API target folders full path
|
|
|
|
- target folders will be created using this path
|
|
|
|
|
2021-04-21 02:26:16 +00:00
|
|
|
example: ${0##*/:-} --api=/home/$USER/v2
|
2021-04-20 00:38:47 +00:00
|
|
|
|
|
|
|
two folders will be created:
|
2021-04-21 02:26:16 +00:00
|
|
|
- /home/$USER/v2
|
|
|
|
- /home/$USER/v2_scripture
|
2021-04-20 00:38:47 +00:00
|
|
|
|
|
|
|
defaults:
|
|
|
|
- repo/v2
|
|
|
|
- repo/v2_scripture
|
|
|
|
|
|
|
|
(these are the target folders)
|
|
|
|
======================================================
|
2021-04-20 22:08:00 +00:00
|
|
|
--bconf=<path>
|
|
|
|
set the path to the Bible config file
|
|
|
|
- This file contains the list of Crosswire
|
|
|
|
Bible Modules that will be used to build
|
|
|
|
the JSON API files
|
|
|
|
|
2021-04-21 02:26:16 +00:00
|
|
|
example: ${0##*/:-} --bconf=/home/$USER/getbible.json
|
2021-04-20 22:08:00 +00:00
|
|
|
|
|
|
|
defaults:
|
|
|
|
- repo/conf/CrosswireModulesMap.json
|
|
|
|
======================================================
|
2021-04-21 02:26:16 +00:00
|
|
|
--conf=<path>
|
|
|
|
set all the config properties with a file
|
|
|
|
|
|
|
|
example: ${0##*/:-} --conf=/home/$USER/.config/getbible.conf
|
|
|
|
|
|
|
|
defaults:
|
|
|
|
- repo/conf/.config
|
|
|
|
======================================================
|
2021-04-25 01:41:17 +00:00
|
|
|
--pull
|
|
|
|
clone and/or pull target folders/repositories
|
|
|
|
|
|
|
|
example: ${0##*/:-} --pull
|
|
|
|
======================================================
|
2021-04-20 22:08:00 +00:00
|
|
|
--push
|
2021-04-20 00:38:47 +00:00
|
|
|
push changes to github (only if there are changes)
|
|
|
|
- setup the target folders (see target folders)
|
|
|
|
- linked them to github (your own repos)
|
|
|
|
- must be able to push (ssh authentication needed)
|
2021-04-20 22:08:00 +00:00
|
|
|
|
2021-04-20 00:38:47 +00:00
|
|
|
REMEMBER THE AGREEMENT (README.md)
|
|
|
|
|
|
|
|
example: ${0##*/:-} --push
|
|
|
|
======================================================
|
2021-04-20 22:08:00 +00:00
|
|
|
--zip=<path>
|
2021-04-20 00:38:47 +00:00
|
|
|
set the ZIP target folder full path for the Crosswire Modules
|
|
|
|
|
2021-04-21 02:26:16 +00:00
|
|
|
example: ${0##*/:-} --zip=/home/$USER/sword_zip
|
2021-04-20 00:38:47 +00:00
|
|
|
|
|
|
|
defaults:
|
|
|
|
- repo/sword_zip
|
|
|
|
======================================================
|
|
|
|
-d
|
|
|
|
Do not download all Crosswire Modules (helpful in testing)
|
2021-04-20 22:08:00 +00:00
|
|
|
Only use this if you already have modules.
|
2021-04-20 00:38:47 +00:00
|
|
|
|
|
|
|
example: ${0##*/:-} -d
|
|
|
|
======================================================
|
2021-04-20 22:08:00 +00:00
|
|
|
--hashonly
|
|
|
|
To only hash the existing JSON scripture files
|
|
|
|
|
|
|
|
example: ${0##*/:-} --hashonly
|
|
|
|
======================================================
|
2021-04-23 03:50:33 +00:00
|
|
|
--github
|
|
|
|
Trigger github workflow behaviour
|
|
|
|
|
|
|
|
example: ${0##*/:-} --github
|
|
|
|
======================================================
|
2021-04-21 02:26:16 +00:00
|
|
|
--test
|
|
|
|
Run a test with only three Bibles
|
|
|
|
|
|
|
|
example: ${0##*/:-} --test
|
|
|
|
======================================================
|
2021-04-20 22:08:00 +00:00
|
|
|
--dry
|
|
|
|
To show all defaults, and not run the build
|
|
|
|
|
|
|
|
example: ${0##*/:-} --dry
|
|
|
|
======================================================
|
|
|
|
-q|--quiet
|
|
|
|
Quiet mode that prevent whiptail from showing progress
|
|
|
|
|
|
|
|
example: ${0##*/:-} -q
|
|
|
|
example: ${0##*/:-} --quiet
|
|
|
|
======================================================
|
2021-04-20 00:38:47 +00:00
|
|
|
-h|--help
|
|
|
|
display this help menu
|
|
|
|
|
|
|
|
example: ${0##*/:-} -h
|
|
|
|
example: ${0##*/:-} --help
|
2021-04-21 02:36:00 +00:00
|
|
|
======================================================
|
|
|
|
${HEADERTITLE}
|
2021-04-20 00:38:47 +00:00
|
|
|
======================================================
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
# get script path
|
2021-04-20 22:08:00 +00:00
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
2021-04-25 01:41:17 +00:00
|
|
|
# the target repos
|
|
|
|
REPOSCRIPTURE="" # must be a private REPO (please)
|
|
|
|
REPOHASH="git@github.com:getbible/v2.git"
|
2021-04-20 00:38:47 +00:00
|
|
|
# set working paths
|
|
|
|
DIR_src="${DIR}/src"
|
|
|
|
DIR_conf="${DIR}/conf"
|
2021-04-20 16:27:46 +00:00
|
|
|
DIR_api="${DIR}/v2"
|
|
|
|
DIR_zip="${DIR}/sword_zip"
|
2021-04-20 22:08:00 +00:00
|
|
|
# set Bible config file path
|
|
|
|
DIR_bible="${DIR_conf}/CrosswireModulesMap.json"
|
2021-04-21 02:26:16 +00:00
|
|
|
# set default config path
|
|
|
|
CONFIGFILE="${DIR}/conf/.config"
|
2021-04-20 00:38:47 +00:00
|
|
|
# download all modules
|
|
|
|
DOWNLOAD=1
|
2021-04-25 01:41:17 +00:00
|
|
|
# clone and/or pull target repositories
|
|
|
|
PULL=0
|
|
|
|
# push changes to github if repos connected, and has changes
|
2021-04-20 00:38:47 +00:00
|
|
|
PUSH=0
|
|
|
|
# show values do not run
|
2021-04-20 22:08:00 +00:00
|
|
|
DRYRUN=0
|
|
|
|
# only hash the scriptures
|
|
|
|
HASHONLY=0
|
|
|
|
# kill all messages
|
|
|
|
QUIET=0
|
2021-04-23 03:50:33 +00:00
|
|
|
# trigger github workflow behaviour
|
|
|
|
GITHUB=0
|
2021-04-20 00:38:47 +00:00
|
|
|
|
|
|
|
# check if we have options
|
|
|
|
while :; do
|
|
|
|
case $1 in
|
2021-04-20 22:08:00 +00:00
|
|
|
-h | --help)
|
|
|
|
show_help # Display a usage synopsis.
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
-q | --quiet)
|
|
|
|
QUIET=1
|
|
|
|
;;
|
|
|
|
-d)
|
|
|
|
DOWNLOAD=0
|
|
|
|
;;
|
|
|
|
--hashonly)
|
|
|
|
HASHONLY=1
|
|
|
|
;;
|
2021-04-21 02:26:16 +00:00
|
|
|
--test)
|
|
|
|
# setup the test environment
|
|
|
|
DIR_bible="${DIR_conf}/CrosswireModulesMapTest.json"
|
|
|
|
DIR_api="${DIR}/v2t"
|
|
|
|
DIR_zip="${DIR}/sword_zipt"
|
|
|
|
;;
|
2021-04-20 22:08:00 +00:00
|
|
|
--dry)
|
|
|
|
DRYRUN=1
|
|
|
|
;;
|
2021-04-23 03:50:33 +00:00
|
|
|
--github)
|
|
|
|
# github actions workflow behaviour... ¯\_(ツ)_/¯
|
|
|
|
GITHUB=1
|
|
|
|
QUIET=1
|
|
|
|
;;
|
2021-04-25 01:41:17 +00:00
|
|
|
--pull)
|
|
|
|
PULL=1
|
|
|
|
;;
|
2021-04-20 22:08:00 +00:00
|
|
|
--push)
|
|
|
|
PUSH=1
|
|
|
|
;;
|
|
|
|
--bconf) # Takes an option argument; ensure it has been specified.
|
|
|
|
if [ "$2" ]; then
|
|
|
|
DIR_bible=$2
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
echo 'ERROR: "--bconf" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--bconf=?*)
|
|
|
|
DIR_bible=${1#*=} # Delete everything up to "=" and assign the remainder.
|
|
|
|
;;
|
|
|
|
--bconf=) # Handle the case of an empty --bconf=
|
|
|
|
echo 'ERROR: "--bconf" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
;;
|
2021-04-25 01:41:17 +00:00
|
|
|
--repo-hash) # Takes an option argument; ensure it has been specified.
|
|
|
|
if [ "$2" ]; then
|
|
|
|
REPOHASH=$2
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
echo 'ERROR: "--repo-hash" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--repo-hash=?*)
|
|
|
|
REPOHASH=${1#*=} # Delete everything up to "=" and assign the remainder.
|
|
|
|
;;
|
|
|
|
--repo-hash=) # Handle the case of an empty --repo-hash=
|
|
|
|
echo 'ERROR: "--repo-hash" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
--repo-scripture) # Takes an option argument; ensure it has been specified.
|
|
|
|
if [ "$2" ]; then
|
|
|
|
REPOSCRIPTURE=$2
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
echo 'ERROR: "--repo-scripture" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--repo-scripture=?*)
|
|
|
|
REPOSCRIPTURE=${1#*=} # Delete everything up to "=" and assign the remainder.
|
|
|
|
;;
|
|
|
|
--repo-scripture=) # Handle the case of an empty --repo-scripture=
|
|
|
|
echo 'ERROR: "--repo-scripture" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
;;
|
2021-04-21 02:26:16 +00:00
|
|
|
--conf) # Takes an option argument; ensure it has been specified.
|
|
|
|
if [ "$2" ]; then
|
|
|
|
CONFIGFILE=$2
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
echo 'ERROR: "--conf" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--conf=?*)
|
|
|
|
CONFIGFILE=${1#*=} # Delete everything up to "=" and assign the remainder.
|
|
|
|
;;
|
|
|
|
--conf=) # Handle the case of an empty --conf=
|
|
|
|
echo 'ERROR: "--conf" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
;;
|
2021-04-20 22:08:00 +00:00
|
|
|
--api) # Takes an option argument; ensure it has been specified.
|
|
|
|
if [ "$2" ]; then
|
|
|
|
DIR_api=$2
|
|
|
|
shift
|
|
|
|
else
|
2021-04-20 00:38:47 +00:00
|
|
|
echo 'ERROR: "--api" requires a non-empty option argument.'
|
|
|
|
exit 1
|
2021-04-20 22:08:00 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--api=?*)
|
|
|
|
DIR_api=${1#*=} # Delete everything up to "=" and assign the remainder.
|
|
|
|
;;
|
|
|
|
--api=) # Handle the case of an empty --api=
|
|
|
|
echo 'ERROR: "--api" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
--zip) # Takes an option argument; ensure it has been specified.
|
|
|
|
if [ "$2" ]; then
|
|
|
|
DIR_zip=$2
|
|
|
|
shift
|
|
|
|
else
|
2021-04-20 00:38:47 +00:00
|
|
|
echo 'ERROR: "--zip" requires a non-empty option argument.'
|
|
|
|
exit 1
|
2021-04-20 22:08:00 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--zip=?*)
|
|
|
|
DIR_zip=${1#*=} # Delete everything up to "=" and assign the remainder.
|
|
|
|
;;
|
|
|
|
--zip=) # Handle the case of an empty --zip=
|
|
|
|
echo 'ERROR: "--zip" requires a non-empty option argument.'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*) # Default case: No more options, so break out of the loop.
|
|
|
|
break ;;
|
2021-04-20 00:38:47 +00:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-04-21 02:26:16 +00:00
|
|
|
# check if config file is set
|
|
|
|
setDefaults
|
|
|
|
|
2021-04-20 22:08:00 +00:00
|
|
|
# show the config values ¯\_(ツ)_/¯
|
|
|
|
if (("$DRYRUN" == 1)); then
|
|
|
|
echo " ${HEADERTITLE}"
|
|
|
|
echo "======================================================"
|
2021-04-21 02:26:16 +00:00
|
|
|
echo "DIR_api: ${DIR_api}"
|
|
|
|
echo "DIR_zip: ${DIR_zip}"
|
|
|
|
echo "DIR_src: ${DIR_src}"
|
|
|
|
echo "DIR_conf: ${DIR_conf}"
|
|
|
|
echo "DIR_bible: ${DIR_bible}"
|
|
|
|
echo "QUIET: ${QUIET}"
|
|
|
|
echo "HASHONLY: ${HASHONLY}"
|
2021-04-23 03:50:33 +00:00
|
|
|
echo "GITHUB: ${GITHUB}"
|
2021-04-21 02:26:16 +00:00
|
|
|
echo "DOWNLOAD: ${DOWNLOAD}"
|
2021-04-25 01:41:17 +00:00
|
|
|
echo "PULL: ${PULL}"
|
2021-04-21 02:26:16 +00:00
|
|
|
echo "PUSH: ${PUSH}"
|
|
|
|
echo "CONFIGFILE: ${CONFIGFILE}"
|
2021-04-20 22:08:00 +00:00
|
|
|
echo "======================================================"
|
2021-04-20 00:38:47 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-04-20 22:08:00 +00:00
|
|
|
# run Main ┬┴┬┴┤(・_├┬┴┬┴
|
2021-04-20 00:38:47 +00:00
|
|
|
main
|