remove unused file
[iankelling.org] / setup.sh
1 #!/bin/bash
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 set -e; . /usr/local/lib/bash-bear; set +e
18
19 usage() {
20 cat <<EOF
21 Usage: ${0##*/} [OPTIONS] [DOMAIN_NAME] [LETSENCRYPT_EMAIL]
22 Setup dependencies, apache, and gitweb. Then call build.rb.
23
24 Default DOMAIN_NAME is iankelling.org. Domain is expected to resolve
25 so we can get a let's encrypt cert.
26
27 This script depends on a few other git repos of mine: distro-functions
28 and basic-https-conf.
29
30
31 -p PORT Apache port, default is 443.
32 -h|--help Print help and exit.
33
34 Note: Uses GNU getopt options parsing style
35 EOF
36 exit $1
37 }
38
39 ##### begin command line parsing ########
40
41
42 port=443
43 temp=$(getopt -l help, sp:h "$@") || usage 1
44 eval set -- "$temp"
45 while true; do
46 case $1 in
47 -s) allow_symlinks_arg=-s; shift ;;
48 -p) port=$2; shift 2 ;;
49 -h|--help) usage ;;
50 --) shift; break ;;
51 *) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;;
52 esac
53 done
54
55 ##### end command line parsing ########
56
57 x="$(readlink -f "$BASH_SOURCE")"
58 script_dir=${x%/*}
59 cd $script_dir
60
61 domain=${1:-iankelling.org} # use argument for testing site
62 email=$2
63 if [[ $email ]]; then
64 email_arg="-e $email"
65 fi
66 gitroot=/a/bin/githtml
67
68 if [[ $EUID != 0 ]]; then
69 s=sudo
70 fi
71
72 deb8=false
73 if grep -xFq 'VERSION_ID="8"' /etc/os-release; then
74 deb8=true
75 fi
76
77 shopt -s extglob
78
79 type -P a2enmod &>/dev/null || $s apt-get -y install apache2
80 type -P sqlite3 &>/dev/null || $s apt-get -y install sqlite3
81 type -P ffmpeg &>/dev/null || $s apt-get -y install ffmpeg
82
83
84 pkgs=(
85 # build.rb dependencies
86 ruby-pygments.rb ruby-safe-yaml ruby-sass
87 # python pkgs used for o(n^2) voting blog entry
88 # # commented out, needs update to python3
89 #python-bcrypt python-passlib
90 # gitweb pkgs
91 gitweb highlight
92 )
93 if $deb8; then
94 pkgs+=(build-essential ruby-dev)
95 else
96 pkgs+=(ruby-redcarpet)
97 fi
98 source /a/bin/distro-functions/src/package-manager-abstractions
99 pi ${pkgs[@]}
100 if $deb8; then
101 sudo gem install redcarpet
102 fi
103 chmod og+x _site/on2vote/vote.py
104
105
106 # debian has the package gitweb, which seems to mainly
107 # have some example apache config, and a minimal gitweb config.
108 # I'll just use the config as example and not use the package.
109 # It's example apache config seems to say we can use cgi or cgid,
110 # and googling cgid it seems a newer faster alternative. I also
111 # depend on this in my o(n^2) python script.
112 $s a2enmod cgid
113
114
115 # additional settings from browsing https://git-scm.com/docs/gitweb.conf
116 $s dd of=/etc/gitweb.conf <<EOF
117 \$feature{'highlight'}{'default'} = [1];
118 # highlighting doesn't work on files without extension.
119 # I noticed in terminal "highlight file" won't do it (unknown file type)
120 # hightlight < file will do it, and it's online documentation
121 # suggests it reads shebang. Todo: file a bug for gitweb
122 # to make highlight read shebangs.
123 our \$projectroot = "$gitroot";
124 # not documented at https://git-scm.com/docs/gitweb.conf,
125 # but it's in the debian conf, so use it.
126 # directory to use for temp files.
127 our \$git_temp = "/tmp";
128 push @git_base_url_list, "https://$domain/git";
129 our @extra_breadcrumbs = (
130 [ '$domain' => '/' ],
131 );
132 our \$home_link_str = 'git';
133 our \$site_footer = '$PWD/_site/gitweb-footer.html';
134 push @stylesheets, "/css/gitweb-site.css";
135 our \$favicon = '/assets/favicon.png';
136 # default is 25, cuts off descriptions.
137 our \$projects_list_description_width = 50;
138 # a bit superflous since they are all me
139 our \$omit_owner = true;
140 # highlight scripts with no extension, uses a patch
141 # that is on it's way upstream.
142 our \$highlight_force = 1;
143 our \$home_text = "$script_dir/_site/gitweb_home.html";
144 our \$projects_list_group_categories = 1;
145 EOF
146
147 web-conf $allow_symlinks_arg $email_arg -p $port - apache2 $domain <<EOF
148 # to run python script on my site:
149 <Directory /var/www/$domain/html/on2vote>
150 # to run python scripts with cgi
151 Options +ExecCGI
152 AddHandler cgi-script .py
153 </Directory>
154
155 <Directory /var/www/$domain/html/stream-videos/>
156 Options Indexes
157 </Directory>
158
159
160 <Directory "/var/www/$domain/html/cgi">
161 Options +ExecCGI
162 SetHandler cgi-script
163 </Directory>
164
165 # redirect some old paths when I was using jekyll.
166 Redirect permanent /10-14-2014/On2-vote-results.html /blog/on2-vote-results.html
167 Redirect permanent /09-29-2014/say-On2.html /blog/say-on2.html
168 Redirect permanent /08-07-2014/uninstalling-setup.html /blog/python-uninstall.html
169 Redirect permanent /08-01-2014/publising-my-technical-notes.html /blog/publishing-my-technical-notes.html
170
171 # All below is for gitweb + git-http-web.
172 # A simple builtin way to have a read only git website.
173 # I didn't find any significantly better alternatives out there.
174 SetEnv GIT_PROJECT_ROOT $gitroot
175 SetEnv GIT_HTTP_EXPORT_ALL
176
177 # note: cgi scripts can go anywhere into the filesystem,
178 # so there is no need to do a directory block for $gitroot
179
180 # fot git-http-web
181 <Directory /usr/lib/git-core>
182 AllowOverride None
183 Require all granted
184 </Directory>
185
186 <Directory /usr/share/gitweb>
187 Options +FollowSymLinks +ExecCGI
188 AddHandler cgi-script .cgi
189 </Directory>
190
191 # from man-git-http-backend, so git-http-web ang gitweb can both be used.
192 # it is instead of this:
193 # #ScriptAlias / /usr/lib/git-core/git-http-backend/
194 ScriptAliasMatch \\
195 "(?x)^/git/(.*/(HEAD | \\
196 info/refs | \\
197 objects/(info/[^/]+ | \\
198 [0-9a-f]{2}/[0-9a-f]{38} | \\
199 pack/pack-[0-9a-f]{40}\\.(pack|idx)) | \\
200 git-(upload|receive)-pack))\$" \\
201 /usr/lib/git-core/git-http-backend/\$1
202
203
204
205 # man-git-http-backend claims we should do this, but
206 # it causes no css/images to be displayed. Instead,
207 # just stick with the standard gitweb example directive
208 # from debian.
209 #ScriptAlias /git /usr/share/gitweb/gitweb.cgi/
210 Alias /git /usr/share/gitweb
211 EOF
212
213
214
215 $script_dir/gitweb-descriptions $gitroot
216
217 $script_dir/build.rb
218 $s rm -rf /var/www/$domain/html
219 $s ln -sT $script_dir/_site /var/www/$domain/html