forked from gorhill/uBlock
-
Notifications
You must be signed in to change notification settings - Fork 99
/
make-safari.sh
executable file
·113 lines (97 loc) · 3.57 KB
/
make-safari.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
#!/usr/bin/env bash
#
# This script assumes an OS X or *NIX environment
echo '*** uBlock0.safariextension: Copying files...'
DES=dist/build/uBlock0.safariextension
rm -rf "$DES"
mkdir -p "$DES"
# Delete .DS_Store before making
find . ../uAssets -name '.DS_Store' -type f -delete
bash ./tools/make-assets.sh "$DES"
cp -R src/css "$DES"/
cp -R src/img "$DES"/
cp -R src/js "$DES"/
cp -R src/lib "$DES"/
cp -R src/_locales "$DES"/
cp src/*.html "$DES"/
mv $DES/img/icon_128.png "$DES"/Icon.png
cp platform/safari/*.js "$DES"/js/
cp platform/safari/*.html "$DES"/
cp -R platform/safari/img "$DES"/
cp platform/safari/Info.plist "$DES"/
cp platform/safari/Settings.plist "$DES"/
cp LICENSE.txt "$DES"/
cp platform/chromium/vapi.js "$DES"/js/
# Use chrome's usercss polyfill
echo "*** uBlock0.safariextension: Concatenating content scripts..."
cat platform/chromium/vapi-usercss.js > /tmp/contentscript.js
echo >> /tmp/contentscript.js
grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js
mv /tmp/contentscript.js $DES/js/contentscript.js
echo ' ✔'
# https://github.com/el1t/uBlock-Safari/issues/4
echo -n '*** uBlock0.safariextension: Adding extensions to extensionless assets...'
find "$DES"/assets/thirdparties -type f -regex '.*\/[^.]*' -exec mv {} {}.txt \;
echo ' ✔'
echo -n '*** uBlock0.safariextension: Generating Info.plist...'
python tools/make-safari-meta.py "$DES"/
echo ' ✔'
# Detect OS for sed arguments
if [[ "$OSTYPE" == "darwin"* ]]; then
declare -a sedargs=('-i' '')
else
declare -a sedargs=('-i')
fi
# https://github.com/el1t/uBlock-Safari/issues/15
echo -n '*** uBlock0.safariextension: Correcting ctrl to ⌘ in messages...'
for filename in "$DES"/_locales/*.json; do
sed "${sedargs[@]}" 's/Ctrl/⌘/g' "$filename"
done
echo ' ✔'
# Declare __MSG__ scripts inside client-injected.js
# Beware: this removes all newlines within each script
echo -n '*** uBlock0.safariextension: Injecting scripts into vapi-client...'
awkscript='BEGIN { p = 0 }
/^\/\/ __MSG__/ {
p = 1
next
}
/^\/\/ __MSG_[A-Za-z_]+__/ && p { exit 0 }
/^[ ]*\/\// { next }
/^[ ]*[^\/]{2}/ && p {
sub(/^[ ]+/, "", $0)
gsub(/\\/, "\\\\")
gsub(/'"'"'/, "\\'"'"'")
printf "%s", $0
}'
for message in $(perl -nle '/^\/\/ (__MSG_[A-Za-z]+__)/ && print $1' < "$DES"/js/client-injected.js); do
script=$(awk "${awkscript/__MSG__/${message}}" "$DES"/js/client-injected.js | sed 's/[\"#&]/\\&/g')
sedargs+=('-e' "s#${message}#${script}#")
done
if ! sed "${sedargs[@]}" "$DES"/js/vapi-client.js 2>/dev/null; then
sed "${sedargs[@]}" "$DES"/js/vapi-client.js
fi
rm -f "$DES"/js/client-injected.js
echo ' ✔'
# Prepare extension for release
if [ "$1" = all ]; then
if [ ! -f dist/certs/key.pem ] || [ ! -f dist/certs/SafariDeveloper.cer ]; then
echo '*** uBlock0.safariextension: Cannot sign extension; missing credentials'
exit 1
fi
echo -n '*** uBlock0.safariextension: Creating signed extension...'
if ! bash ./tools/make-safari-sign.sh "$DES"; then
echo
echo '*** uBlock0.safariextension: Error signing extension'
exit 1
fi
echo ' ✔'
RELEASES=../uBlock-releases
if [ -d "$RELEASES" ]; then
echo -n '*** uBlock0.safariextension: Copying into releases directory...'
cp "${DES/safariextension/safariextz}" "$RELEASES"
cp "$DES/../Update.plist" "$RELEASES"
echo ' ✔'
fi
fi
echo '*** uBlock0.safariextension: Done.'