hydra-sql/containers/hydra-sql/composer-wrapper.sh

34 lines
921 B
Bash
Executable File

#!/bin/bash
set -eo pipefail
export COMPOSER_HOME=/tmp/composer
COMPOSER_AUTH="${COMPOSER_HOME}/auth.json"
function fix_composer_auth {
if [ ! -f "${COMPOSER_AUTH}" ]; then
return
fi
GITHUB_TOKEN=$(cat "${COMPOSER_AUTH}" | jq -r '.["github-oauth"]["github.com"]')
if [ ! -z "${GITHUB_TOKEN}" ]; then
GITHUB_USERNAME=$(cat "${COMPOSER_AUTH}" | jq -r '.["http-basic"]["github.com"].username')
if [ -z "${GITHUB_USERNAME}" ]; then
echo -n "Identifiant Github ? "
read GITHUB_USERNAME
fi
cat "${COMPOSER_AUTH}" | jq ".[\"http-basic\"][\"github.com\"] = {\"username\": \"${GITHUB_USERNAME}\", \"password\":\"${GITHUB_TOKEN}\"}" | sponge "${COMPOSER_AUTH}"
cat "${COMPOSER_AUTH}" | jq "del(.[\"github-oauth\"])" | sponge "${COMPOSER_AUTH}"
fi
}
function main {
fix_composer_auth
php composer.phar ${@:1}
}
main $@