3230bba9fca6b75796a7bc5337473f3a42218965
[iankelling.org] / setup.sh
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This script depends on a few other git repos of mine, such as
18 # distro-functions, basic-https-conf, acme-tiny-wrapper
19
20 set -eE -o pipefail
21 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
22
23 cd "${BASH_SOURCE%/*}"
24
25 domain=${1:-iankelling.org} # use argument for testing site
26 gitroot=/a/bin/githtml
27
28 shopt -s extglob
29
30 type -P a2enmod &>/dev/null || pi apache2
31
32 acme-tiny-wrapper $domain
33
34 pkgs=(
35 # build.rb dependencies
36 ruby-pygments.rb ruby-safe-yaml ruby-redcarpet
37 # python pkgs used for o(n^2) voting blog entry
38 python-bcrypt python-passlib
39 # gitweb pkgs
40 gitweb highlight
41 )
42 pi ${pkgs[@]}
43 chmod og+x _site/on2vote/vote.py
44
45
46 # debian has the package gitweb, which seems to mainly
47 # have some example apache config, and a minimal gitweb config.
48 # I'll just use the config as example and not use the package.
49 # It's example apache config seems to say we can use cgi or cgid,
50 # and googling cgid it seems a newer faster alternative. I also
51 # depend on this in my o(n^2) python script.
52 sudo a2enmod cgid
53
54
55 # additional settings from browsing https://git-scm.com/docs/gitweb.conf
56 s dd of=/etc/gitweb.conf <<EOF
57 \$feature{'highlight'}{'default'} = [1];
58 # highlighting doesn't work on files without extension.
59 # I noticed in terminal "highlight file" won't do it (unknown file type)
60 # hightlight < file will do it, and it's online documentation
61 # suggests it reads shebang. Todo: file a bug for gitweb
62 # to make highlight read shebangs.
63 our \$projectroot = "$gitroot";
64 # not documented at https://git-scm.com/docs/gitweb.conf,
65 # but it's in the debian conf, so use it.
66 # directory to use for temp files.
67 our \$git_temp = "/tmp";
68 push @git_base_url_list, "https://$domain/git";
69 our @extra_breadcrumbs = (
70 [ '$domain' => '/' ],
71 );
72 our \$home_link_str = 'git';
73 our \$site_footer = '$PWD/_site/gitweb-footer.html';
74 push @stylesheets, "/gitweb-site.css";
75 push @stylesheets, "/common.css";
76 our \$favicon = '/assets/favicon.png';
77 # default is 25, cuts off descriptions.
78 our $projects_list_description_width = 40;
79 # a bit superflous since they are all me
80 our $omit_owner = true;
81 # highlight scripts with no extension, uses a patch
82 # that is on it's way upstream.
83 our $highlight_force = 1;
84 EOF
85
86 apache-site - $domain <<EOF
87 # to run python script on my site:
88 <Directory /var/www/$domain/html/on2vote>
89 # to run python scripts with cgi
90 Options +ExecCGI
91 AddHandler cgi-script .py
92 </Directory>
93
94 # redirect some old paths when I was using jekyll.
95 Redirect permanent /10-14-2014/On2-vote-results.html /blog/on2-vote-results.html
96 Redirect permanent /09-29-2014/say-On2.html /blog/say-on2.html
97 Redirect permanent /08-07-2014/uninstalling-setup.html /blog/python-uninstall.html
98 Redirect permanent /08-01-2014/publising-my-technical-notes.html /blog/publishing-my-technical-notes.html
99
100 # All below is for gitweb + git-http-web.
101 # A simple builtin way to have a read only git website.
102 # I didn't find any significantly better alternatives out there.
103 SetEnv GIT_PROJECT_ROOT $gitroot
104 SetEnv GIT_HTTP_EXPORT_ALL
105
106 # note: cgi scripts can go anywhere into the filesystem,
107 # so there is no need to do a directory block for $gitroot
108
109 # fot git-http-web
110 <Directory /usr/lib/git-core>
111 AllowOverride None
112 Require all granted
113 </Directory>
114
115 <Directory /usr/share/gitweb>
116 Options +FollowSymLinks +ExecCGI
117 AddHandler cgi-script .cgi
118 </Directory>
119
120 # from man-git-http-backend, so git-http-web ang gitweb can both be used.
121 # it is instead of this:
122 # #ScriptAlias / /usr/lib/git-core/git-http-backend/
123 ScriptAliasMatch \\
124 "(?x)^/git/(.*/(HEAD | \\
125 info/refs | \\
126 objects/(info/[^/]+ | \\
127 [0-9a-f]{2}/[0-9a-f]{38} | \\
128 pack/pack-[0-9a-f]{40}\\.(pack|idx)) | \\
129 git-(upload|receive)-pack))\$" \\
130 /usr/lib/git-core/git-http-backend/\$1
131
132
133
134 # man-git-http-backend claims we should do this, but
135 # it causes no css/images to be displayed. Instead,
136 # just stick with the standard gitweb example directive
137 # from debian.
138 #ScriptAlias /git /usr/share/gitweb/gitweb.cgi/
139 Alias /git /usr/share/gitweb
140 EOF
141
142
143 # my projects all have README or --help with a short single line
144 # description which I parse and put into the gitweb description.
145 _git_desc_readme() {
146 while read -r line; do
147 [[ $line ]] || continue
148 if echo "$line" | grep "^ *[#*]" &>/dev/null; then
149 continue
150 fi
151 echo "$line" > .git/description
152 break
153 done < README*
154 }
155 gitweb_descriptions() {
156 for d in $gitroot/*; do
157 d=$(readlink -f $d)
158 cd $d/..
159 e ${PWD##*/}
160 shopt -s nullglob
161 f=(!(LICENSE|COPYING|README|.git))
162 shopt -u nullglob
163 if [[ ${#f[@]} == 1 && ! -d $f ]]; then
164 if [[ ! -x $f ]]; then
165 if [[ $f == *-function ]]; then
166 ${f%-function} --help | sed -n '2p' > .git/description
167 else
168 _git_desc_readme
169 fi
170 else
171 $f --help | sed -n '2p' > .git/description
172 fi
173 else
174 _git_desc_readme
175 fi
176 done
177 }
178
179 gitweb_descriptions
180
181 ./build.rb