#!/bin/bash # # Templater: setup or configure a new code project. # # Copyright (C) 2017 Silvio Rhatto - rhatto at riseup.net # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published # by the Free Software Foundation, either version 3 of the License, # or any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Parameters NAME="templater" PROGRAM="$0" BASENAME="`basename $0`" PROJECT="$1" shift MODULES="$*" CWD="`pwd`" # Set shared files location if [ -e "`dirname $(readlink -f $0)`/share/$NAME" ]; then # Development or local installation layout SHARE="`dirname $(readlink -f $0)`/share/$NAME" else # System installation layout SHARE="`dirname $(readlink -f $0)`/../share/$NAME" fi # Include basic functions source $SHARE/templater/functions || exit 1 # Syntax check if [ -z "$PROJECT" ]; then echo "$BASENAME: create a new project folder and/or setup helper utilities" echo "" echo "usage: $BASENAME [ ... ] [--diff]" echo "" echo "examples": echo "" echo -e "\t $BASENAME myproject git ikiwiki # adds git and ikiwiki config into myproject" echo -e "\t $BASENAME . pelican # add pelican config into the current folder" echo "" echo "available modules:" echo "" #templater_implementations | xargs -L 6 | column -t -c 6 | sed -e 's/^/\t/' for module in `templater_implementations`; do echo -e "\t $module: `cat $SHARE/$module/description`" done echo "" exit 1 fi # Initialize templater_init # Go to project folder cd $PROJECT &> /dev/null # Process modules if [ -z "$MODULES" ]; then for project in `templater_implementations`; do templater_ask $project done else for module in $MODULES; do # Skip options if echo $module | grep -q '^--'; then continue fi #if `templater_implementations | grep -q "^$module"`; then if [ -d "$SHARE/$module" ]; then # Dispatch if echo $* | grep -q -- '--diff'; then templater_diff $module #elif echo $* | grep -q -- '--update'; then else $SHARE/$module/setup $SHARE fi else templater_echo "No such module $module, skipping" fi done fi # Teardown cd $CWD templater_echo "Done processing the project :)"