Return to Snippet

Revision: 17723
at September 19, 2009 12:41 by AzizLight


Updated Code
#!/bin/bash
# This is where the CodeIgniter main folder is
ci_dir="/Users/aziz/Sites/source/CodeIgniter_1.7.2"

# The current date used for the default project name if no project name is submited
date=`date +"%Y-%m-%d_%H-%M-%S"`

# Create the main project folder
if [ -z $1 ]
then
    read -p "Choose a name for your project: [Default: ci-$date]" project_name
    if [ -z $project_name ]
    then
        \cp -R $ci_dir ./ci-$date
        project_name=ci-$date
    else
        \cp -R $ci_dir ./$project_name
        project_name=$project_name
    fi
else
    let "folder_exists= 1"
    while [ $folder_exists -eq 1 ]
    do
        if [ -d $1 ]
        then
            echo 'This directory already exists'
            read -p "Choose a name for your project: [Default: ci-$date]" project_name
            if [ -z $project_name ]
            then
                let "folder_exists= 0"
                \cp -R $ci_dir ./ci-$date
                project_name=ci-$date
            else
                if [ -d $project_name ]
                then
                    let "folder_exists= 1"
                else
                    let "folder_exists= 0"
                    \cp -R $ci_dir ./$project_name
                    project_name=$project_name
                fi
            fi
        else
            let "folder_exists= 0"
            \cp -R $ci_dir $1
            project_name=$1
        fi
    done
fi

# Ask the user if he wants to move the application folder outside the system folder
dir=`pwd`
echo "Project folder created in $dir/"
read -p "Do you want to move the application? [Default: y]"$'\n'"[y/n] " -n 1 choice
if [ -z $choice ] || [ $choice = 'y' ]
then
    \cd "$project_name"
    mv system/application application
    \cd -
    echo -e "\nApplication folder moved outside the system folder\n"
fi
read -p "Do you want to create a public folder in the application root? [Default: y]"$'\n'"[y/n] " -n 1 choice
if [ -z $choice ] || [ $choice = 'y' ]
then
  \cd "$project_name"
  \mkdir -p public/css public/js
  \cd -
  echo -e "\nplublic folder successfully generated"
fi
echo -e "\nProject generated successfully in $dir/$project_name"

Revision: 17722
at September 12, 2009 16:41 by AzizLight


Initial Code
#!/bin/bash
# This is where the CodeIgniter main folder is
ci_dir="/Users/aziz/Documents/Scripts/CodeIgniter_1.7.2"

# The current date used for the default project name if no project name is submited
date=`date +"%Y-%m-%d_%H-%M-%S"`

# Create the main project folder
if [ -z $1 ]
then
    read -p "Choose a name for your project: [Default: ci-$date]" project_name
    if [ -z $project_name ]
    then
        \cp -R $ci_dir ./ci-$date
        project_name=ci-$date
    else
        \cp -R $ci_dir ./$project_name
        project_name=$project_name
    fi
else
    let "folder_exists= 1"
    while [ $folder_exists -eq 1 ]
    do
        if [ -d $1 ]
        then
            echo 'This directory already exists'
            read -p "Choose a name for your project: [Default: ci-$date]" project_name
            if [ -z $project_name ]
            then
                let "folder_exists= 0"
                \cp -R $ci_dir ./ci-$date
                project_name=ci-$date
            else
                if [ -d $project_name ]
                then
                    let "folder_exists= 1"
                else
                    let "folder_exists= 0"
                    \cp -R $ci_dir ./$project_name
                    project_name=$project_name
                fi
            fi
        else
            let "folder_exists= 0"
            \cp -R $ci_dir $1
            project_name=$1
        fi
    done
fi

# Ask the user if he wants to move the application folder outside the system folder
dir=`pwd`
echo "Project folder created in $dir/"
read -p "Do you want to move the application? [Default: y]"$'\n'"[y/n] " -n 1 choice
if [ -z $choice ] || [ $choice = 'y' ]
then
    cd "$project_name"
    mv system/application application
    cd -
    echo 'application folder moved outside the system folder'
fi
echo -e "\nProject generated successfully in $dir/$project_name"

Initial URL

                                

Initial Description
/!\Notice: Change the ci_dir to wherever your ci folder is on line 3. /!\

Usage: ci [name of project]

Gives the project a name based on the current date if the user didn't provide one. Option to move the app directory outside of the system directory.

Edit [Sept 19, 2009]: I updated the script so that it also gives the option to create a public folder in the application root - that is in the same folder as the system folder. The script also create a css and a js folder in the public folder.

Initial Title
Create basic CodeIgniter project

Initial Tags
Bash, codeigniter

Initial Language
Bash