diff options
| author | Mathieu Deous | 2022-05-02 20:18:23 +0200 |
|---|---|---|
| committer | GitHub | 2022-05-02 20:18:23 +0200 |
| commit | 48936efa96ae17295be4e0a71be3294f0ec6aef8 (patch) | |
| tree | f4e69551f1368aa048edf46b7b061600f3668329 /utils/magento1_whitelist.sh | |
| parent | bbc738e16f8b637afde58d65196374af98a5e0e2 (diff) | |
Make application go-install-able and create a docker image
Diffstat (limited to 'utils/magento1_whitelist.sh')
| -rwxr-xr-x | utils/magento1_whitelist.sh | 56 |
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 | ||
| 3 | set -o errexit -o nounset -o pipefail; | ||
| 4 | |||
| 5 | SCRIPTDIR="$( dirname "$(readlink -f "$0")" )"; | ||
| 6 | OUTFILE="${SCRIPTDIR}/../whitelists/magento1ce.yar"; | ||
| 7 | TMPFILE="${OUTFILE}.new"; | ||
| 8 | |||
| 9 | # First empty the target whitelist so we can completely generate a new one | ||
| 10 | cat <<EOF >"${OUTFILE}"; | ||
| 11 | private rule Magento1Ce : ECommerce | ||
| 12 | { | ||
| 13 | condition: | ||
| 14 | false | ||
| 15 | } | ||
| 16 | EOF | ||
| 17 | |||
| 18 | # Create a temporary directory and make sure it is empty | ||
| 19 | GENTEMPDIR="$( mktemp -d --suffix="_gen_whitelist_m1" )"; | ||
| 20 | |||
| 21 | # Add header to whitelist tempfile | ||
| 22 | cat <<EOF | tee "${TMPFILE}"; | ||
| 23 | private rule Magento1Ce : ECommerce | ||
| 24 | { | ||
| 25 | condition: | ||
| 26 | EOF | ||
| 27 | |||
| 28 | # Fetch tags (releases) from Github repo | ||
| 29 | TAGS=$( git ls-remote --tags https://github.com/OpenMage/magento-mirror.git | cut -d '/' -f3 | grep -P '^[\d\.]+$' ); | ||
| 30 | |||
| 31 | # Foreach tag (release) | ||
| 32 | while 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}"; | ||
| 43 | done <<< "${TAGS}"; | ||
| 44 | |||
| 45 | # Add footer to whitelist tempfile | ||
| 46 | cat <<EOF | tee -a "${TMPFILE}"; | ||
| 47 | false | ||
| 48 | } | ||
| 49 | EOF | ||
| 50 | |||
| 51 | # Copy temporary file to target whitelist while removing duplicate lines except empty ones | ||
| 52 | cat "${TMPFILE}" | awk 'match($0,/^\s*$/)||!seen[$0]++' > "${OUTFILE}"; | ||
| 53 | |||
| 54 | # Clean up | ||
| 55 | rm "${TMPFILE}"; | ||
| 56 | rm -rf "${GENTEMPDIR}"; | ||
