Skip to content

Instantly share code, notes, and snippets.

@0m3r
Last active November 24, 2020 12:11
Show Gist options
  • Save 0m3r/eff7ff873713e7e7223f08c1e7020f35 to your computer and use it in GitHub Desktop.
Save 0m3r/eff7ff873713e7e7223f08c1e7020f35 to your computer and use it in GitHub Desktop.

Usage examples :

curl -s https://gist.githubusercontent.com/0m3r/eff7ff873713e7e7223f08c1e7020f35/raw/9b1fe9263a7d64ad7c0869af04b6cf51cd5d319f/detector.sh | bash -s 2.2.0 magento/framework

curl -s https://gist.githubusercontent.com/0m3r/eff7ff873713e7e7223f08c1e7020f35/raw/9b1fe9263a7d64ad7c0869af04b6cf51cd5d319f/detector.sh --output detector.sh

cat detector.sh | bash -s 2.2.0,2.3.0 magento/framework,magento/module-store
cat detector.sh | bash -s magento/product-community-edition 2.2.0,2.3.0 magento/framework,magento/module-store

Check remote file checksum:

curl -s https://gist.githubusercontent.com/0m3r/eff7ff873713e7e7223f08c1e7020f35/raw/9b1fe9263a7d64ad7c0869af04b6cf51cd5d319f/detector.sh | sha1sum
ef26f6439f95b2ad7502218dad96b430b5386866
#!/bin/bash
if test "$#" -eq 0; then
echo >&2 "Usage examples : ";
echo >&2 " curl -s https://gist.githubusercontent.com/0m3r/eff7ff873713e7e7223f08c1e7020f35/raw/2fc68a271c379fc7b9af2aa8277b775adb670a1c/detector.sh | bash -s 2.2.0 magento/framework";
echo >&2 " curl -s https://gist.githubusercontent.com/0m3r/eff7ff873713e7e7223f08c1e7020f35/raw/2fc68a271c379fc7b9af2aa8277b775adb670a1c/detector.sh --output detector.sh";
echo >&2 " cat detector.sh | bash -s 2.2.0,2.3.0 magento/framework,magento/module-store";
echo >&2 " cat detector.sh | bash -s magento/product-community-edition 2.2.0,2.3.0 magento/framework,magento/module-store";
echo >&2 "Check remote file checksum: ";
echo >&2 " curl -s https://gist.githubusercontent.com/0m3r/eff7ff873713e7e7223f08c1e7020f35/raw/2fc68a271c379fc7b9af2aa8277b775adb670a1c/detector.sh | sha1sum";
echo >&2 "efca2a5f9102677f857a982be7d321f31a13411b";
exit 1;
fi
if test "$#" -eq 3; then
PACKAGE=${1}
VERSION=${2}
REQUIRE=${3}
else
PACKAGE="magento/product-community-edition"
VERSION=${1}
REQUIRE=${2}
fi
VERSIONS=($(echo $VERSION | tr "," " "))
if [[ ! $REQUIRE ]]; then
REQUIRE="magento/framework"
fi
REQUIRES=($(echo $REQUIRE | tr "," " "))
REPO='https://repo.magento.com/packages.json'
REPOP='https://repo.magento.com/p/'
REPOPPROVIERCE='https://repo.magento.com/p/provider-ce'
hash composer 2>/dev/null || { echo >&2 "The script requires composer (https://getcomposer.org/download/)"; exit 1; }
hash jq 2>/dev/null || { echo >&2 "The script requires jq (https://stedolan.github.io/jq/download/)"; exit 1; }
USERNAME=$(composer global config http-basic.repo.magento.com.username -q) >/dev/null || {
echo >&2 "Get and set your magento credentials https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html) \n composer config -g http-basic.repo.magento.com [Public Key] [Private Key]";
exit 1;
}
PASSWORD=$(composer global config http-basic.repo.magento.com.password -q)
COMPOSER_COMMAND=''
ADD_TO_C=''
for REQUIRE in "${REQUIRES[@]}"; do
CONSTRAINTS=''
for VERSION in "${VERSIONS[@]}"; do
JQUERY='."provider-includes"."p/provider-ce$%hash%.json".sha256'
PROVIDER_HASH=$(curl --silent --basic --user $USERNAME:$PASSWORD $REPO | jq $JQUERY | sed -e 's/^"//' -e 's/"$//')
# echo "curl --silent --basic --user $USERNAME:$PASSWORD $REPO | jq $JQUERY | sed -e 's/^"//' -e 's/"$//"
# echo "$PROVIDER_HASH"
JQUERY='.providers."'$PACKAGE'".sha256'
PROVIDER_HASH=$(curl --silent --basic --user $USERNAME:$PASSWORD $REPOPPROVIERCE\$$PROVIDER_HASH.json | jq $JQUERY | sed -e 's/^"//' -e 's/"$//')
# echo "$PROVIDER_HASH"
curl --silent --basic --user $USERNAME:$PASSWORD $REPOP$PACKAGE\$$PROVIDER_HASH.json --output $PROVIDER_HASH.gz
gunzip $PROVIDER_HASH.gz
rm $PROVIDER_HASH.gz
JQUERY='.packages."'$PACKAGE'"."'$VERSION'".require."'$REQUIRE'"'
REQUIRE_VERSION=$(cat $PACKAGE_$PROVIDER_HASH | jq $JQUERY | sed -e 's/^"//' -e 's/"$//')
REQUIRE_VERSION="$(cut -d '.' -f 1 <<< "$REQUIRE_VERSION")"."$(cut -d '.' -f 2 <<< "$REQUIRE_VERSION")"
rm $PROVIDER_HASH
# echo "curl --silent --basic --user $USERNAME:$PASSWORD $REPO | jq $JQUERY"
# JQUERY='.packages."'$PACKAGE'"."'$VERSION'".require."'$REQUIRE'"'
# REQUIRE_VERSION=$(curl --silent --basic --user $USERNAME:$PASSWORD $REPO | jq $JQUERY | sed -e 's/^"//' -e 's/"$//')
# REQUIRE_VERSION="$(cut -d '.' -f 1 <<< "$REQUIRE_VERSION")"."$(cut -d '.' -f 2 <<< "$REQUIRE_VERSION")"
echo ''$PACKAGE':'$VERSION' requires '$REQUIRE':'$REQUIRE_VERSION
if [[ ! $CONSTRAINTS ]]; then
CONSTRAINTS="^${REQUIRE_VERSION}"
else
CONSTRAINTS="${CONSTRAINTS}|^${REQUIRE_VERSION}"
fi
done
if [[ ! $COMPOSER_COMMAND ]]; then
COMPOSER_COMMAND="composer require ${REQUIRE}:${CONSTRAINTS}"
else
COMPOSER_COMMAND="${COMPOSER_COMMAND},${REQUIRE}:${CONSTRAINTS}"
fi
echo "composer require ${REQUIRE}:\"${CONSTRAINTS}\" --no-update "
ADD_TO_C="${ADD_TO_C}\n\"${REQUIRE}\": \"${CONSTRAINTS}\","
done
echo "${COMPOSER_COMMAND} --no-update"
echo "========================="
echo -e $ADD_TO_C
echo "========================="
echo "composer validate"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment