|
#!/usr/bin/env bash |
|
|
|
#--------------------------------------------------------------------- |
|
usage () |
|
{ |
|
cat <<EOT |
|
|
|
${0##*/} |
|
This script will download and create a CakePHP "core" folder for |
|
the version number specified as the command line argument in |
|
whatever folder it lives in. You must relocate this script to its |
|
own directory where it can spawn new folders for each Cake version |
|
without interfering with a git repo. This should be somewhere |
|
central on your system where all Cake projects can symlink to the |
|
individual Cake version required. |
|
|
|
Usage: |
|
cakes/${0##*/} x.y[.z] [-f] |
|
|
|
Pass a CakePHP release number (or major.minor for latest) as |
|
the first argument. |
|
|
|
Specify '-f' as the second argument to forcibly replace the |
|
cakephp repo. |
|
|
|
|
|
EOT |
|
|
|
exit 0 |
|
} |
|
if [ "$1" = '-h' ]; then |
|
usage |
|
fi |
|
|
|
umask a+rw |
|
|
|
DIR="$( cd -P "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"; |
|
TMPDIR="${DIR}/tmp" |
|
REPO=git://github.com/cakephp/cakephp.git |
|
REUSE_REPO=1 # Change this to 0 to force the script to clone the whole cakephp repo every time. |
|
|
|
# Force the cakephp repo to be deleted and recreated. Safe, but sloooowwww. |
|
if [ "$2" = '-f' ]; then |
|
REUSE_REPO=0 |
|
fi |
|
|
|
|
|
# Just a little precaution since this script comes bundled in the |
|
# CakePHP-Skeleton's bin/ folder, but should't be used from there. |
|
if [ "${DIR##*/}" = 'bin' ]; then |
|
echo "!!! The script has detected you are trying to run it from the bin/ folder." |
|
echo "!!! You must move this script to its own folder outside of the git repo." |
|
exit 2 |
|
fi |
|
|
|
if [ -n "$1" ]; then |
|
TAG=$1 |
|
else |
|
usage |
|
fi |
|
|
|
# If configured, reuse the existing temp folder (if present). |
|
if [ $REUSE_REPO -gt 0 ] && [ -d "${TMPDIR}" ]; then |
|
echo "## Reusing existing tmp folder: ${TMPDIR}" >&2 |
|
|
|
else |
|
# Delete a leftover temp folder if present. |
|
if [ -d "${TMPDIR}" ]; then |
|
echo "## Purging old tmp folder: ${TMPDIR}" >&2 |
|
rm -rf ${TMPDIR} |
|
fi |
|
|
|
echo "## Cloning cake repository from ${REPO}" >&2 |
|
git clone ${REPO} ${TMPDIR} |
|
fi |
|
|
|
echo "## Fetching updates from remote." >&2 |
|
cd ${TMPDIR} |
|
git fetch |
|
|
|
# "Fill in" the full version number if we were only given a major and minor. |
|
NUM_DOTS=$( tr -dc '.' <<<"$TAG" | awk '{ print length; }' ) |
|
if [ $NUM_DOTS -lt 2 ]; then |
|
echo "## Determining latest point release." >&2 |
|
POINTRELEASE=$( git tag -l | grep "^${TAG}[0-9\.]*$" | sed "s/${TAG}\.//" | sort -n | tail -1 ) |
|
TAG="${TAG}.${POINTRELEASE}" |
|
fi |
|
|
|
echo "## Verifying requested tag: ${TAG}" >&2 |
|
git show-ref --tags --quiet --verify -- "refs/tags/${TAG}" |
|
if [ $? -ne 0 ]; then |
|
echo "!! Tag '$TAG' does not exist in the repo. Please check your input and try again." |
|
exit 1 |
|
fi |
|
|
|
DESTDIR="${DIR}/cake_${TAG}" |
|
|
|
# Automatically replace an existing copy of the version. |
|
if [ -d "${DESTDIR}" ]; then |
|
echo "## Recreating Cake core v${TAG}" >&2 |
|
rm -rf ${DESTDIR} |
|
else |
|
echo "## Creating Cake core v${TAG}" >&2 |
|
fi |
|
|
|
echo "## Staging snapshot." >&2 |
|
mkdir ${DESTDIR} |
|
git archive $TAG --format=zip > archive.zip |
|
mv archive.zip ${DESTDIR} |
|
|
|
echo "## Installing snapshot into destination." >&2 |
|
cd ${DESTDIR} |
|
unzip -q archive.zip |
|
|
|
echo "## Cleaning up." >&2 |
|
rm -f archive.zip |
|
if [ $REUSE_REPO -eq 0 ]; then |
|
rm -rf ${TMPDIR} |
|
fi |
|
|
|
echo "## Done: ${DESTDIR}" >&2 |