1
0
Fork 0
repo2html/repo2html

94 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
#
# Detects repository VCS and begins VCS-specific processing
#
# Copyright (C) 2012 Mike Gerwitz
#
# This file is part of repo2html.
#
# 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 3 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 <http://www.gnu.org/licenses/>.
# #
# repository detection
repotype=
if repodir="$( git rev-parse --git-dir 2>/dev/null )"; then
# use absolute path for git directory
export GIT_DIR="$( cd $repodir && pwd )"
repotype=git
else
# contribute!
echo "fatal: only git repositories are currently supported" >&2
exit 128
fi
# store our cwd and enter our own (to make invoking relative scripts easier)
path_out="$( pwd )"
path="$( dirname "$0" )"
cd "$path"
# provides configuration warning and outputs a default
cwarn()
{
echo "Warning: no $1 provided; defaulting to: ${2:-(empty)}" >&2
echo "$2"
}
# configuration (note that this setup in conjunction with the below defaults
# imply that they can be passed in as environment variables as an alternative to
# options)
while getopts t:d:c:l:f:R: opt; do
case "$opt" in
t) title="$OPTARG";;
d) desc="$OPTARG";;
c) copyright="$OPTARG";;
l) license="$OPTARG";;
f) msgfmt="$OPTARG";;
R) rss_count="$OPTARG";;
?) exit 64;;
esac
done
shift $((OPTIND-1))
url_root="${1?Missing root URL (for RSS)}"
# default title to repository name (as taken from the directory)
title="${title:-$( cwarn title $( basename "$path_out" ) )}"
desc="${desc:-$( cwarn description )}"
# default to a restrictive copyright (unfortunately, that's the best we can do,
# since copyright is restrictive by default)
copyright="${copyright:-$( cwarn copyright 'Respective Authors' )}"
license="${license:-$( cwarn license )}"
# provide default message formatter if necessary
msgfmt="${msgfmt:-./msgfmt}"
# make configuration available to all scripts
export title desc copyright license msgfmt url_root
# clear and prime the cachefile (TODO: we could maintain cache files from
# previous runs if we offer a flag that opts out of reprocessing previously
# processed commits)
echo "Priming hashcache..." >&2
./hashcache clear
"$repotype"/list | while read hash _ ts id _; do
./hashcache "$hash" "$( ./outfgen "$ts" "$id" )"
done
# pass commit list to the HTML and RSS processors
"$repotype"/list | tee \
>( ./rss "$repotype" "$url_root" "$rss_count" > "$path_out/rss.xml" ) \
| ./processor "$repotype" "$path_out"