-
Notifications
You must be signed in to change notification settings - Fork 13
/
buildxml.sh
executable file
·154 lines (140 loc) · 4.06 KB
/
buildxml.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
#
# This script will rebuild and redeploy the SageTVPuginsV9.xml
# it should be called like the following
# GIT_COMMIT=true GIT_TOKEN=git_username:git_pat ./buildpluginsxml.sh
#
PLUGIN_DIR=${PLUGIN_DIR:-XXX}
PLUGIN_BASENAME=${PLUGIN_BASENAME:-XXX}
PLUGIN_FILE=${PLUGIN_BASENAME}.xml
PLUGIN_MD5=${PLUGIN_BASENAME}.md5
TMP_FILE=${PLUGIN_BASENAME}TMP.xml
VERSION=`date +%Y.%0m%0d.%0H%0M`
FAILED_PLUGINS=""
GIT_REPO=OpenSageTV/sagetv-plugin-repo.git
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > ${TMP_FILE}
echo "<PluginRepository version=\"${VERSION}\">" >> ${TMP_FILE}
# finding regular xml manifests
for file in `find ${PLUGIN_DIR}/ -name '*.xml'` ; do
# validate the xml we just got
xmllint --noout ${file}
if [ $? -eq 0 ] ; then
echo "Adding Plugin $file"
cat ${file} | grep -v '<?xml ' >> ${TMP_FILE}
else
FAILED_PLUGINS="${FAILED_PLUGINS} ${file}"
echo "XML File for ${file} is not valid. Skipping..." >&2
fi
done
# resolve .url locators
mkdir tmp
cd tmp
for file in `find ../${PLUGIN_DIR}/ -name '*.url'` ; do
if [ -e tmp.xml ] ; then
rm tmp.xml
fi
url=`cat ${file} | head -n1`
echo "Resolving Reference URL $url"
wget -O tmp.xml "$url"
if [ $? -ne 0 ] ; then
FAILED_PLUGINS="${FAILED_PLUGINS} ${file}"
echo "Failed to resolve $url in ${file}. Skipping..."
else
# validate the xml we just got
xmllint --noout tmp.xml
if [ $? -eq 0 ]
then
echo "Adding Plugin from $url"
cat tmp.xml | grep -v '<?xml ' >> ../${TMP_FILE}
else
FAILED_PLUGINS="${FAILED_PLUGINS} ${file}"
echo "XML File for ${url} is not valid. Skipping ${file} ..." >&2
fi
fi
done
cd ..
rm -rf tmp
echo '</PluginRepository>' >> ${TMP_FILE}
# before we carry on, let's validate if anything actually changed.
diff <(grep -v "<PluginRepository" ${PLUGIN_FILE}) <(grep -v "<PluginRepository" ${TMP_FILE}) > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Nothing Changed, so let's exit"
rm -f ${TMP_FILE}
exit 0;
fi
# it appears that we have some updates, so, let's validate
# now validate the entire composited xml file to make sure it is valid
xmllint --noout ${TMP_FILE}
if [ $? -eq 0 ]; then
rm ${PLUGIN_FILE}
mv ${TMP_FILE} ${PLUGIN_FILE}
# generate the md5 checksum
md5sum ${PLUGIN_FILE} | tr " " "\n" | grep -v 'xml' > ${PLUGIN_MD5}
echo ""
echo ""
if [ "$FAILED_PLUGINS" != "" ] ; then
echo ""
echo ""
echo "Successfully created ${PLUGIN_FILE} and ${PLUGIN_MD5} BUT Some plugins are omitted"
echo "** PLUGIN FAILURES **"
echo "$FAILED_PLUGINS"
echo "** PLUGIN FAILURES **"
else
echo "Successfully created ${PLUGIN_FILE} and ${PLUGIN_MD5}"
fi
else
echo ""
echo ""
echo "XML File is not valid"
if [ "$FAILED_PLUGINS" != "" ] ; then
echo "** PLUGIN FAILURES **"
echo "$FAILED_PLUGINS"
echo "** PLUGIN FAILURES **"
exit 2
fi
fi
#
# Last Step commit these new changes
if [ "true" = "$GIT_COMMIT" ] ; then
if [ -z "$GIT_TOKEN" ] ; then
echo "missing GIT_TOKEN"
echo "GIT_TOKEN should be user:personal_access_token used to authenticate the user"
exit 1
fi
mkdir tmp
cd tmp
git config --global push.default matching
git config --global user.email "[email protected]"
git config --global user.name "Travis CI Builder"
git clone https://${GIT_TOKEN}@github.com/${GIT_REPO}
if [ $? -ne 0 ]; then
cd ..
rm -rf tmp
echo "Failed to clone Git Rep"
exit 3
fi
cd sagetv-plugin-repo
echo "Committing Changed Files to Git"
cp ../../${PLUGIN_FILE} .
cp ../../${PLUGIN_MD5} .
git add ${PLUGIN_FILE}
git add ${PLUGIN_MD5}
git commit -m "[ci skip] updated plugins xml to $VERSION"
if [ $? -ne 0 ]; then
cd ../../
rm -rf tmp
echo "Failed to commit git changes"
exit 4
fi
# nuke the output for git push since it contains our url
git push > /dev/null 2>&1
if [ $? -ne 0 ]; then
cd ../../
rm -rf tmp
echo "Failed to push changes"
exit 4
fi
cd ../../
rm -rf tmp
echo "Re-published $PLUGIN_FILE"
fi