# Parameters
BASENAME="`basename $0`"
-CODE="$HOME/code"
PROJECT="$1"
REPO="$2"
BOOTSTRAP="git://git.sarava.org/puppet-bootstrap.git"
TEMPLATES="git://git.sarava.org/templates.git"
+# Read a parameter from user
+function sandbox_ask {
+ local input
+ local function="$1"
+ local default="n"
+ shift 2
+
+ read -rep "Setup $function? (defaults to $default): " input
+
+ if [ "$input" == "y" ]; then
+ sandbox_$function
+ fi
+}
+
+# Checkout to develop branch if available
+function sandbox_checkout_develop {
+ (
+ cd $PROJECT
+
+ if git branch --list develop | grep -q develop; then
+ git checkout develop
+ fi
+ )
+}
+
# Initialize project
function sandbox_init {
- echo "Initializing $PROJECT..."
- mkdir -p $CODE/$PROJECT
+ if [ ! -d "$PROJECT" ]; then
+ echo "Initializing $PROJECT..."
+ mkdir -p $PROJECT
+ fi
}
# Git integration
function sandbox_git {
(
- cd $CODE/$PROJECT
+ cd $PROJECT
touch .gitignore
echo "$PROJECT" > README.md
echo "Installing hooks..."
git hooks --install
fi
+ )
+}
- git branch develop
+# Setup git-flow integration
+function sandbox_git_flow {
+ (
+ cd $PROJECT
- if [ -e "/usr/lib/git-core/git-flow" ]; then
- echo ""
- echo "Setting up git-flow..."
- git flow init -d
+ if ! git branch --list develop | grep -q develop; then
+ git branch develop
+
+ if [ -e "/usr/lib/git-core/git-flow" ]; then
+ echo ""
+ echo "Setting up git-flow..."
+ git flow init -d
+ fi
fi
)
}
else
echo ""
echo "Setting up ikiwiki integration..."
- cd $CODE/$PROJECT
- git checkout develop
+ cd $PROJECT
+ sandbox_checkout_develop
if [ ! -e ".gitignore" ]; then
cp $HOME/file/templates/ikiwiki/.gitignore .
- elif ! grep -q -f $HOME/file/templates/ikiwiki/.gitignore; then
+ elif ! grep -q -f $HOME/file/templates/ikiwiki/.gitignore .gitignore; then
cat $HOME/file/templates/ikiwiki/.gitignore >> .gitignore
fi
fi
if [ ! -d "templates" ]; then
- cp r $HOME/file/templates/ikiwiki/templates .
+ cp -r $HOME/file/templates/ikiwiki/templates .
fi
if [ ! -d "bootstrap" ]; then
- cp r $HOME/file/bootstrap/ikiwiki/bootstrap .
+ cp -r $HOME/file/templates/ikiwiki/bootstrap .
fi
git add .
(
echo ""
echo "Setting up vagrant integration..."
- cd $CODE/$PROJECT
- git checkout develop
+ cd $PROJECT
+ sandbox_checkout_develop
echo '.vagrant' >> .gitignore
git commit -a -m "Adds vagrant support"
# Use the best approach
- #git clone $BOOSTRAP $CODE/$PROJECT/puppet
+ #git clone $BOOSTRAP $PROJECT/puppet
#git submodule add $BOOSTRAP puppet
git remote add puppet $BOOTSTRAP
git subtree add --prefix puppet $BOOTSTRAP master --squash
# Clone or initialize
if [ ! -z "$REPO" ]; then
- git clone $URL $CODE/$PROJECT
+ git clone $URL $PROJECT
else
sandbox_init
- sandbox_git
- sandbox_ikiwiki
- sandbox_vagrant
+ sandbox_ask git
+ sandbox_ask git_flow
+ sandbox_ask ikiwiki
+ sandbox_ask vagrant
fi
# Teardown
-echo "Welcome to your new project :)"
+echo "Done sandboxing :)"