Created
September 4, 2015 01:58
-
-
Save gongo/fddf53da92c9d26a10e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
readonly BASE_DIR=$(cd $(dirname $0) && pwd) | |
readonly REPO_URI="https://raw.githubusercontent.com/php/php-src" | |
readonly SEMVER_RE='php-([0-9]+)\.([0-9]+)\.([0-9]+)([^0-9][_0-9A-Za-z-]+)?' | |
phpini_error() { | |
echo "$1" | |
exit 1 | |
} | |
phpini_filename() { | |
local tag=$1 | |
if [[ "$tag" =~ ^${SEMVER_RE}$ ]] ; then | |
if [[ "${BASH_REMATCH[1]}" -lt 5 ]] ; then | |
# PHP 4 or less | |
echo "php.ini-recommended" | |
elif [[ "${BASH_REMATCH[1]}" -eq 5 && "${BASH_REMATCH[2]}" -lt 3 ]] ; then | |
# Less than PHP 5.3 | |
echo "php.ini-recommended" | |
else | |
echo "php.ini-production" | |
fi | |
else | |
phpini_error "Invalid tag name: '${tag}'" | |
fi | |
} | |
phpini_fetch() { | |
local commit=$1 | |
local tag=$2 | |
local url="${REPO_URI}/${commit}/$(phpini_filename $tag)" | |
local dir="${BASE_DIR}/${tag}" | |
echo "Fetch ${tag}'s php.ini" | |
mkdir -p "$dir" | |
curl -L --silent "$url" > "${dir}/php.ini" | |
} | |
phpini_main() { | |
local IFS=$'\n' | |
for refs in $(git ls-remote -t https://github.com/php/php-src 'php-*^{}') | |
do | |
commit=$(echo "$refs" | cut -f 1) | |
tag=$(echo "$refs" | cut -f 2 | cut -d '^' -f 1 | sed -e 's|refs/tags/||') | |
phpini_fetch "$commit" "$tag" | |
done | |
} | |
phpini_main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
raw.githubusercontent.com
でも commit id じゃなくて tag name で取得できるっぽいのであとでまた変化するかも