forked from duckduckgo/iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_embedded.sh
executable file
·60 lines (44 loc) · 1.82 KB
/
update_embedded.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
#!/bin/sh
TEMP_FILENAME="embedded_new_file"
TEMP_ETAG_FILENAME="embedded_new_etag"
rm -f "$TEMP_FILENAME"
rm -f "$TEMP_ETAG_FILENAME"
performUpdate() {
if [ "$#" -ne 3 ]; then
printf "Function expects 3 paramters: url, provider file path and data file path\n"
exit 1
fi
FILE_URL=$1
PROVIDER_PATH=$2
DATA_PATH=$3
printf "Processing: %s\n" "${FILE_URL}"
if test ! -f "$DATA_PATH"; then
printf "Error: %s does not exist\n" "${DATA_PATH}"
exit 1
fi
if test ! -f "$PROVIDER_PATH"; then
printf "Error: %s does not exist\n" "${PROVIDER_PATH}"
exit 1
fi
OLD_ETAG=$(grep 'public static let embeddedDataETag' "${PROVIDER_PATH}" | awk -F '\\\\"' '{print $2}')
OLD_SHA=$(grep 'public static let embeddedDataSHA' "${PROVIDER_PATH}" | awk -F '"' '{print $2}')
printf "Existing ETag: %s\n" "${OLD_ETAG}"
printf "Existing SHA256: %s\n" "${OLD_SHA}"
curl -o "$TEMP_FILENAME" -H "If-None-Match: \"${OLD_ETAG}\"" --etag-save "$TEMP_ETAG_FILENAME" "${FILE_URL}"
if test -f $TEMP_FILENAME; then
NEW_ETAG=$(< "$TEMP_ETAG_FILENAME" awk -F '"' '{print $2}')
NEW_SHA=$(shasum -a 256 "$TEMP_FILENAME" | awk -F ' ' '{print $1}')
printf "New ETag: %s\n" "$NEW_ETAG"
printf "New SHA256: %s\n" "$NEW_SHA"
sed -i '' "s/$OLD_ETAG/$NEW_ETAG/g" "${PROVIDER_PATH}"
sed -i '' "s/$OLD_SHA/$NEW_SHA/g" "${PROVIDER_PATH}"
cp "$TEMP_FILENAME" "$DATA_PATH"
printf 'Files updated\n\n'
else
printf 'Nothing to update\n\n'
fi
rm -f "$TEMP_FILENAME"
rm -f "$TEMP_ETAG_FILENAME"
}
performUpdate 'https://staticcdn.duckduckgo.com/trackerblocking/v3/apple-tds.json' 'Core/AppTrackerDataSetProvider.swift' 'Core/trackerData.json'
performUpdate 'https://staticcdn.duckduckgo.com/trackerblocking/config/v2/ios-config.json' 'Core/AppPrivacyConfigurationDataProvider.swift' 'Core/ios-config.json'