Skip to content

Commit

Permalink
index-alphabetic-browse.sh: minor fix and improvements (#4093)
Browse files Browse the repository at this point in the history
- Use $() instead of ``, avoid using eval, quote variables
  • Loading branch information
rominail authored Nov 25, 2024
1 parent 433d69a commit 7dd7211
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions index-alphabetic-browse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ fi
set -e
set -x

cd "`dirname $0`/import"
cd "$(dirname "$0")/import"
SOLRMARC_CLASSPATH=$(echo solrmarc_core*.jar)
if [[ `wc -w <<<"$SOLRMARC_CLASSPATH"` -gt 1 ]]
if [[ $(wc -w <<<"$SOLRMARC_CLASSPATH") -gt 1 ]]
then
echo "Error: more than one solrmarc_core*.jar in import/; exiting."
exit 1
Expand All @@ -53,26 +53,25 @@ CLASSPATH="browse-indexing.jar:${SOLRMARC_CLASSPATH}:${VUFIND_HOME}/import/lib/*
# current index is stored in the last line of index.properties
function locate_index
{
local targetVar=$1
local indexDir=$2
local indexDir=$1
# default value
local subDir="index"

if [ -e $indexDir/index.properties ]
if [ -e "$indexDir/index.properties" ]
then
# read it into an array
readarray farr < $indexDir/index.properties
readarray farr < "$indexDir/index.properties"
# get the last line
indexline="${farr[${#farr[@]}-1]}"
# parse the lastline to just get the filename
subDir=`echo $indexline | sed s/index=//`
subDir=${indexline#index=}
fi

eval $targetVar="$indexDir/$subDir"
echo "$indexDir/$subDir"
}

locate_index "bib_index" "${SOLR_HOME}/biblio"
locate_index "auth_index" "${SOLR_HOME}/authority"
bib_index=$(locate_index "${SOLR_HOME}/biblio")
auth_index=$(locate_index "${SOLR_HOME}/authority")
index_dir="${SOLR_HOME}/alphabetical_browse"

mkdir -p "$index_dir"
Expand All @@ -87,12 +86,12 @@ function build_browse

# Get the browse headings from Solr
if [ "$skip_authority" = "1" ]; then
if ! output=$($JAVA ${extra_jvm_opts} -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp $CLASSPATH org.vufind.solr.indexing.PrintBrowseHeadings "$bib_index" "$field" "${browse}.tmp" 2>&1); then
if ! output=$($JAVA ${extra_jvm_opts} -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp "$CLASSPATH" org.vufind.solr.indexing.PrintBrowseHeadings "$bib_index" "$field" "${browse}.tmp" 2>&1); then
echo "ERROR: Failed to create browse headings for ${browse}. ${output}."
exit 1
fi
else
if ! output=$($JAVA ${extra_jvm_opts} -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp $CLASSPATH org.vufind.solr.indexing.PrintBrowseHeadings "$bib_index" "$field" "$auth_index" "${browse}.tmp" 2>&1); then
if ! output=$($JAVA ${extra_jvm_opts} -Dfile.encoding="UTF-8" -Dfield.preferred=heading -Dfield.insteadof=use_for -cp "$CLASSPATH" org.vufind.solr.indexing.PrintBrowseHeadings "$bib_index" "$field" "$auth_index" "${browse}.tmp" 2>&1); then
echo "ERROR: Failed to create browse headings for ${browse}. ${output}."
exit 1
fi
Expand All @@ -105,13 +104,13 @@ function build_browse
fi

# Build the SQLite database
if ! output=$($JAVA -Dfile.encoding="UTF-8" -cp $CLASSPATH org.vufind.solr.indexing.CreateBrowseSQLite "sorted-${browse}.tmp" "${browse}_browse.db" 2>&1); then
if ! output=$($JAVA -Dfile.encoding="UTF-8" -cp "$CLASSPATH" org.vufind.solr.indexing.CreateBrowseSQLite "sorted-${browse}.tmp" "${browse}_browse.db" 2>&1); then
echo "ERROR: Failed to build the SQLite database for ${browse}. ${output}."
exit 1
fi

# Clear up temp files
if ! output=$(rm -f *.tmp 2>&1); then
if ! output=$(rm -f -- *.tmp 2>&1); then
echo "ERROR: Failed to clear out temp files for ${browse}. ${output}."
exit 1
fi
Expand All @@ -124,7 +123,7 @@ function build_browse

# Indicate that the new database is ready for use
if ! output=$(touch "$index_dir/${browse}_browse.db-ready" 2>&1); then
echo "ERROR: Failed to mark the new ${browse} database as ready for use. ${error}."
echo "ERROR: Failed to mark the new ${browse} database as ready for use. ${output}."
exit 1
fi
}
Expand Down

0 comments on commit 7dd7211

Please sign in to comment.