Skip to content

Commit 813510e

Browse files
committed
Merge pull request #22 from loadsys/f/operation-improvements
F/operation improvements
2 parents e3f7007 + 5fda333 commit 813510e

18 files changed

Lines changed: 186 additions & 96 deletions

add-cakephp-version

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ usage ()
55
{
66
cat <<EOT
77
8-
${0##*/}
9-
This script will download and create a CakePHP "core" folder for
10-
the version number specified as the command line argument in
11-
whatever folder it lives in. You must relocate this script to its
12-
own directory where it can spawn new folders for each Cake version
13-
without interfering with a git repo. This should be somewhere
14-
central on your system where all Cake projects can symlink to the
8+
${0##*/}
9+
This script will download and create a CakePHP "core" folder for
10+
the version number specified as the command line argument in
11+
whatever folder it lives in. You must relocate this script to its
12+
own directory where it can spawn new folders for each Cake version
13+
without interfering with a git repo. This should be somewhere
14+
central on your system where all Cake projects can symlink to the
1515
individual Cake version required.
1616
1717
Usage:
18-
bin/${0##*/} x.y.z [-f]
19-
20-
Pass a CakePHP release number as the first argument.
21-
22-
Specify '-f' as the second argument to forcibly replace the
18+
cakes/${0##*/} x.y[.z] [-f]
19+
20+
Pass a CakePHP release number (or major.minor for latest) as
21+
the first argument.
22+
23+
Specify '-f' as the second argument to forcibly replace the
2324
cakephp repo.
2425
2526
@@ -31,7 +32,6 @@ if [ "$1" = '-h' ]; then
3132
usage
3233
fi
3334

34-
3535
umask a+rw
3636

3737
DIR="$( cd -P "$( dirname "$0" )" >/dev/null 2>&1 && pwd )";
@@ -45,7 +45,7 @@ if [ "$2" = '-f' ]; then
4545
fi
4646

4747

48-
# Just a little precaution since this script comes bundled in the
48+
# Just a little precaution since this script comes bundled in the
4949
# CakePHP-Skeleton's bin/ folder, but should't be used from there.
5050
if [ "${DIR##*/}" = 'bin' ]; then
5151
echo "!!! The script has detected you are trying to run it from the bin/ folder."
@@ -58,15 +58,6 @@ if [ -n "$1" ]; then
5858
else
5959
usage
6060
fi
61-
DESTDIR="${DIR}/cake_${TAG}"
62-
63-
# Automatically replace an existing copy of the version.
64-
if [ -d "${DESTDIR}" ]; then
65-
echo "## Recreating Cake core v${TAG}" >&2
66-
rm -rf ${DESTDIR}
67-
else
68-
echo "## Creating Cake core v${TAG}" >&2
69-
fi
7061

7162
# If configured, reuse the existing temp folder (if present).
7263
if [ $REUSE_REPO -gt 0 ] && [ -d "${TMPDIR}" ]; then
@@ -87,13 +78,31 @@ echo "## Fetching updates from remote." >&2
8778
cd ${TMPDIR}
8879
git fetch
8980

81+
# "Fill in" the full version number if we were only given a major and minor.
82+
NUM_DOTS=$( tr -dc '.' <<<"$TAG" | awk '{ print length; }' )
83+
if [ $NUM_DOTS -lt 2 ]; then
84+
echo "## Determining latest point release." >&2
85+
POINTRELEASE=$( git tag -l | grep "^${TAG}[0-9\.]*$" | sed "s/${TAG}\.//" | sort -n | tail -1 )
86+
TAG="${TAG}.${POINTRELEASE}"
87+
fi
88+
9089
echo "## Verifying requested tag: ${TAG}" >&2
91-
git show-ref --tags --quiet --verify -- "refs/tags/$1"
90+
git show-ref --tags --quiet --verify -- "refs/tags/${TAG}"
9291
if [ $? -ne 0 ]; then
93-
echo "!! Tag does not exist in the repo. Please check your input and try again."
92+
echo "!! Tag '$TAG' does not exist in the repo. Please check your input and try again."
9493
exit 1
9594
fi
9695

96+
DESTDIR="${DIR}/cake_${TAG}"
97+
98+
# Automatically replace an existing copy of the version.
99+
if [ -d "${DESTDIR}" ]; then
100+
echo "## Recreating Cake core v${TAG}" >&2
101+
rm -rf ${DESTDIR}
102+
else
103+
echo "## Creating Cake core v${TAG}" >&2
104+
fi
105+
97106
echo "## Staging snapshot." >&2
98107
mkdir ${DESTDIR}
99108
git archive $TAG --format=zip > archive.zip

db-backup

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ if (isset($argv[1]) && $argv[1] == '-h') {
3030
// Set up variables.
3131
$dir = getcwd();
3232
$backupDir = $dir . '/backups';
33-
$dbConfigFile = $dir . '/Config/database.php';
33+
$configDir = $dir . '/Config';
34+
$dbConfigFile = $configDir . '/database.php';
3435
$date = date('Ymd-His');
3536
if (!is_readable($dbConfigFile)) {
3637
echo "!! Failed to read database config file: '{$dbConfigFile}'" . PHP_EOL;

db-loadschema

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ fi
2626

2727
# Variable initialization.
2828
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
29+
APP_DIR="$DIR"
2930
BIN_DIR="$DIR/bin"
30-
CONFIG_DIR="$DIR/Config"
31+
CONFIG_DIR="$APP_DIR/Config"
3132
MIGRATION_DIR="$CONFIG_DIR/Migration"
3233
CAKE_SHELL="$DIR/Console/cake"
3334
DEFAULT_SCHEMAPHP="$CONFIG_DIR/Schema/schema.php"

db-login

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ fi
2424

2525

2626
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
27-
BINDIR="${DIR}/bin"
27+
BIN_DIR="$DIR/bin"
2828

2929
# Holy yuck, but nothing else works!
30-
eval $( ${BINDIR}/db-credentials )
30+
eval $( ${BIN_DIR}/db-credentials )
3131

3232
CMD="mysql --host=${DB_HOST} --database=${DB_NAME} --user=${DB_USER}"
3333
PATTERN=" |'"

db-sample-data

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,67 @@
11
#!/usr/bin/env bash
2-
# Script is designed to dump frequently updated data from production for
3-
# importing into a local development database. Currently has hardcoded
4-
# $TABLES and needs to be abstracted to work for "any" project more easily.
5-
# beporter@users.sourceforge.net, 2013-03-08
6-
#
7-
# Run from web root directory on production.
8-
#
9-
# Example:
10-
# bin/db-sample-data database dbuser password
11-
12-
echo "WORK IN PROGRESS";
13-
exit 0;
2+
3+
#---------------------------------------------------------------------
4+
usage ()
5+
{
6+
cat <<EOT
7+
8+
${0##*/}
9+
Dumps frequently updated data from production to a web-accessible
10+
file for downloading and importing into a local development
11+
database. Prompts with the download URL and waits for a response
12+
from the user to delete the file. Pass the names of the DB tables
13+
you wish to download as arguments. Without arguments, will dump
14+
the entire \$default database.
15+
16+
Usage:
17+
bin/${0##*/} [table] [table2] [table3]
18+
19+
20+
EOT
21+
22+
exit 0
23+
}
24+
if [ "$1" = '-h' ]; then
25+
usage
26+
fi
27+
28+
if [ -z "$1" ]; then
29+
TABLES=''
30+
else
31+
TABLES="--tables "$*""
32+
fi
33+
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
34+
APP_DIR="$DIR"
35+
BIN_DIR="${DIR}/bin"
36+
1437

1538
# Configuration vars. Set these appropriately for your app and environment.
16-
TABLES="table1 table2 table3"
17-
WEBROOT_PATH="webroot/"
18-
PUBLIC_URL="http://mysite.com"
39+
PUBLIC_URL=""
40+
WEBROOT_PATH="$APP_DIR/webroot/"
41+
1942

2043
# Internal var setup.
21-
DB=$1
22-
USER=$2
23-
PASS=$3
44+
eval $( ${BIN_DIR}/db-credentials ) # Yuck, but nothing else works!
2445
DATE=$(date +%Y-%m-%d)
2546
OPTIONS="--skip-add-drop-table --no-create-info"
26-
TMP_PATH="tmp/"
27-
DESTINATION_FILE="${DB}_sample_data_$DATE.sql"
47+
TMP_PATH="$APP_DIR/tmp/"
48+
DESTINATION_NAME="${DB_NAME}_sample_data_${DATE}"
2849

50+
# Generate the dump, compress it and move it into place.
51+
cd "${TMP_PATH}"
52+
mysqldump --host="${DB_HOST}" --user="${DB_USER}" -p${DB_PASS} ${OPTIONS} ${DB_NAME} $TABLES > "${DESTINATION_NAME}.sql"
53+
zip -rq9 "${WEBROOT_PATH}${DESTINATION_NAME}.zip" "${DESTINATION_NAME}.sql"
54+
rm -f "${DESTINATION_NAME}.sql"
2955

30-
mysqldump -u ${USER} -p${PASS} ${OPTIONS} ${DB} --tables ${TABLES} > "${TMP_PATH}${DESTINATION_FILE}"
31-
zip -rv9 "${WEBROOT_PATH}${DESTINATION}.zip" "${TMP_PATH}${DESTINATION_FILE}"
32-
rm -f "${TMP_PATH}${DESTINATION_FILE}"
33-
echo "Download URL: ${PUBLIC_URL}/${DESTINATION}.zip"
34-
read -p "Delete ${PUBLIC_URL}/${DESTINATION}.zip? [Y/n]: " ARG_DELETEFILE
56+
# Prompt to download the file, then delete it.
57+
echo "## Download URL: ${PUBLIC_URL}/${DESTINATION_NAME}.zip"
58+
read -p "?? Delete ${PUBLIC_URL}/${DESTINATION_NAME}.zip? [Y/n]: " ARG_DELETEFILE
3559
case $ARG_DELETEFILE in
36-
[Yy]*|* ) rm -f "${WEBROOT_PATH}${DESTINATION}.zip"; echo "File deleted." break;;
37-
[Nn]* ) echo "File REMAINS! Please clean it up when you are done to prevent data leaks." break;;
60+
[Yy]*|*)
61+
rm -f "${WEBROOT_PATH}${DESTINATION_NAME}.zip"
62+
echo "## File deleted."
63+
;;
64+
[Nn]*)
65+
echo "## File REMAINS! Please clean it up when you are done to prevent data leaks."
66+
;;
3867
esac

db-showupdates

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ if [ "$1" = '-h' ]; then
2828
fi
2929

3030
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
31-
SQLFILE="$DIR/Config/sql/db_updates.sql"
32-
TMP_A="$DIR/tmp/db_updates.a.sql"
33-
TMP_B="$DIR/tmp/db_updates.b.sql"
31+
APP_DIR="." # Must be relative to git root.
32+
SQLFILE="$APP_DIR/Config/sql/db_updates.sql"
33+
TMP_A="$APP_DIR/tmp/db_updates.a.sql"
34+
TMP_B="$APP_DIR/tmp/db_updates.b.sql"
3435

3536
#@TODO: Add a -s (silent) flag for db-apply-updates.sh to use to suppress all "for humans" output.
3637

deps-install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ echo "## Running installs for all dependency management tools found.";
4040
"$BINDIR/git-submodules"
4141

4242
# Install PEAR packages if config file is present.
43-
if [ -e "$PEAR_PACKAGES_FILE" ]; then
43+
if [ -r "$PEAR_PACKAGES_FILE" ]; then
4444
PEAR="$( which pear )"
4545
if [ $? -gt 0 ]; then
4646
echo "!! Found pear config file '$PEAR_PACKAGES_FILE', but pear is not present on this system."

docs-generate

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,18 @@ fi
2626
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
2727
CFG_FILE="$DIR/Config/phpdoc.xml"
2828

29-
bin/phpdoc.php --configuration="${CFG_FILE}" "$@"
29+
# Bail out if phpcs isn't available to us
30+
PHPDOC="$( which phpdoc )"
31+
if [ $? -gt 0 ]; then
32+
PHPDOC="$BIN_DIR/phpdoc"
33+
test -x $PHPDOC
34+
fi
35+
if [ $? -gt 0 ]; then
36+
echo "!! The 'phpdoc' command was not found on this system."
37+
echo ""
38+
exit 1
39+
fi
40+
echo "## Found phpdoc at: ${PHPDOC}"
41+
42+
43+
$PHPDOC --configuration="${CFG_FILE}" "$@"

git-currentbranch

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,5 @@ if [ "$1" = '-h' ]; then
2727
usage
2828
fi
2929

30-
#@TODO: Works, but throws a fatal error message if run in a non-git dir. We need to suppress that output.
31-
32-
git rev-parse --quiet --abbrev-ref HEAD
33-
exit $?
30+
git rev-parse --quiet --abbrev-ref HEAD 2>/dev/null
31+
exit $?

paths

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ fi
4040

4141
echo "!! @TODO: Write the script!"
4242
exit 1
43+
44+
# core (cake or Lib/Cake)
45+
# app
46+
# backups
47+
# config
48+
# tmp
49+
# webroot
50+
# lib

0 commit comments

Comments
 (0)