summaryrefslogtreecommitdiff
path: root/install.sh
blob: 81abd428dd0ce59c54db82be40b07e5ca914e0a7 (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/sh

replace_string() {
  sed "s/<?fugitive-install\s\+$1\s*?>/$2/"
}

fugitive_write_template() {
  name=`git config --get user.name`
  base64 -d | gunzip | replace_string "name" "$name" | \
    replace_string "year" "`date +%Y`"
}

fugitive_install_hooks() {
  echo -n "Installing fugitive hooks scripts... "
  (base64 -d | gunzip) > .git/hooks/post-commit <<EOF
#INCLUDE:post-commit.sh#
EOF
  chmod +x .git/hooks/post-commit
  (base64 -d | gunzip) > .git/hooks/post-receive <<EOF
#INCLUDE:post-receive.sh#
EOF
  chmod +x .git/hooks/post-receive
  echo "done."
}

fugitive_install() {
  DIR="."
  if [ "$1" != "" ]; then DIR="$1"; fi
  if [ ! -d "$DIR" ]; then mkdir -p "$DIR"; fi
  cd "$DIR"
  if [ -d ".git" ]; then
    echo "There's already a git repository here, aborting install."
    exit 1
  fi
  echo -n "Creating new git repository... "
  git init >/dev/null
  echo "done."
  echo -n "Creating default directory tree... "
  mkdir -p _drafts _articles _templates
  echo "done."
  echo -n "Adding default directory paths and settings to git config... "
  git config --add --path fugitive.blog-url "http://localhost/fugitive/"
  git config --add --path fugitive.templates-dir "_templates"
  git config --add --path fugitive.articles-dir "_articles"
  git config --add --path fugitive.public-dir "."
  git config --add --path fugitive.preproc ""
  echo "done."
  echo -n "Writing default template files... "
  fugitive_write_template > _templates/article.html <<EOF
#INCLUDE:default-files/article.html#
EOF
  fugitive_write_template > _templates/archives.html <<EOF
#INCLUDE:default-files/archives.html#
EOF
  fugitive_write_template > _templates/top.html <<EOF
#INCLUDE:default-files/top.html#
EOF
  fugitive_write_template > _templates/bottom.html <<EOF
#INCLUDE:default-files/bottom.html#
EOF
  fugitive_write_template > _templates/feed.xml <<EOF
#INCLUDE:default-files/feed.xml#
EOF
  echo "done."
  echo -n "Writing default css files... "
  (base64 -d | gunzip) > fugitive.css <<EOF
#INCLUDE:default-files/fugitive.css#
EOF
  (base64 -d | gunzip) > print.css <<EOF
#INCLUDE:default-files/print.css#
EOF
  echo "done."
  fugitive_install_hooks
  echo -n "Importing files into git repository... "
  git add _templates/* fugitive.css print.css >/dev/null
  git commit -m "fugitive inital import" >/dev/null
  echo "done."
  echo -n "Preventing git to track temporary and generated files... "
  echo "*~\nindex.html\narchives.html" > .git/info/exclude
  echo "done."
  echo "Writing dummy article (README) and adding it to the repos... "
  (base64 -d | gunzip) > _articles/README <<EOF
#INCLUDE:README#
EOF
  git add _articles/README
  git ci -m "fugitive fresh install" >/dev/null
  echo "done."
  cd - >/dev/null
  echo 'Installation almost complete, please visit your blog :-).'
}

case "$1" in
  "--help") fugitive_help >&2;;
  "--install") fugitive_install "$2";;
  "--install-hooks") fugitive_install_hooks "$2";;
  *) fugitive_usage >&2;;
esac