![]() |
|
Snippets |
|
I share here the script I use to initialize a new Symfony project, as I always subversion them.
This script handles the following default scenario :
You can customize the behaviour of the script defining environment variables. This is an unusual way to do, but it has two advantages :
Here is what you can change in the default scenario :
Here is what is always done, and the really goal of this script (to simplify your life) :
Full usage :
Usage : new-symfony-project PROJECT-NAME You can define following variables to customize the creation : - SYMFONY_BRANCH : The Symfony branch used - SYMFONY_REPOS : The full Symfony SVN repository URL, if set, SYMFONY_BRANCH is ignored - SYMFONY_DATA : The path to the data folder of your Symfony installation. If not left empty, no SVN version will be downloaded (using local installation) and two precedent variables will be ignored - TRUNK_URL : The trunk of your project (default : repos created) - SVNADMIN_REPOS : Local root for SVN repositories - WEB_DIR : Local root for Web directories
Examples :
# Start a new project using default options $ new-symfont-project MyProject # Start a new project embedding 1.1 Symfony branch $ SYMFONY_BRANCH=1.1 new-symfont-project MyProject # Start a new project embedding 1.1 Symfony branch and versionned in a remote repository (already initialized) $ SYMFONY_BRANCH=1.1 TRUNK_URL=my-svn-host/my-svn-repos/trunk new-symfont-project MyProject # Start a new project using system-wide install $ SYMFONY_DATA=/usr/share/php/data new-symfont-project MyProject
Here is the code, you must customize the first 5 lines to fit your default environment options :
#!/bin/bash DEFAULT_WEB_DIR=/home/naholyr/www DEFAULT_SVNADMIN_REPOS=/home/naholyr/svn DEFAULT_SYMFONY_BRANCH=1.0 PROJECT=$1 if [ "$PROJECT" = "" ]; then # Show help and exit echo "Usage : new-symfony-project PROJECT-NAME" echo "You can define following variables to customize the creation :" echo "- SYMFONY_BRANCH : The Symfony branch used (default : $DEFAULT_SYMFONY_BRANCH)" echo "- SYMFONY_REPOS : The full Symfony SVN repository URL, if set, SYMFONY_BRANCH is ignored" echo "- SYMFONY_DATA : The path to the data folder of your Symfony installation. If not left" echo " empty, no SVN version will be downloaded (using local installation) and two precedent" echo " variables will be ignored" echo "- TRUNK_URL : The trunk of your project (default : repos created)" echo "- SVNADMIN_REPOS : Local root for SVN repositories (default : $DEFAULT_SVNADMIN_REPOS)" echo "- WEB_DIR : Local root for Web directories (default : $DEFAULT_WEB_DIR)" fi if [ "$SVNADMIN_REPOS" = "" ]; then SVNADMIN_REPOS=$DEFAULT_SVNADMIN_REPOS fi if [ "$WEB_DIR" = "" ]; then WEB_DIR=$DEFAULT_WEB_DIR fi if [ "$SYMFONY_BRANCH" = "" ]; then SYMFONY_BRANCH=$DEFAULT_SYMFONY_BRANCH fi if [ "$SYMFONY_REPOS" = "" ]; then SYMFONY_REPOS=http://svn.symfony-project.com/branches/$SYMFONY_BRANCH fi if [ "$TRUNK_URL" = "" ]; then SVN_REPOS="file://$SVNADMIN_REPOS" SVN_PROJECT=$SVN_REPOS/$PROJECT # Create repository svnadmin create $SVNADMIN_REPOS/$PROJECT svn mkdir -m "Standard structure" $SVN_PROJECT/trunk $SVN_PROJECT/branches $SVN_PROJECT/tags svn mkdir -m "Create folder for Symfony" $SVN_PROJECT/trunk/lib $SVN_PROJECT/trunk/lib/vendor TRUNK_URL=$SVN_PROJECT/trunk fi # Create web folder cd $WEB_DIR svn co $TRUNK_URL $PROJECT cd $PROJECT if [ "$SYMFONY_DATA" = "" ]; then # Download Symfony svn propset svn:externals "symfony $SYMFONY_REPOS" lib/vendor svn commit -m "External link to Symfony" svn update SYMFONY_DATA=$(pwd)/lib/vendor/symfony/data fi # Create Symfony project $SYMFONY_DATA/bin/symfony init-project $PROJECT # Link to Symfony web elements ln -s $SYMFONY_DATA/web/sf web/sf # Commit the new project svn status | grep ^? | sed "s/? *//" | xargs svn add svn mkdir lib/model/om lib/model/map svn propset svn:ignore "*" log svn propset svn:ignore "*" cache svn propset svn:ignore "*schema-transformed.xml" config svn propset svn:ignore "lib.model.schema.sql plugins.*.sql sqldb.map" data/sql svn propset svn:ignore "*" lib/model/om svn propset svn:ignore "*" lib/model/map svn commit -m "Project initialized" # Conclusion ./symfony -V echo "Working directory : $WEB_DIR/$PROJECT" echo "You should be ready to go :)"
Note that if you work this way, intensively take advantage of Subversion and install plugins as svn:externals ;)
Comments on this snippet
Very nice snippet. Note that there is a simpler way to add all new files to the repo.
Replacing the line: svn status | grep ^? | sed "s/? *//" | xargs svn add by this one: svn add * --force
Cheers, Cedric