]> gitweb.fluxo.info Git - templater.git/commitdiff
Go to project folder just once
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 27 Oct 2017 12:41:18 +0000 (10:41 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 27 Oct 2017 12:41:18 +0000 (10:41 -0200)
templater

index cec59eda6f338aa41155c4e72532ac9415bf1d04..497585cd7a76377243a3c566855457da17349022 100755 (executable)
--- a/templater
+++ b/templater
@@ -11,6 +11,7 @@ PROJECT="$1"
 shift
 MODULES="$*"
 BOOTSTRAP="https://git.fluxo.info/puppet-bootstrap.git"
+CWD="`pwd`"
 
 # Initialize project
 function __templater_init {
@@ -42,13 +43,9 @@ function __templater_implementations {
 
 # Checkout to develop branch if available
 function __templater_checkout_develop {
-  (
-    cd $PROJECT &> /dev/null
-
-    if git branch --list develop | grep -q develop; then
-      git checkout develop
-    fi
-  )
+  if git branch --list develop | grep -q develop; then
+    git checkout develop
+  fi
 }
 
 # Copy or append source file into destination
@@ -69,11 +66,9 @@ function __templater_copy_or_append {
 
 # Basic implementation
 function templater_basic {
-  if [ ! -e "$PROJECT/README.md" ]; then
-  (
-    cd $PROJECT &> /dev/null
+  if [ ! -e "README.md" ]; then
     echo "$PROJECT"                           > README.md
-    echo  $PROJECT | sed -e 's|.|=|g'        >> README.md
+    basename $PROJECT | sed -e 's|.|=|g'     >> README.md
     #echo ""                                 >> README.md
     #echo "This is the $PROJECT repository." >> README.md
 
@@ -83,43 +78,35 @@ function templater_basic {
     #echo "* Nothing here? :P" >> TODO.md
 
     touch ChangeLog
-    )
   fi
 }
 
 # Git implementation
 function templater_git {
-  if [ ! -d "$PROJECT/.git" ]; then
-  (
-    cd $PROJECT &> /dev/null
+  if [ ! -d ".git" ]; then
     touch .gitignore
 
     git init
     git add .
     #git commit -m "Initial import"
-  )
   fi
 }
 
 # Git hooks implementation
 function templater_githooks {
-  if [ ! -d "$PROJECT/.git" ]; then
-  (
+  # TODO: check if githooks are already set
+  if [ -d ".git" ]; then
     if which git-hooks &> /dev/null; then
       echo ""
       echo "Installing hooks..."
       git hooks --install
     fi
-  )
   fi
 }
 
 # Setup git-flow implementation
 function templater_gitflow {
-  if ! grep -q '^\[gitflow' $PROJECT/.git/config; then
-  (
-    cd $PROJECT &> /dev/null
-
+  if ! grep -q '^\[gitflow' .git/config; then
     if ! git branch --list develop | grep -q develop; then
       git branch develop
 
@@ -129,62 +116,50 @@ function templater_gitflow {
         git flow init -d
       fi
     fi
-  )
   fi
 }
 
 # Vagrant implementation
 function templater_vagrant {
-  if [ ! -e "$PROJECT/Vagrantfile" ]; then
-  (
+  if [ ! -e "Vagrantfile" ]; then
     echo ""
     echo "Setting up vagrant..."
-    cd $PROJECT &> /dev/null
     #__templater_checkout_develop
     vagrant init
     echo '.vagrant' >> .gitignore
     git commit -a -m "Adds vagrant support"
-  )
   fi
 }
 
 # KVMX implementation
 function templater_kvmx {
-  if [ ! -e "$PROJECT/kvmxfile" ]; then
-  (
+  if [ ! -e "kvmxfile" ]; then
     echo ""
     echo "Setting up vagrant..."
-    cd $PROJECT &> /dev/null
     kvmx init
     git commit -a -m "Adds kvmx support"
-  )
   fi
 }
 
 # Puppet implementation
 function templater_puppet {
-  if [ ! -d "$PROJECT/puppet" ]; then
-  (
+  if [ ! -d "puppet" ]; then
     echo ""
     echo "Setting up puppet..."
-    cd $PROJECT &> /dev/null
 
     # Use the best approach
     #git clone $BOOSTRAP $PROJECT/puppet
     #git submodule add $BOOSTRAP puppet
     git remote add puppet $BOOTSTRAP
     git subtree add --prefix puppet $BOOTSTRAP master --squash
-  )
   fi
 }
 
 # Ikiwiki implementation
 function templater_ikiwiki {
-  if [ ! -e "$PROJECT/ikiwiki.yaml" ]; then
-  (
+  if [ ! -e "ikiwiki.yaml" ]; then
     echo ""
     echo "Setting up ikiwiki..."
-    cd $PROJECT &> /dev/null
 
     #__templater_checkout_develop
     __templater_copy_or_append ikiwiki .gitignore
@@ -216,17 +191,14 @@ function templater_ikiwiki {
       git add .
       #git commit -a -m "Static site generation support using ikiwiki"
     fi
-  )
   fi
 }
 
 # Sphinx implementation
 function templater_sphinx {
-  if [ ! -e "$PROJECT/conf.py" ]; then
-  (
+  if [ ! -e "conf.py" ]; then
     echo ""
     echo "Setting up sphinx..."
-    cd $PROJECT &> /dev/null
 
     #__templater_checkout_develop
     __templater_copy_or_append sphinx .gitignore
@@ -247,17 +219,14 @@ function templater_sphinx {
       mkdir _themes
       git submodule add https://github.com/snide/sphinx_rtd_theme _themes/sphinx_rtd_theme
     fi
-  )
   fi
 }
 
 # Pelican implementation
 function templater_pelican {
-  if [ ! -e "$PROJECT/pelicanconf.py" ]; then
-  (
+  if [ ! -e "pelicanconf.py" ]; then
     echo ""
     echo "Setting up pelican..."
-    cd $PROJECT &> /dev/null
 
     #__templater_checkout_develop
     __templater_copy_or_append pelican .gitignore
@@ -273,7 +242,6 @@ function templater_pelican {
     if [ ! -d "content" ]; then
       cp -r $DIRNAME/share/pelican/content .
     fi
-  )
   fi
 }
 
@@ -322,6 +290,9 @@ fi
 # Initialize
 __templater_init
 
+# Go to project folder
+cd $PROJECT &> /dev/null
+
 # Setup modules
 if [ -z "$MODULES" ]; then
   for project in `__templater_implementations`; do
@@ -334,4 +305,5 @@ else
 fi
 
 # Teardown
+cd $CWD
 echo "Done processing the project :)"