setup-composer-auth 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. MAGENTO_USERNAME_PROP="http-basic.repo.magento.com.username"
  3. MAGENTO_PASSWORD_PROP="http-basic.repo.magento.com.password"
  4. hash composer 2>/dev/null && IS_COMPOSER_ON_HOST=true
  5. if [ $IS_COMPOSER_ON_HOST ]; then
  6. PUBLIC_KEY="$(composer config --global $MAGENTO_USERNAME_PROP 2>/dev/null)"
  7. PRIVATE_KEY="$(composer config --global $MAGENTO_PASSWORD_PROP 2>/dev/null)"
  8. fi
  9. if [ -z "$PUBLIC_KEY" ] || [ -z "$PRIVATE_KEY" ]; then
  10. exec < /dev/tty
  11. echo
  12. echo "Composer authentication required (repo.magento.com public and private keys):"
  13. read -r -p " Username: " PUBLIC_KEY
  14. read -r -p " Password: " PRIVATE_KEY
  15. echo
  16. exec <&-
  17. fi
  18. if [ -z "$PUBLIC_KEY" ] || [ -z "$PRIVATE_KEY" ]; then
  19. echo "Please setup Composer auth for repo.magento.com to continue." && exit 1
  20. fi
  21. # Output must be piped otherwise file descriptor errors occur. Carriage returns?
  22. echo "composer config --global http-basic.repo.magento.com ${PUBLIC_KEY} ${PRIVATE_KEY}" | bin/clinotty bash -
  23. # Also make sure alternate auth.json is setup (Magento uses this internally)
  24. bin/clinotty [ -d "./var/composer_home" ] && cp /var/www/.composer/auth.json ./var/composer_home/auth.json
  25. echo "Composer auth has been setup."