1
|
#!/bin/sh
|
2
|
|
3
|
# Copyright © 2021 jahoti <jahoti@tilde.team>
|
4
|
#
|
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
# you may not use this file except in compliance with the License.
|
7
|
# You may obtain a copy of the License at
|
8
|
#
|
9
|
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
#
|
11
|
# Unless required by applicable law or agreed to in writing, software
|
12
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
# See the License for the specific language governing permissions and
|
15
|
# limitations under the License.
|
16
|
|
17
|
MY_COPY="$1"
|
18
|
MOZ_COPY="$2"
|
19
|
|
20
|
if [ ! -d "$MY_COPY" ]; then
|
21
|
echo "Native copy of the extension (first argument) is not a directory." >&2
|
22
|
exit 1
|
23
|
elif [ ! -f "$MOZ_COPY" ]; then
|
24
|
echo "Mozilla-signed copy of the extension (second argument is not a file." >&2
|
25
|
exit 1
|
26
|
elif [ -e /tmp/credenza ]; then
|
27
|
echo "The testing location /tmp/credenza is already in use." >& 2
|
28
|
exit 1
|
29
|
fi
|
30
|
|
31
|
${CMD_UNZIP:-unzip -d }/tmp/credenza "$MOZ_COPY"
|
32
|
COULD_UNZIP=$?
|
33
|
if [ $COULD_UNZIP != 0 ]; then
|
34
|
echo "Something went wrong while unbundling the Mozilla-signed copy of the extension." >&2
|
35
|
rm -rf /tmp/credenza
|
36
|
exit $COULD_UNZIP
|
37
|
fi
|
38
|
|
39
|
# Compare manifests (Mozilla prettifies them)
|
40
|
python3 << EOF
|
41
|
import json
|
42
|
|
43
|
def clean_lines(text):
|
44
|
return ''.join([line for line in text.split('\n') if line[:2] != '//'])
|
45
|
|
46
|
f, g = open('/tmp/credenza/manifest.json'), open('${MY_COPY}/manifest.json')
|
47
|
manifest1, manifest2 = clean_lines(f.read()), clean_lines(g.read())
|
48
|
f.close()
|
49
|
g.close()
|
50
|
|
51
|
if json.loads(manifest1) != json.loads(manifest2):
|
52
|
raise Exception('\033[33mValidation failed; manifests differ.\033[30m')
|
53
|
EOF
|
54
|
|
55
|
if [ $? != 0 ]; then
|
56
|
rm -rf /tmp/credenza
|
57
|
exit 2
|
58
|
fi
|
59
|
|
60
|
cp "$MY_COPY"/manifest.json /tmp/credenza
|
61
|
rm -rf /tmp/credenza/META-INF/
|
62
|
|
63
|
if diff -r "$MY_COPY" /tmp/credenza; then
|
64
|
echo '\033'[33mValidation was successful.'\033'[30m
|
65
|
else
|
66
|
echo '\033'[33mValidation failed\; see above 'for' differences.'\033'[30m
|
67
|
fi
|
68
|
|
69
|
rm -rf /tmp/credenza
|