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