Repository navigation
Expand file tree
/
Copy pathverify-release.sh
More file actions
executable file
·159 lines (131 loc) · 6.14 KB
/
Copy pathverify-release.sh
File metadata and controls
executable file
·159 lines (131 loc) · 6.14 KB
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
155
156
157
158
159
#!/usr/bin/env sh
set -eu
if [ "$#" -ne 1 ]; then
printf '%s\n' "Usage: $0 /path/to/basicrum-real-user-monitoring.zip" >&2
exit 1
fi
ARCHIVE_INPUT=$1
if [ ! -f "$ARCHIVE_INPUT" ]; then
printf '%s\n' "Release archive does not exist: $ARCHIVE_INPUT" >&2
exit 1
fi
if ! command -v unzip >/dev/null 2>&1; then
printf '%s\n' 'Required command is not installed: unzip' >&2
exit 1
fi
ARCHIVE_DIR=$(CDPATH= cd -- "$(dirname -- "$ARCHIVE_INPUT")" && pwd)
ARCHIVE_NAME=$(basename -- "$ARCHIVE_INPUT")
ARCHIVE_PATH="$ARCHIVE_DIR/$ARCHIVE_NAME"
ARCHIVE_ENTRIES=$(unzip -Z1 "$ARCHIVE_PATH")
PLUGIN_SLUG=basicrum-real-user-monitoring
if [ "$ARCHIVE_NAME" != "${PLUGIN_SLUG}.zip" ]; then
printf '%s\n' "Release archive must be named ${PLUGIN_SLUG}.zip." >&2
exit 1
fi
unzip -tq "$ARCHIVE_PATH" >/dev/null
require_entry() {
if ! printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Fqx "$1"; then
printf '%s\n' "Required release file is missing: $1" >&2
exit 1
fi
}
require_entry "$PLUGIN_SLUG/basicrum.php"
require_entry "$PLUGIN_SLUG/uninstall.php"
require_entry "$PLUGIN_SLUG/readme.txt"
require_entry "$PLUGIN_SLUG/LICENSE.md"
require_entry "$PLUGIN_SLUG/THIRD-PARTY-NOTICES.txt"
require_entry "$PLUGIN_SLUG/composer.json"
require_entry "$PLUGIN_SLUG/src/Plugin.php"
require_entry "$PLUGIN_SLUG/src/Assets.php"
require_entry "$PLUGIN_SLUG/src/ConsentIntegration.php"
require_entry "$PLUGIN_SLUG/vendor/autoload.php"
require_entry "$PLUGIN_SLUG/vendor/composer/autoload_classmap.php"
require_entry "$PLUGIN_SLUG/vendor/composer/installed.php"
require_entry "$PLUGIN_SLUG/assets/js/boomr/boomerang-1.815.60.cutting-edge.min.js"
require_entry "$PLUGIN_SLUG/assets/js/boomr/LICENSE.txt"
require_entry "$PLUGIN_SLUG/assets/js/loaders/boomerang-loader-v15.min.js"
require_entry "$PLUGIN_SLUG/assets/js/loaders/consent-boomerang-loader-v1-15.min.js"
require_entry "$PLUGIN_SLUG/assets/js/integrations/borlabs-cookie-v3.js"
require_entry "$PLUGIN_SLUG/assets/js/integrations/wp-consent-api.js"
require_entry "$PLUGIN_SLUG/assets/js/integrations/cookieyes.js"
require_entry "$PLUGIN_SLUG/assets/js/integrations/generic-opt-in.js"
require_entry "$PLUGIN_SLUG/assets/js/integrations/generic-opt-out.js"
require_entry "$PLUGIN_SLUG/assets/images/basicrum-logo.png"
require_entry "$PLUGIN_SLUG/assets/images/basicrum-menu-icon.svg"
require_entry "$PLUGIN_SLUG/languages/basicrum-real-user-monitoring.pot"
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Fqx "$PLUGIN_SLUG/assets/js/loaders/consent-api.js"; then
printf '%s\n' 'Release archive contains the retired consent API bridge.' >&2
exit 1
fi
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Ev "^${PLUGIN_SLUG}(/|$)" | grep -q .; then
printf '%s\n' "Release archive contains files outside the $PLUGIN_SLUG directory." >&2
exit 1
fi
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Eq "^${PLUGIN_SLUG}/(tests|\\.git|\\.github|release)(/|$)"; then
printf '%s\n' 'Release archive contains a development directory.' >&2
exit 1
fi
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Eq "^${PLUGIN_SLUG}/languages/.*\\.(po|mo)$"; then
printf '%s\n' 'Release archive contains a bundled locale-specific translation.' >&2
exit 1
fi
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Eq "^${PLUGIN_SLUG}/(AGENTS\\.md|CLAUDE\\.md|CONTRIBUTING\\.md|SECURITY\\.md|checklist\\.md|docs(/|$))"; then
printf '%s\n' 'Release archive contains repository-only documentation.' >&2
exit 1
fi
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Eq "^${PLUGIN_SLUG}/vendor/(bin|antecedent|brain|dealerdirect|doctrine|hamcrest|mockery|myclabs|nikic|phar-io|php-parallel-lint|phpcompatibility|phpcsstandards|phpunit|sebastian|squizlabs|theseer|wp-coding-standards|yoast)(/|$)"; then
printf '%s\n' 'Release archive contains a development dependency.' >&2
exit 1
fi
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Eq "^${PLUGIN_SLUG}/vendor/.*/\\.github(/|$)"; then
printf '%s\n' 'Release archive contains dependency repository metadata.' >&2
exit 1
fi
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Eq "^${PLUGIN_SLUG}/vendor/composer/installers(/|$)"; then
printf '%s\n' 'Release archive contains the Composer installer plugin.' >&2
exit 1
fi
if unzip -p "$ARCHIVE_PATH" "$PLUGIN_SLUG/vendor/composer/autoload_classmap.php" | grep -Fq 'Composer\\Installers'; then
printf '%s\n' 'Composer class map references the removed Composer installer plugin.' >&2
exit 1
fi
if ! unzip -p "$ARCHIVE_PATH" "$PLUGIN_SLUG/vendor/composer/autoload_classmap.php" | grep -Fq "'Basicrum\\\\WP\\\\Plugin'"; then
printf '%s\n' 'Composer class map does not contain the Basicrum plugin classes.' >&2
exit 1
fi
if ! unzip -p "$ARCHIVE_PATH" "$PLUGIN_SLUG/vendor/composer/autoload_classmap.php" | grep -Fq "'Basicrum\\\\WP\\\\ConsentIntegration'"; then
printf '%s\n' 'Composer class map does not contain the consent integration service.' >&2
exit 1
fi
if ! unzip -p "$ARCHIVE_PATH" "$PLUGIN_SLUG/assets/js/boomr/LICENSE.txt" | grep -Fq 'Copyright (c) 2017-2023, Akamai Technologies, Inc.'; then
printf '%s\n' 'Bundled Boomerang license text is incomplete.' >&2
exit 1
fi
if ! unzip -p "$ARCHIVE_PATH" "$PLUGIN_SLUG/THIRD-PARTY-NOTICES.txt" | grep -Fq 'Boomerang 1.815.60'; then
printf '%s\n' 'Bundled software notice is incomplete.' >&2
exit 1
fi
if printf '%s\n' "$ARCHIVE_ENTRIES" | grep -Eq "^${PLUGIN_SLUG}/(\\.distignore|composer\\.lock|package(-lock)?\\.json|playwright[^/]*\\.config\\.(js|cjs|mjs|ts)|patchwork\\.json|phpcs\\.ruleset\\.xml|phpunit[^/]*\\.xml|phpstan\\.neon\\.dist|README\\.md|coverage\\.xml|\\.phpunit\\.result\\.cache)$"; then
printf '%s\n' 'Release archive contains a development file.' >&2
exit 1
fi
CHECKSUM_PATH="$ARCHIVE_PATH.sha256"
if [ -f "$CHECKSUM_PATH" ]; then
if command -v sha256sum >/dev/null 2>&1; then
(
cd "$ARCHIVE_DIR"
sha256sum -c "$(basename -- "$CHECKSUM_PATH")" >/dev/null
)
elif command -v shasum >/dev/null 2>&1; then
EXPECTED_CHECKSUM=$(awk 'NR == 1 { print $1 }' "$CHECKSUM_PATH")
ACTUAL_CHECKSUM=$(shasum -a 256 "$ARCHIVE_PATH" | awk '{ print $1 }')
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
printf '%s\n' 'Release checksum verification failed.' >&2
exit 1
fi
else
printf '%s\n' 'Neither sha256sum nor shasum is installed.' >&2
exit 1
fi
fi
printf '%s\n' "Verified release archive: $ARCHIVE_PATH"