Created
May 29, 2026 15:18
-
-
Save DonRichards/7e16077332d201834749c259cb2f63c1 to your computer and use it in GitHub Desktop.
Dataverse Merge Bundle.properties post upgrade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # How to use: | |
| #./merge_bundle_properties.sh ~/Bundle.properties /usr/local/payara/glassfish/domains/domain1/applications/dataverse-6.10.1/WEB-INF/classes/propertyFiles/Bundle.properties ~/Bundle.properties.merged | |
| CUSTOM_FILE="${1:?Usage: $0 CUSTOM_FILE APP_FILE OUTPUT_FILE}" | |
| APP_FILE="${2:?Usage: $0 CUSTOM_FILE APP_FILE OUTPUT_FILE}" | |
| OUTPUT_FILE="${3:?Usage: $0 CUSTOM_FILE APP_FILE OUTPUT_FILE}" | |
| # Help if $1 is --help, -h, or is empty. | |
| if [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ -z "$1" ]; then | |
| echo "Usage: $0 CUSTOM_FILE APP_FILE OUTPUT_FILE" | |
| echo "CUSTOM_FILE: The file that contains the custom properties" | |
| echo "APP_FILE: The file that contains the application properties" | |
| echo "OUTPUT_FILE: The file that will contain the merged properties" | |
| exit 0 | |
| fi | |
| awk ' | |
| FNR == NR { | |
| if ($0 ~ /^[[:space:]]*#/ || $0 ~ /^[[:space:]]*$/) | |
| next | |
| pos = index($0, "=") | |
| if (pos == 0) | |
| next | |
| key = substr($0, 1, pos - 1) | |
| custom[key] = $0 | |
| next | |
| } | |
| { | |
| pos = index($0, "=") | |
| if (pos > 0) { | |
| key = substr($0, 1, pos - 1) | |
| if (key in custom) { | |
| print custom[key] | |
| seen[key] = 1 | |
| next | |
| } | |
| } | |
| } | |
| END { | |
| for (key in custom) { | |
| if (!(key in seen)) | |
| print custom[key] | |
| } | |
| } | |
| ' "$CUSTOM_FILE" "$APP_FILE" > "$OUTPUT_FILE" | |
| echo "Merged file written to $OUTPUT_FILE" | |
| # Copy the original Bundle.properties to the original location naming it to Bundle.properties.MM-DD-YYYY | |
| echo "Copying $APP_FILE to ${APP_FILE}.$(date +%m-%d-%Y)" | |
| BACKUP_FILE=${APP_FILE}.$(date +%m-%d-%Y) | |
| if [ -f $BACKUP_FILE ]; then | |
| echo "Backup file $BACKUP_FILE already exists, skipping copy" | |
| else | |
| if ! sudo cp $APP_FILE $BACKUP_FILE; then | |
| echo "Failed to copy $APP_FILE to $BACKUP_FILE" | |
| echo "Exiting..." | |
| exit 1 | |
| fi | |
| echo "Copied $APP_FILE to $BACKUP_FILE" | |
| fi | |
| # Before the copy, grep the removed properties from the original Bundle.properties | |
| # and print them to the console | |
| echo "Finding removed properties..." | |
| REMOVED_PROPERTIES=$(comm -23 \ | |
| <(grep -v '^[[:space:]]*#' "$CUSTOM_FILE" | grep '=' | cut -d= -f1 | sed 's/[[:space:]]*$//' | sort) \ | |
| <(grep -v '^[[:space:]]*#' "$BACKUP_FILE" | grep '=' | cut -d= -f1 | sed 's/[[:space:]]*$//' | sort) \ | |
| ) | |
| if [ -n "$REMOVED_PROPERTIES" ]; then | |
| echo "----------------------------------------" | |
| echo "WARNING: The following keys exist in your CUSTOM_FILE but are NOT in the new APP_FILE." | |
| echo "Dataverse may have removed or renamed them. They were appended to the output but may be dead keys:" | |
| echo "----------------------------------------" | |
| echo "$REMOVED_PROPERTIES" | |
| echo "----------------------------------------" | |
| else | |
| echo "No custom keys are missing from the new APP_FILE." | |
| fi | |
| # Copy the merged Bundle.properties to the original location name it to Bundle.properties.MM-DD-YYYY | |
| echo "Copying $OUTPUT_FILE to $APP_FILE" | |
| if ! sudo cp $OUTPUT_FILE $APP_FILE; then | |
| echo "Failed to copy $OUTPUT_FILE to $APP_FILE" | |
| echo "Exiting..." | |
| exit 1 | |
| else | |
| echo "Copied $OUTPUT_FILE to $APP_FILE" | |
| fi | |
| echo "Finding brought over properties..." | |
| BROUGHT_OVER_PROPERTIES=$(awk -F= ' | |
| FNR==NR { | |
| if ($0 ~ /^[[:space:]]*#/ || $0 ~ /^[[:space:]]*$/ || index($0,"=")==0) next | |
| key=$1; val=substr($0, index($0,"=")+1) | |
| custom[key]=val; next | |
| } | |
| { | |
| if ($0 ~ /^[[:space:]]*#/ || $0 ~ /^[[:space:]]*$/ || index($0,"=")==0) next | |
| key=$1; val=substr($0, index($0,"=")+1) | |
| if (key in custom && custom[key] != val) print key | |
| } | |
| ' "$CUSTOM_FILE" "$BACKUP_FILE") | |
| if [ -n "$BROUGHT_OVER_PROPERTIES" ]; then | |
| echo "" | |
| echo "WARNING: Brought over properties:" | |
| echo "These properties were custom properties." | |
| echo "These were brought over from $CUSTOM_FILE and merged into $APP_FILE:" | |
| echo "----------------------------------------" | |
| echo "$BROUGHT_OVER_PROPERTIES" | |
| echo "----------------------------------------" | |
| else | |
| echo "No custom properties were merged." | |
| fi | |
| echo "" | |
| echo "WARNING: Removed properties:" | |
| echo "These properties were removed from the original Bundle.properties:" | |
| echo "These can safely be removed if no longer needed." | |
| echo "----------------------------------------" | |
| echo "$REMOVED_PROPERTIES" | |
| echo "----------------------------------------" | |
| echo "" | |
| echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment