1#!/bin/bash 2 3set -eu 4set -o pipefail 5 6SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 7SOURCE_DIR=$(dirname $(dirname ${SCRIPT_DIR})) 8 9# Arg $1 is Messages.sh file path EXCLUDING the name of the script. 10# Arg $2 is resulting pot-file path INCLUDING the name of the file. 11compare() { 12 echo "Comparing result of executing '${1}/Messages.sh' with pot file '$2'." 13 14 CURRENT="" 15 16 MSGS_FILE="${SOURCE_DIR}/${1}/Messages.sh" 17 POT_FILE="${SOURCE_DIR}/${2}" 18 19 if [ -f "$POT_FILE" ]; then 20 # Save current pot file content to variable. 21 CURRENT=$(<${POT_FILE}) 22 23 # Move current pot file to restore it later. 24 TMP_FILE="$(mktemp)" 25 cp -p $POT_FILE $TMP_FILE 26 fi 27 28 # Apply Messages.sh 29 $MSGS_FILE 30 CMP=$(<${POT_FILE}) 31 32 # Remove date lines from pot content. 33 CURRENT=$(echo "$CURRENT" | sed '/POT-Creation-Date/d') 34 CMP=$(echo "$CMP" | sed '/POT-Creation-Date/d') 35 36 if [ "$CURRENT" == "$CMP" ]; then 37 echo "Relevant data is identical." 38 else 39 echo "------------------------------------------------------------------------" 40 echo "Relevant data is not equal to the current pot file." 41 echo "Run the '${1}/Messages.sh' file to fix the discrepancy" 42 echo "or copy the following expected pot-file content into '$2':" 43 echo "------------------------------------------------------------------------" 44 cat "$POT_FILE" 45 echo "------------------------------------------------------------------------" 46 echo 47 FAILED=$(($FAILED + 1)) 48 fi 49 50 # Restore pot-file to initial state or if none existed prior delete the created one. 51 if [ -z "$TMP_FILE" ]; then 52 echo "No previous pot-file, removing temporarly created one." 53 rm $POT_FILE 54 else 55 echo "Restoring original pot-file." 56 cp -p $TMP_FILE $POT_FILE 57 fi 58} 59 60FAILED=0 61compare kcm kcm/po/kcm_kdisplay.pot 62compare plasma-integration plasma-integration/po/kdisplay-plasma.pot 63 64if [ "$FAILED" != "0" ]; then 65 echo; echo "Number of failed pot-files: $FAILED" 66 echo "In case you want to copy the above pot-file content instead of running the respective" 67 echo "Messages.sh scripts locally use the raw output and not the one presented in GitLab's UI!" 68 echo "The output in the UI is reformatted and empty lines have been removed." 69fi 70 71exit $FAILED 72