aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.md1
-rwxr-xr-xsandbox80
2 files changed, 59 insertions, 22 deletions
diff --git a/TODO.md b/TODO.md
index dd245e4..9c779a2 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,6 +2,7 @@ TODO
====
* Better sandbox template
+ * Split `git init` from `git flow`.
* Should work for more use cases.
* Should be indepotent.
* Asking whether to setup:
diff --git a/sandbox b/sandbox
index 88f8fca..bfb0050 100755
--- a/sandbox
+++ b/sandbox
@@ -5,22 +5,48 @@
# 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
@@ -42,13 +68,22 @@ function sandbox_git {
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
)
}
@@ -61,12 +96,12 @@ function sandbox_ikiwiki {
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
@@ -81,11 +116,11 @@ function sandbox_ikiwiki {
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 .
@@ -99,13 +134,13 @@ function sandbox_vagrant {
(
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
@@ -120,13 +155,14 @@ fi
# 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 :)"