errord=false
-check_files()
+# Make sure the config file doesn't set cvars with the wrong prefix
+correct_prefixes()
{
- countw=`awk ''"$3"' { print $2; }' "$1" | sort -u | tr -d '\r' | git hash-object --stdin | cut -c 1-32`
- for b in $2; do
- if [ "$b" = "balance-testing.cfg" ] || [ "$b" = "balance-testingxpm.cfg" ]; then
- continue
- fi
+ local allRegex="$1"
+ local validRegex="$2"
+ local configFile="$3"
+ local tmpFile="$4"
+
+ awk ''"$allRegex"' && !'"$validRegex"' { print $2; }' "$configFile" | tr -d '\r' | sort -u > "$tmpFile"
+ if [ -s "$tmpFile" ]
+ then
+ printf "\033[31m%s\033[0m\n" "Invalid cvars changed in $configFile. Aborting."
+ echo "The following cvars are in $configFile but shouldn't be there:"
+ diff /dev/null "$tmpFile" | grep "^>"
+ echo
+ errord=true
+ fi
+}
+
+# Make sure the files set the same cvars, or the custom doesn't set any which the default doesn't
+correct_cvars()
+{
+ local validRegex="$1"
+ local customFile="$2"
+ local defaultFile="$3"
+ local mustSetAll="$4"
+ local A="$5"
+ local B="$6"
- countb=`awk ''"$3"' { print $2; }' "$b" | sort -u | tr -d '\r' | git hash-object --stdin | cut -c 1-32`
- if [ "$countw" != "$countb" ]; then
- echo "Mismatch between $1 and $b. Aborting."
+ awk ''"$validRegex"' { print $2; }' "$defaultFile" | tr -d '\r' | sort -u > "$A"
+ awk ''"$validRegex"' { print $2; }' "$customFile" | tr -d '\r' | sort -u > "$B"
+ extra=""
+ if $mustSetAll
+ then
+ # Files must change identical cvars, extract all differences
+ extra="$(diff "$A" "$B" | grep "^[<>]")"
+ else
+ # Only extract cvars that are in $customFile but not $defaultFile
+ # $customFile is allowed to override $defaultFile, but not change anything else
+ extra="$(diff "$A" "$B" | grep "^>")"
+ fi
+ if [ "$extra" != "" ]
+ then
+ printf "\033[31m%s\033[0m\n" "Cvar mismatch between $defaultFile and $customFile. Aborting."
+ if $mustSetAll
+ then
echo "Differences are:"
- echo "< missing in $b"
- echo "> must get removed from $b"
- A=`mktemp || echo a.tmp`
- B=`mktemp || echo b.tmp`
- awk ''"$3"' { print $2; }' "$1" | sort -u | tr -d '\r' > "$A"
- awk ''"$3"' { print $2; }' "$b" | sort -u | tr -d '\r' > "$B"
- diff "$A" "$B" | grep '^[<>]' | sort
- rm -f "$A" "$B"
- errord=true
+ echo "< missing in $customFile"
+ echo "> must be removed from $customFile"
+ else
+ echo "The following cvars are missing from $defaultFile, so must be either added to $defaultFile or more likely removed from $customFile:"
+ fi
+ echo "$extra"
+ echo
+ errord=true
+ fi
+}
+
+check_files()
+{
+ local defaultFile="$1"
+ local customFiles="$2"
+ local validRegex="$3"
+ local allRegex="$4"
+ local mustSetAll="$5"
+
+ A="$(mktemp || echo a.tmp)"
+ B="$(mktemp || echo b.tmp)"
+
+ # First check defaultFile
+ correct_prefixes "$allRegex" "$validRegex" "$defaultFile" "$A"
+
+ # Now compare defaultFile to the customFiles
+ for customFile in $customFiles
+ do
+ if [ "$customFile" = "balance-testing.cfg" ] \
+ || [ "$customFile" = "balance-testingxpm.cfg" ] \
+ || [ "$customFile" = "$defaultFile" ]
+ then
+ continue
fi
+ correct_prefixes "$allRegex" "$validRegex" "$customFile" "$B"
+ correct_cvars "$validRegex" "$customFile" "$defaultFile" "$mustSetAll" "$A" "$B"
done
+ rm -f "$A" "$B"
}
-check_files "balance-xonotic.cfg" "balance-*.cfg" "/^seta? g_/"
-check_files "bal-wep-xonotic.cfg" "bal-wep-*.cfg" "/^seta? g_/"
-check_files "_hud_descriptions.cfg" "hud_*.cfg" "/^seta? hud_/"
+check_files "balance-xonotic.cfg" "balance-*.cfg" "/^seta? +g_/" "/^seta? +/" false
+check_files "bal-wep-xonotic.cfg" "bal-wep-*.cfg" "/^seta? +g_/" "/^seta? +/" false
+check_files "_hud_descriptions.cfg" "hud_*.cfg" "/^seta? +_?hud_/" "/^seta? +/" true
-if $errord; then
- if [ "$CMAKE" != "" ]; then
- exit 1
+if $errord
+then
+ if [ "$CMAKE" != "" ]
+ then
+ exit 1
fi
echo "Please wait for 30 seconds, so you have had enough time to read this..."
sleep 30