summaryrefslogtreecommitdiff
path: root/utils/magento1_whitelist.sh
diff options
context:
space:
mode:
authorMathieu Deous2022-05-02 20:18:23 +0200
committerGitHub2022-05-02 20:18:23 +0200
commit48936efa96ae17295be4e0a71be3294f0ec6aef8 (patch)
treef4e69551f1368aa048edf46b7b061600f3668329 /utils/magento1_whitelist.sh
parentbbc738e16f8b637afde58d65196374af98a5e0e2 (diff)
Make application go-install-able and create a docker image
Diffstat (limited to 'utils/magento1_whitelist.sh')
-rwxr-xr-xutils/magento1_whitelist.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/utils/magento1_whitelist.sh b/utils/magento1_whitelist.sh
new file mode 100755
index 0000000..a747f80
--- /dev/null
+++ b/utils/magento1_whitelist.sh
@@ -0,0 +1,56 @@
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/magento1ce.yar";
7TMPFILE="${OUTFILE}.new";
8
9# First empty the target whitelist so we can completely generate a new one
10cat <<EOF >"${OUTFILE}";
11private rule Magento1Ce : 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_m1" )";
20
21# Add header to whitelist tempfile
22cat <<EOF | tee "${TMPFILE}";
23private rule Magento1Ce : ECommerce
24{
25 condition:
26EOF
27
28# Fetch tags (releases) from Github repo
29TAGS=$( git ls-remote --tags https://github.com/OpenMage/magento-mirror.git | cut -d '/' -f3 | grep -P '^[\d\.]+$' );
30
31# Foreach tag (release)
32while read -r TAG; do
33 # Download tarball of release
34 wget "https://github.com/OpenMage/magento-mirror/archive/${TAG}.tar.gz" -O "${GENTEMPDIR}/${TAG}.tgz";
35 # Unpack tarball
36 tar -C "${GENTEMPDIR}" -xpzf "${GENTEMPDIR}/${TAG}.tgz";
37 # Add version comment to whitelist tempfile
38 echo " /* Magento CE ${TAG} */" | tee -a "${TMPFILE}";
39 # Generate whitelist for version, add output to whitelist tempfile
40 ${SCRIPTDIR}/generate_whitelist.py "Magento CE ${TAG}" "${GENTEMPDIR}/magento-mirror-${TAG}" | grep 'hash.sha1' | sed "s|// ${GENTEMPDIR}/magento-mirror-${TAG}/|// |" | tee -a "${TMPFILE}";
41 # Add white line, with indent
42 echo " " | tee -a "${TMPFILE}";
43done <<< "${TAGS}";
44
45# Add footer to whitelist tempfile
46cat <<EOF | tee -a "${TMPFILE}";
47 false
48}
49EOF
50
51# Copy temporary file to target whitelist while removing duplicate lines except empty ones
52cat "${TMPFILE}" | awk 'match($0,/^\s*$/)||!seen[$0]++' > "${OUTFILE}";
53
54# Clean up
55rm "${TMPFILE}";
56rm -rf "${GENTEMPDIR}";