Skip to content

Instantly share code, notes, and snippets.

@gongo
Created September 4, 2015 01:58
Show Gist options
  • Save gongo/fddf53da92c9d26a10e3 to your computer and use it in GitHub Desktop.
Save gongo/fddf53da92c9d26a10e3 to your computer and use it in GitHub Desktop.
#!/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
@gongo
Copy link
Author

gongo commented Sep 4, 2015

raw.githubusercontent.com でも commit id じゃなくて tag name で取得できるっぽいので
あとでまた変化するかも

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment