summaryrefslogtreecommitdiff
path: root/utils/magento2_whitelist.sh
diff options
context:
space:
mode:
Diffstat (limited to 'utils/magento2_whitelist.sh')
-rwxr-xr-xutils/magento2_whitelist.sh83
1 files changed, 83 insertions, 0 deletions
diff --git a/utils/magento2_whitelist.sh b/utils/magento2_whitelist.sh
new file mode 100755
index 0000000..bb742c8
--- /dev/null
+++ b/utils/magento2_whitelist.sh
@@ -0,0 +1,83 @@
1#!/bin/bash
2# Quit script if something goes wrong
3set -o errexit -o nounset -o pipefail;
4
5SCRIPTDIR="$( dirname "$(readlink -f "$0")" )";
6OUTFILE="${SCRIPTDIR}/../whitelists/magento2.yar";
7TMPFILE="${OUTFILE}.new";
8
9# First empty the target whitelist so we can completely generate a new one
10cat <<EOF >"${OUTFILE}";
11private rule Magento2 : ECommerce
12{
13 condition:
14 false
15}
16EOF
17
18# Create a temporary directory and make sure it is empty
19GENTEMPDIR="$( mktemp -d --suffix="_gen_whitelist_m2" )";
20
21# Composer access tokens
22if [ ! -f "${HOME}/.composer/auth.json" ]; then
23 echo -e "\nYou have no '.composer/auth.json' in your home dir. We will create it from a template and open an editor.";
24 echo -e "Press [Enter] to continue. Press Ctrl-C if you wish to leave.";
25 read;
26 mkdir -p "${HOME}/.composer";
27 cat <<EOF >"${HOME}/.composer/auth.json"
28{
29 "INFO_GITHUB": "==== GET TOKEN: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ ====",
30 "github-oauth": {
31 "github.com": "---github-token-goes-here---"
32 },
33 "INFO_MAGENTO": "==== GET TOKEN: https://devdocs.magento.com/guides/v2.0/install-gde/prereq/connect-auth.html ====",
34 "http-basic": {
35 "repo.magento.com": {
36 "username": "---public-key-goes-here---",
37 "password": "---private-key-goes-here---"
38 }
39 }
40}
41EOF
42 editor "${HOME}/.composer/auth.json";
43fi
44
45# Add header to whitelist tempfile
46cat <<EOF | tee "${TMPFILE}";
47private rule Magento2 : ECommerce
48{
49 condition:
50EOF
51
52# Fetch tags (releases) from Github repo
53TAGS=$( git ls-remote --tags https://github.com/magento/magento2.git | cut -d '/' -f3 | grep -P '^[\d\.]+$' | sort -V );
54
55# Foreach tag (release)
56while read -r TAG; do
57 # Download tarball of release
58 wget "https://github.com/magento/magento2/archive/${TAG}.tar.gz" -O "${GENTEMPDIR}/${TAG}.tgz";
59 # Unpack tarball
60 tar -C "${GENTEMPDIR}" -xpzf "${GENTEMPDIR}/${TAG}.tgz";
61 # Run 'composer install' inside unpacked release
62 SOURCEDIR="${GENTEMPDIR}/magento2-${TAG}";
63 composer --working-dir="${SOURCEDIR}" -- install;
64 # Add version comment to whitelist
65 echo " /* Magento2 ${TAG} */" | tee -a "${TMPFILE}";
66 # Generate whitelist for version, add output to whitelist tempfile
67 ${SCRIPTDIR}/generate_whitelist.py "Magento2 ${TAG}" "${SOURCEDIR}" | grep 'hash.sha1' | sed "s|// ${SOURCEDIR}/|// |" | tee -a "${TMPFILE}";
68 # Add white line, with indent
69 echo " " | tee -a "${TMPFILE}";
70done <<< "${TAGS}";
71
72# Add footer to whitelist tempfile
73cat <<EOF | tee -a "${TMPFILE}";
74 false
75}
76EOF
77
78# Copy temporary file to target whitelist while removing duplicate lines except empty ones
79cat "${TMPFILE}" | awk 'match($0,/^\s*$/)||!seen[$0]++' > "${OUTFILE}";
80
81# Clean up
82rm "${TMPFILE}";
83rm -rf "${GENTEMPDIR}";