#!/bin/bash

# First argument is a valid configuration as input
INPUT="$1"

# Second argument is a directory for output
DEST="$2"

# Remove old files (at first build $DEST does not exist yet)
rm -f "$DEST"/*.asr

# Copy valid input
cp "$INPUT" "$DEST"

# Generate config with unknown language (otherwise valid)
sed 's/^Language=.*$/Language=xxx/g'  "$INPUT" > "$DEST"/unknown-language.asr

# Generate invalid configurations with only one detail changed
sed '/^Version=/d'                 "$INPUT" > "$DEST"/invalid-missing-key-version.asr
sed 's/^Version=.*$/Version=/g'    "$INPUT" > "$DEST"/invalid-empty-key-version.asr
sed 's/^Version=.*$/Version=2.0/g' "$INPUT" > "$DEST"/invalid-key-version1.asr
sed 's/^Version=.*$/Version=1/g'   "$INPUT" > "$DEST"/invalid-key-version2.asr
sed 's/^Version=.*$/Version=1.a/g' "$INPUT" > "$DEST"/invalid-key-version3.asr
sed 's/^Version=.*$/Version=1,0/g' "$INPUT" > "$DEST"/invalid-key-version3.asr
sed '1s;^;NoGroup = 1\n\n;'        "$INPUT" > "$DEST"/invalid-key-without-group.asr
sed 's/^\[Model\]/[ledoM]/g'       "$INPUT" > "$DEST"/invalid-missing-group-model.asr
sed '/^Name=/d'                    "$INPUT" > "$DEST"/invalid-missing-key-name.asr
sed '/^Plugin=/d'                  "$INPUT" > "$DEST"/invalid-missing-key-plugin.asr
sed '/^BaseFolder=/d'              "$INPUT" > "$DEST"/invalid-missing-key-basefolder.asr
sed 's/^Name=.*$/Name=/g'          "$INPUT" > "$DEST"/invalid-empty-key-name.asr
sed 's/^Plugin=.*$/Plugin=/g'      "$INPUT" > "$DEST"/invalid-empty-key-plugin.asr
sed 's/^Language=.*$/Language=/g'  "$INPUT" > "$DEST"/invalid-empty-key-language.asr
