aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-10-25 18:52:31 -0200
committerSilvio Rhatto <rhatto@riseup.net>2017-10-25 18:52:31 -0200
commitbb9f5038bc7b6e622b2bf17ed0a6b8ceb5f11aee (patch)
tree0937516edd59460f9480cefe0d945f6ab4b251a8
parent3397e3a73ac892a20b6c99ddd571356655946bdc (diff)
downloadscripts-bb9f5038bc7b6e622b2bf17ed0a6b8ceb5f11aee.tar.gz
scripts-bb9f5038bc7b6e622b2bf17ed0a6b8ceb5f11aee.tar.bz2
Refactor sandbox and rename to project
-rwxr-xr-xproject (renamed from sandbox)87
1 files changed, 66 insertions, 21 deletions
diff --git a/sandbox b/project
index 808733d..3b4bb91 100755
--- 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 :)"