This repository was archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 434
/
Copy pathupdate_embedded.sh
executable file
·65 lines (48 loc) · 2.11 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
61
62
63
64
65
#!/bin/sh
TEMP_FILENAME="embedded_new_file"
TEMP_ETAG_FILENAME="embedded_new_etag"
rm -f "$TEMP_FILENAME"
rm -f "$TEMP_ETAG_FILENAME"
# Get the directory where the script is stored
script_dir=$(dirname "$(readlink -f "$0")")
base_dir="${script_dir}/.."
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"
}
# The following URLs shall match the ones in AppURLs.swift. Danger checks that the URLs match on every PR. If the code changes, the regex that Danger uses may need an update.
performUpdate 'https://staticcdn.duckduckgo.com/trackerblocking/v5/current/ios-tds.json' "${base_dir}/Core/AppTrackerDataSetProvider.swift" "${base_dir}/Core/trackerData.json"
performUpdate 'https://staticcdn.duckduckgo.com/trackerblocking/config/v4/ios-config.json' "${base_dir}/Core/AppPrivacyConfigurationDataProvider.swift" "${base_dir}/Core/ios-config.json"