Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Optimize use of subscripted variables
Tom Scavo committed May 6, 2017
1 parent 27bb60c commit aaa35e7
Showing 1 changed file with 41 additions and 102 deletions.
143 changes: 41 additions & 102 deletions bin/process_main_aggregate.sh
@@ -25,12 +25,12 @@ display_help () {
This script produces the following files from the InCommon
main aggregate:
${out_filename[1]}
${out_filename[2]}
${out_filename[3]}
${out_filename[4]}
${out_filename[5]}
${out_filename[6]}
${out_filenames[1]}
${out_filenames[2]}
${out_filenames[3]}
${out_filenames[4]}
${out_filenames[5]}
${out_filenames[6]}
The script is intended to be run as a cron job. It can (and
should) be run often, to pick up the latest changes to metadata.
@@ -112,12 +112,20 @@ if [ -z "$LOG_LEVEL" ]; then
fi

# output filenames
out_filename[1]="all-idp-displaynames.csv"
out_filename[2]="all-idps-rands.csv"
out_filename[3]="all-sps-rands.csv"
out_filename[4]="security-contacts-legacy-list.csv"
out_filename[5]="security-contacts-summary.json"
out_filename[6]="security-contacts-summary-local.json"
out_filenames[1]="all-idp-displaynames.csv"
out_filenames[2]="all-idps-rands.csv"
out_filenames[3]="all-sps-rands.csv"
out_filenames[4]="security-contacts-legacy-list.csv"
out_filenames[5]="security-contacts-summary.json"
out_filenames[6]="security-contacts-summary-local.json"

# XSL filenames
xsl_filenames[1]="list_all_IdP_DisplayNames_csv.xsl"
xsl_filenames[2]="list_all_RandS_IdPs_csv.xsl"
xsl_filenames[3]="list_all_RandS_SPs_csv.xsl"
xsl_filenames[4]="security_contacts_legacy_list_csv.xsl"
xsl_filenames[5]="security_contacts_summary_json.xsl"
xsl_filenames[6]="security_contacts_summary_local_json.xsl"

#######################################################################
# Process command-line options and arguments
@@ -190,36 +198,13 @@ if [ $status_code -ne 0 ]; then
fi

# XSL stylesheets must exist
xsl_file[1]=$LIB_DIR/list_all_IdP_DisplayNames_csv.xsl
if [ ! -f "${xsl_file[1]}" ]; then
echo "ERROR: $script_name: lib file does not exist: ${xsl_file[1]}" >&2
exit 2
fi
xsl_file[2]=$LIB_DIR/list_all_RandS_IdPs_csv.xsl
if [ ! -f "${xsl_file[2]}" ]; then
echo "ERROR: $script_name: lib file does not exist: ${xsl_file[2]}" >&2
exit 2
fi
xsl_file[3]=$LIB_DIR/list_all_RandS_SPs_csv.xsl
if [ ! -f "${xsl_file[3]}" ]; then
echo "ERROR: $script_name: lib file does not exist: ${xsl_file[3]}" >&2
exit 2
fi
xsl_file[4]=$LIB_DIR/security_contacts_legacy_list_csv.xsl
if [ ! -f "${xsl_file[4]}" ]; then
echo "ERROR: $script_name: lib file does not exist: ${xsl_file[4]}" >&2
exit 2
fi
xsl_file[5]=$LIB_DIR/security_contacts_summary_json.xsl
if [ ! -f "${xsl_file[5]}" ]; then
echo "ERROR: $script_name: lib file does not exist: ${xsl_file[5]}" >&2
exit 2
fi
xsl_file[6]=$LIB_DIR/security_contacts_summary_local_json.xsl
if [ ! -f "${xsl_file[6]}" ]; then
echo "ERROR: $script_name: lib file does not exist: ${xsl_file[6]}" >&2
exit 2
fi
for i in ${!xsl_filenames[*]}; do
xsl_files[$i]=$LIB_DIR/${xsl_filenames[$i]}
if [ ! -f "${xsl_files[$i]}" ]; then
echo "ERROR: $script_name: lib file does not exist: ${xsl_files[$i]}" >&2
exit 2
fi
done

# create a temporary subdirectory
tmp_dir="${TMPDIR%%/}/${script_name%%.*}_$$"
@@ -234,12 +219,9 @@ fi
xml_file="${tmp_dir}/saml-metadata.xml"

# output files
out_file[1]="${tmp_dir}/${out_filename[1]}"
out_file[2]="${tmp_dir}/${out_filename[2]}"
out_file[3]="${tmp_dir}/${out_filename[3]}"
out_file[4]="${tmp_dir}/${out_filename[4]}"
out_file[5]="${tmp_dir}/${out_filename[5]}"
out_file[6]="${tmp_dir}/${out_filename[6]}"
for i in ${!out_filenames[*]}; do
out_files[$i]="${tmp_dir}/${out_filenames[$i]}"
done

#######################################################################
# Main processing
@@ -265,63 +247,20 @@ if [ $exit_code -gt 1 ]; then
clean_up_and_exit -d "$tmp_dir" $exit_code
fi

# create the first output file
print_log_message -I "$script_name writing output file: ${out_filename[1]}"
/usr/bin/xsltproc ${xsl_file[1]} $xml_file > ${out_file[1]}
exit_code=$?
if [ $exit_code -ne 0 ]; then
print_log_message -E "$script_name: xsltproc failed ($exit_code) on stylesheet: ${xsl_file[1]}"
clean_up_and_exit -d "$tmp_dir" $exit_code
fi

# create the second output file
print_log_message -I "$script_name writing output file: ${out_filename[2]}"
/usr/bin/xsltproc ${xsl_file[2]} $xml_file > ${out_file[2]}
exit_code=$?
if [ $exit_code -ne 0 ]; then
print_log_message -E "$script_name: xsltproc failed ($exit_code) on stylesheet: ${xsl_file[2]}"
clean_up_and_exit -d "$tmp_dir" $exit_code
fi

# create the third output file
print_log_message -I "$script_name writing output file: ${out_filename[3]}"
/usr/bin/xsltproc ${xsl_file[3]} $xml_file > ${out_file[3]}
exit_code=$?
if [ $exit_code -ne 0 ]; then
print_log_message -E "$script_name: xsltproc failed ($exit_code) on stylesheet: ${xsl_file[3]}"
clean_up_and_exit -d "$tmp_dir" $exit_code
fi

# create the fourth output file
print_log_message -I "$script_name writing output file: ${out_filename[4]}"
/usr/bin/xsltproc ${xsl_file[4]} $xml_file > ${out_file[4]}
exit_code=$?
if [ $exit_code -ne 0 ]; then
print_log_message -E "$script_name: xsltproc failed ($exit_code) on stylesheet: ${xsl_file[4]}"
clean_up_and_exit -d "$tmp_dir" $exit_code
fi

# create the fifth output file
print_log_message -I "$script_name writing output file: ${out_filename[5]}"
/usr/bin/xsltproc ${xsl_file[5]} $xml_file > ${out_file[5]}
exit_code=$?
if [ $exit_code -ne 0 ]; then
print_log_message -E "$script_name: xsltproc failed ($exit_code) on stylesheet: ${xsl_file[5]}"
clean_up_and_exit -d "$tmp_dir" $exit_code
fi

# create the sixth output file
print_log_message -I "$script_name writing output file: ${out_filename[6]}"
/usr/bin/xsltproc ${xsl_file[6]} $xml_file > ${out_file[6]}
exit_code=$?
if [ $exit_code -ne 0 ]; then
print_log_message -E "$script_name: xsltproc failed ($exit_code) on stylesheet: ${xsl_file[6]}"
clean_up_and_exit -d "$tmp_dir" $exit_code
fi
# create the output files
for i in ${!out_files[*]}; do
print_log_message -I "$script_name writing output file: ${out_filenames[$i]}"
/usr/bin/xsltproc ${xsl_files[$i]} $xml_file > ${out_files[$i]}
exit_code=$?
if [ $exit_code -ne 0 ]; then
print_log_message -E "$script_name: xsltproc failed ($exit_code) on stylesheet: ${xsl_files[$i]}"
clean_up_and_exit -d "$tmp_dir" $exit_code
fi
done

# move the output files to the web directory
print_log_message -I "$script_name moving output files to dir: $out_dir"
/bin/mv ${out_file[1]} ${out_file[2]} ${out_file[3]} ${out_file[4]} ${out_file[5]} ${out_file[6]} $out_dir
/bin/mv $( echo -n ${out_files[*]} ) $out_dir
exit_code=$?
if [ $exit_code -ne 0 ]; then
print_log_message -E "$script_name: mv failed ($exit_code) to dir: $out_dir"

0 comments on commit aaa35e7

Please sign in to comment.