|
#!/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" |