Skip to content

Instantly share code, notes, and snippets.

@daveWid
Created July 9, 2010 16:01
Show Gist options
  • Save daveWid/469645 to your computer and use it in GitHub Desktop.
Save daveWid/469645 to your computer and use it in GitHub Desktop.
#!/bin/bash
dir="/Users/dave/Sites/"
project=""
# Check for Git
type -P git &>/dev/null || { echo "Git is not installed. Exiting." >&2; exit 1; }
# Get a project name
while [ -z "$project" ]
do
echo "Please enter your project name"
read project
done
# Move over into the directory
cd "$dir"
# Check for the project already
if [ -d $project ]
then
echo "$project already exists. Exiting."
exit 1
else
mkdir "$project" && cd "$project"
# Initialize Git Repository
git init
# Make directories
mkdir -p htdocs/{css,images,js}
mkdir -p kohana/application/classes/{controller,model}
mkdir -p kohana/application/{config,views}
mkdir -m 0777 -p kohana/application/{cache,logs}
# Add ignore rule for .DS_Store files (only necessary on OS X)
echo ".DS_Store" > .gitignore
# Make ignore files for the cache and logs directories
echo '[^.]*' > kohana/application/{logs,cache}/.gitignore
# Add in Kohana modules
# Add git repos that you use across all projects below -
# This is just the core and database.
git submodule add git://github.com/kohana/core.git kohana/system
git submodule add git://github.com/kohana/database.git kohana/modules/database
git submodule init
# Add in the index.php, .htaccess and bootstrap.php files
curl -o htdocs/index.php http://github.com/kohana/kohana/raw/master/index.php
curl -o htdocs/.htaccess http://github.com/kohana/kohana/raw/master/example.htaccess
curl -o kohana/application/bootstrap.php http://github.com/kohana/kohana/raw/master/application/bootstrap.php
git add .
git commit -m 'Initial Commit.'
# Send success message
echo "------------"
echo "$project created successfully!"
fi
@daveWid
Copy link
Author

daveWid commented Jul 9, 2010

This script will set up a kohana project in no time from the command line.

You will need to change the dir variable at the top of the script to where your web projects will live and save. The command line will ask you for your project name and take care of everything else for you.

@GeertDD
Copy link

GeertDD commented Jul 9, 2010

Good script. What about setting dir to the current directory by default? Optionally let it be set by a --dir flag. See my fork.

@GeertDD
Copy link

GeertDD commented Jul 9, 2010

Dave, just wondering, what does the &>/dev/null part do? As well as >&2.

type -P git &>/dev/null || { echo "Git is not installed. Exiting." >&2; exit 1; }

@daveWid
Copy link
Author

daveWid commented Jul 9, 2010

I just wanted to run a check to make sure that git was installed and I found an answer over on StackOverflow

http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script

I think the &>/dev/null just makes sure that git is available on the system. As for the >&2, I have no idea, but it works so I left it as is. You might be able to pull the & before the >/dev/null and the >&2 part out, but my bash knowledge is pretty basic.

@daveWid
Copy link
Author

daveWid commented Jul 9, 2010

To make things even easier, I saved Geert's fork and put the script in my /Users/dave/shell directory.

Then I added this line to alias to my ~/.bash_profile

alias kreate="sh /Users/dave/shell/create_kohana_project.sh"

Then I can just run kreate from the CL and everything runs in the current directory. (You can use something else then kreate as the alias, it is just short and something I will remember is for Kohana)

@GeertDD
Copy link

GeertDD commented Jul 16, 2010

I pulled the "unknown" parts out, and simply changed it to type -P git || { echo 'Git is not installed. Exiting.'; exit 1; }, which seems to work fine.

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