github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/scripts/diff-config.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  jq_cmd=jq
     4  [[ $(type -P "$jq_cmd") ]] || { 
     5  	echo "'$jq_cmd' command line JSON processor not found";
     6  	echo "Please install on linux with 'sudo apt-get install jq'"
     7  	echo "Please install on mac with 'brew install jq'"
     8  	exit 1; 
     9  }
    10  
    11  if [ -z "$FROM" ]
    12  then
    13    echo "Missing FROM version. Usage: make diff-config FROM=1.1.1 TO=2.2.2"
    14    exit 1
    15  fi
    16  
    17  if [ -z "$TO" ]
    18  then
    19    echo "Missing TO version. Usage: make diff-config FROM=1.1.1 TO=2.2.2"
    20    exit 1
    21  fi
    22  
    23  # Returns the config file for a specific release
    24  fetch_config() {
    25    local url="https://releases.mattermost.com/$1/mattermost-$1-linux-amd64.tar.gz"
    26    curl -sf "$url" | tar -xzOf - mattermost/config/config.json | jq -S .
    27  }
    28  
    29  echo Fetching config files
    30  from_config="$(fetch_config "$FROM")"
    31  if [ -z "$from_config" ]
    32  then
    33    echo Invalid version "$FROM"
    34    exit 1
    35  fi
    36  
    37  to_config=$(fetch_config "$TO")
    38  if [ -z "$to_config" ]
    39  then
    40    echo Invalid version "$TO"
    41    exit 1
    42  fi
    43  
    44  echo Comparing config files
    45  diff -y <(echo "$from_config") <(echo "$to_config")
    46  
    47  # We ignore exits with 1 since it just means there's a difference, which is fine for us.
    48  diff_exit=$?
    49  if [ $diff_exit -eq 1 ]; then
    50    exit 0
    51  else
    52    exit $diff_exit
    53  fi