#!/bin/bash
# Copyright (C) 2016 Ian Kelling
# 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 2 of the License, or
# (at your option) 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 .
# This script depends on a few other git repos of mine, such as
# distro-functions, basic-https-conf, acme-tiny-wrapper
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
usage() {
cat </dev/null || $s apt-get -y install apache2
type -P sqlite3 &>/dev/null || $s apt-get -y install sqlite3
acme-tiny-wrapper $domain
pkgs=(
# build.rb dependencies
ruby-pygments.rb ruby-safe-yaml ruby-sass
# python pkgs used for o(n^2) voting blog entry
python-bcrypt python-passlib
# gitweb pkgs
gitweb highlight
)
if $deb8; then
pkgs+=(build-essential ruby-dev)
else
pkgs+=(ruby-redcarpet)
fi
$s apt-get -y install ${pkgs[@]}
if $deb8; then
sudo gem install redcarpet
fi
chmod og+x _site/on2vote/vote.py
# debian has the package gitweb, which seems to mainly
# have some example apache config, and a minimal gitweb config.
# I'll just use the config as example and not use the package.
# It's example apache config seems to say we can use cgi or cgid,
# and googling cgid it seems a newer faster alternative. I also
# depend on this in my o(n^2) python script.
$s a2enmod cgid
# additional settings from browsing https://git-scm.com/docs/gitweb.conf
$s dd of=/etc/gitweb.conf < '/' ],
);
our \$home_link_str = 'git';
our \$site_footer = '$PWD/_site/gitweb-footer.html';
push @stylesheets, "/css/gitweb-site.css";
our \$favicon = '/assets/favicon.png';
# default is 25, cuts off descriptions.
our \$projects_list_description_width = 40;
# a bit superflous since they are all me
our \$omit_owner = true;
# highlight scripts with no extension, uses a patch
# that is on it's way upstream.
our \$highlight_force = 1;
EOF
apache-site - $domain <
# to run python scripts with cgi
Options +ExecCGI
AddHandler cgi-script .py
Options +ExecCGI
SetHandler cgi-script
# redirect some old paths when I was using jekyll.
Redirect permanent /10-14-2014/On2-vote-results.html /blog/on2-vote-results.html
Redirect permanent /09-29-2014/say-On2.html /blog/say-on2.html
Redirect permanent /08-07-2014/uninstalling-setup.html /blog/python-uninstall.html
Redirect permanent /08-01-2014/publising-my-technical-notes.html /blog/publishing-my-technical-notes.html
# All below is for gitweb + git-http-web.
# A simple builtin way to have a read only git website.
# I didn't find any significantly better alternatives out there.
SetEnv GIT_PROJECT_ROOT $gitroot
SetEnv GIT_HTTP_EXPORT_ALL
# note: cgi scripts can go anywhere into the filesystem,
# so there is no need to do a directory block for $gitroot
# fot git-http-web
AllowOverride None
Require all granted
Options +FollowSymLinks +ExecCGI
AddHandler cgi-script .cgi
# from man-git-http-backend, so git-http-web ang gitweb can both be used.
# it is instead of this:
# #ScriptAlias / /usr/lib/git-core/git-http-backend/
ScriptAliasMatch \\
"(?x)^/git/(.*/(HEAD | \\
info/refs | \\
objects/(info/[^/]+ | \\
[0-9a-f]{2}/[0-9a-f]{38} | \\
pack/pack-[0-9a-f]{40}\\.(pack|idx)) | \\
git-(upload|receive)-pack))\$" \\
/usr/lib/git-core/git-http-backend/\$1
# man-git-http-backend claims we should do this, but
# it causes no css/images to be displayed. Instead,
# just stick with the standard gitweb example directive
# from debian.
#ScriptAlias /git /usr/share/gitweb/gitweb.cgi/
Alias /git /usr/share/gitweb
EOF
$script_dir/gitweb-descriptions $gitroot
$script_dir/build.rb
$s rm -rf /var/www/$domain/html
$s ln -sT $script_dir/_site /var/www/$domain/html