aboutsummaryrefslogtreecommitdiff
path: root/templater
blob: cd1366045b10467688f95bfe4b05f3e3ab6a81f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/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 <http://www.gnu.org/licenses/>.

# 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 <path> [<module1> ... <moduleN>] [--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 :)"