-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
45 lines (36 loc) · 1.49 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
{
./yq -r '
"<?xml version='\''1.0'\'' standalone='\''yes'\''?>\n\n" +
"<!DOCTYPE PLUGIN [\n" +
(.ENTITIES | to_entries | (map(.key | length) | max) as $max | (map("<!ENTITY " + .key + (" " * ($max +4 - (.key | length) + 1)) + " \"" + .value + "\">") | join("\n"))) +
"\n]>\n" +
(.ENTITIES | to_entries | map(.key + "=\"&" + .key + ";\"") | "<PLUGIN " + join(" ") + ">")
' plg.yaml
./yq -o xml '. as $root | {"CHANGES": $root.CHANGES}' plg.yaml
./yq --xml-attribute-prefix "$" ".FILES" -o xml plg.yaml
} > output.xml
content=$(awk -v RS= 'match($0, /<CHANGES>([^<]*)<\/CHANGES>/, arr) {print arr[1]}' output.xml)
content=$(<"$content")
# inserts changelog
gawk -v content="$content" -i inplace '{gsub(/<CHANGES>.*<\/CHANGES>/, "<CHANGES>\n" content "\n</CHANGES>")} 1' output.xml
# Adds two \n before comments
sed -i ':a;N;$!ba;s/\([^\n]\)\(<!--\)/\1\n\n\2/g; s/\([^\n]\n\)\(<!--\)/\n\n\2/g' output.xml
# Replaces & with &
sed -i 's/&/\&/g' output.xml
# inserts inline shell scripts
while IFS= read -r line
do
if [[ $line =~ \<INLINE\>(.*)\</INLINE\> ]]; then
filename="${BASH_REMATCH[1]}"
if [ -f "$filename" ]; then
content=$(cat "$filename")
printf '%s\n' "${line/<INLINE>$filename<\/INLINE>/<INLINE>$'\n'<![CDATA[$'\n'$content$'\n']]>$'\n'<\/INLINE>}"
else
echo "File not found: $filename" >&2
echo "$line"
fi
else
echo "$line"
fi
done < output.xml > output.plg