aboutsummaryrefslogtreecommitdiff
path: root/templater
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-10-27 10:41:18 -0200
committerSilvio Rhatto <rhatto@riseup.net>2017-10-27 10:41:18 -0200
commit319f7cc943604ab5f30e123b0d0a2bdcde1f693e (patch)
treea9d9c64f744b156d985369e0afbdf116efe7019c /templater
parentade98dfe542598c731b9e0bfb360bceb8c688c71 (diff)
downloadtemplater-319f7cc943604ab5f30e123b0d0a2bdcde1f693e.tar.gz
templater-319f7cc943604ab5f30e123b0d0a2bdcde1f693e.tar.bz2
Go to project folder just once
Diffstat (limited to 'templater')
-rwxr-xr-xtemplater68
1 files changed, 20 insertions, 48 deletions
diff --git a/templater b/templater
index cec59ed..497585c 100755
--- 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 :)"