From 12d5184311febabea8462ed99dc22ad48be91f83 Mon Sep 17 00:00:00 2001 From: Tom Scavo Date: Mon, 8 May 2017 12:21:22 -0400 Subject: [PATCH] Align two scripts --- bin/process_export_aggregate.sh | 65 +++++++++++++++------------------ bin/process_main_aggregate.sh | 16 ++++---- 2 files changed, 38 insertions(+), 43 deletions(-) diff --git a/bin/process_export_aggregate.sh b/bin/process_export_aggregate.sh index f4fc216..e7c5690 100755 --- a/bin/process_export_aggregate.sh +++ b/bin/process_export_aggregate.sh @@ -25,8 +25,8 @@ display_help () { This script produces the following files from the InCommon export aggregate: - $csv_filename1 - $csv_filename2 + ${out_filenames[1]} + ${out_filenames[2]} 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. @@ -109,9 +109,13 @@ fi LIB_FILENAMES="core_lib.sh http_tools.sh" +# XSL filenames +xsl_filenames[1]="list_all_IdPs_csv.xsl" +xsl_filenames[2]="list_all_SPs_csv.xsl" + # output filenames -csv_filename1="all-idps-exported.csv" -csv_filename2="all-sps-exported.csv" +out_filenames[1]="all-idps-exported.csv" +out_filenames[2]="all-sps-exported.csv" ####################################################################### # Process command-line options and arguments @@ -183,16 +187,13 @@ for lib_filename in $LIB_FILENAMES; do done # XSL stylesheets must exist -xsl_file1=$LIB_DIR/list_all_IdPs_csv.xsl -if [ ! -f "$xsl_file1" ]; then - echo "ERROR: $script_name: lib file does not exist: $xsl_file1" >&2 - exit 2 -fi -xsl_file2=$LIB_DIR/list_all_SPs_csv.xsl -if [ ! -f "$xsl_file2" ]; then - echo "ERROR: $script_name: lib file does not exist: $xsl_file2" >&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%%.*}_$$" @@ -207,8 +208,9 @@ fi xml_file="${tmp_dir}/saml-metadata.xml" # output files -csv_file1="${tmp_dir}/$csv_filename1" -csv_file2="${tmp_dir}/$csv_filename2" +for i in ${!out_filenames[*]}; do + out_files[$i]="${tmp_dir}/${out_filenames[$i]}" +done ####################################################################### # Main processing @@ -227,32 +229,25 @@ if [ $status_code -eq 1 ]; then clean_up_and_exit -d "$tmp_dir" 0 fi if [ $status_code -gt 1 ]; then - print_log_message -E "$script_name: cget.sh failed ($status_code) on location: $md_location" + print_log_message -E "$script_name: conditional_get failed ($status_code) on location: $md_location" clean_up_and_exit -d "$tmp_dir" $status_code fi print_log_message -D "$script_name using XML file: $xml_file" -# create the first output file -print_log_message -I "$script_name writing output file: $csv_file1" -/usr/bin/xsltproc $xsl_file1 $xml_file > $csv_file1 -status_code=$? -if [ $status_code -ne 0 ]; then - print_log_message -E "$script_name: xsltproc failed ($status_code) on stylesheet: $xsl_file1" - clean_up_and_exit -d "$tmp_dir" $status_code -fi - -# create the second output file -print_log_message -I "$script_name writing output file: $csv_file2" -/usr/bin/xsltproc $xsl_file2 $xml_file > $csv_file2 -status_code=$? -if [ $status_code -ne 0 ]; then - print_log_message -E "$script_name: xsltproc failed ($status_code) on stylesheet: $xsl_file2" - clean_up_and_exit -d "$tmp_dir" $status_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]} + status_code=$? + if [ $status_code -ne 0 ]; then + print_log_message -E "$script_name: xsltproc failed ($status_code) on stylesheet: ${xsl_files[$i]}" + clean_up_and_exit -d "$tmp_dir" $status_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 $csv_file1 $csv_file2 $out_dir +/bin/mv $( echo -n ${out_files[*]} ) $out_dir status_code=$? if [ $status_code -ne 0 ]; then print_log_message -E "$script_name: mv failed ($status_code) to dir: $out_dir" diff --git a/bin/process_main_aggregate.sh b/bin/process_main_aggregate.sh index 1c35e9c..26750e1 100755 --- a/bin/process_main_aggregate.sh +++ b/bin/process_main_aggregate.sh @@ -113,14 +113,6 @@ fi LIB_FILENAMES="core_lib.sh http_tools.sh" -# output filenames -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" @@ -129,6 +121,14 @@ 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" +# output filenames +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" + ####################################################################### # Process command-line options and arguments #######################################################################