]> gitweb.fluxo.info Git - scripts.git/commitdiff
Refactor sandbox and rename to project
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 25 Oct 2017 20:52:31 +0000 (18:52 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 25 Oct 2017 20:52:31 +0000 (18:52 -0200)
project [moved from sandbox with 68% similarity]

diff --git a/sandbox b/project
similarity index 68%
rename from sandbox
rename to project
index 808733d53672d3b163b07412558f63cf3182d4c8..3b4bb913eb6e67885217957294ce517c17d566f3 100755 (executable)
--- a/sandbox
+++ b/project
@@ -4,14 +4,16 @@
 #
 
 # Parameters
+PROGRAM="$0"
 BASENAME="`basename $0`"
 PROJECT="$1"
-REPO="$2"
+shift
+MODULES="$*"
 BOOTSTRAP="https://git.fluxo.info/puppet-bootstrap.git"
 TEMPLATES="https://git.fluxo.info/templates.git"
 
 # Read a parameter from user
-function sandbox_ask {
+function __project_ask {
   local input
   local function="$1"
   local default="n"
@@ -20,12 +22,12 @@ function sandbox_ask {
   read -rep "Setup $function? (defaults to $default): " input
 
   if [ "$input" == "y" ]; then
-    sandbox_$function
+    project_$function
   fi
 }
 
 # Checkout to develop branch if available
-function sandbox_checkout_develop {
+function __project_checkout_develop {
   (
     cd $PROJECT
 
@@ -36,7 +38,7 @@ function sandbox_checkout_develop {
 }
 
 # Initialize project
-function sandbox_init {
+function __project_init {
   if [ ! -d "$PROJECT" ]; then
     echo "Initializing $PROJECT..."
     mkdir -p $PROJECT
@@ -44,7 +46,8 @@ function sandbox_init {
 }
 
 # Git integration
-function sandbox_git {
+function project_git {
+  if [ ! -d "$PROJECT/.git" ]; then
   (
     cd $PROJECT
     touch .gitignore
@@ -69,10 +72,12 @@ function sandbox_git {
       git hooks --install
     fi
   )
+  fi
 }
 
 # Setup git-flow integration
-function sandbox_git_flow {
+function project_gitflow {
+  if ! grep -q '^\[gitflow' $PROJECT/.git/config; then
   (
     cd $PROJECT
 
@@ -86,10 +91,11 @@ function sandbox_git_flow {
       fi
     fi
   )
+  fi
 }
 
 # Ikiwiki integration
-function sandbox_ikiwiki {
+function project_ikiwiki {
   (
     if [ ! -d "$HOME/file/templates" ]; then
       echo "Please clone $TEMPLATES into $HOME/file/templates"
@@ -97,7 +103,7 @@ function sandbox_ikiwiki {
       echo ""
       echo "Setting up ikiwiki integration..."
       cd $PROJECT
-      sandbox_checkout_develop
+      __project_checkout_develop
 
       if [ ! -e ".gitignore" ]; then
         cp $HOME/file/templates/ikiwiki/.gitignore .
@@ -134,14 +140,40 @@ function sandbox_ikiwiki {
 }
 
 # Vagrant integration
-function sandbox_vagrant {
+function project_vagrant {
+  if [ ! -e "$PROJECT/Vagrantfile" ]; then
   (
     echo ""
     echo "Setting up vagrant integration..."
     cd $PROJECT
-    sandbox_checkout_develop
+    __project_checkout_develop
+    vagrant init
     echo '.vagrant' >> .gitignore
     git commit -a -m "Adds vagrant support"
+  )
+  fi
+}
+
+# KVMX integration
+function project_kvmx {
+  if [ ! -e "$PROJECT/kvmxfile" ]; then
+  (
+    echo ""
+    echo "Setting up vagrant integration..."
+    cd $PROJECT
+    kvmx init
+    git commit -a -m "Adds kvmx support"
+  )
+  fi
+}
+
+# Puppet integration
+function project_puppet {
+  if [ ! -d "$PROJECT/puppet" ]; then
+  (
+    echo ""
+    echo "Setting up puppet integration..."
+    cd $PROJECT
 
     # Use the best approach
     #git clone $BOOSTRAP $PROJECT/puppet
@@ -149,24 +181,37 @@ function sandbox_vagrant {
     git remote add puppet $BOOTSTRAP
     git subtree add --prefix puppet $BOOTSTRAP master --squash
   )
+  fi
 }
 
 # Syntax check
 if [ -z "$PROJECT" ]; then
-  echo "usage: $BASENAME <path> [url]"
+  echo "$BASENAME: create a new project folder and setup helper utilities"
+  echo ""
+  echo "usage: $BASENAME <path> [<module1> ... <moduleN>]"
+  echo "available modules:"
+  echo ""
+  grep "^function project_" $PROGRAM | cut -d ' ' -f 2 | sed -e 's/project_//' | sort | xargs -L 6 | column -t -c 6 | sed -e 's/^/\t/'
+  echo ""
   exit 1
 fi
 
-# Clone or initialize
-if [ ! -z "$REPO" ]; then
-  git clone $URL $PROJECT
+# Initialize
+__project_init
+
+# Setup modules
+if [ ! -z "$MODULES" ]; then
+  __project_ask git
+  __project_ask gitflow
+  __project_ask ikiwiki
+  __project_ask kvmx
+  __project_ask puppet
+  __project_ask vagrant
 else
-  sandbox_init
-  sandbox_ask git
-  sandbox_ask git_flow
-  sandbox_ask ikiwiki
-  sandbox_ask vagrant
+  for module in $MODULES; do
+    project_$module
+  done
 fi
 
 # Teardown
-echo "Done sandboxing :)"
+echo "Done processing the project :)"